The tag has no wiki summary.

learn more… | top users | synonyms

10
votes
2answers
7k views

When to use single-quote, double-quote in grep?

While trying to search for a simple pattern "hello" in a file, all the following forms of grep work: grep hello file1 grep 'hello' file1 grep "hello" file1 Is there a specific case where one of ...
9
votes
6answers
2k views

Deleting a UNIX directory with a hyphen in the name

Through a boneheaded maneuver on my part, I accidentally created a directory called (for instance) -A, and ended up filling it with files. I want to delete said directory. I've tried: rmdir -- -A ...
6
votes
9answers
10k views

'Argument list too long' error while copying a large number of files

I am using the following command: \cp -uf /home/ftpuser1/public_html/ftparea/*.jpg /home/ftpuser2/public_html/ftparea/ And I am getting the error: -bash: /bin/cp: Argument list too long I have ...
6
votes
2answers
582 views

When do file extensions override shebang lines on Linux?

Some PHP cron jobs started failing on a shared server recently. They had been working without error and no updates for nearly a year, but now would no longer run due to syntax errors. What was going ...
5
votes
4answers
5k views

Append an echo to file?

In linux, how do I do something like echo 'hello world' > log.txt but instead of overwriting the contents of log.txt, it appends to the end of of log.txt?
5
votes
6answers
3k views

In *nix, how to determine which filesystem a particular file is on?

In a generic, modern unix environment (say, GNU/Linux, GNU/Solaris, or Mac OS X), is there a good way to determine which mountpoint and filesystem-type a particular absolute file path is on? I ...
4
votes
2answers
166 views

supress expansion of * in echo

I am working on a script which dynamically executes some queries on daily basis. These queries are coming from a table in the database. Here is the sample output of the query table: ...
4
votes
3answers
867 views

Faking the date for a specific shell session

I'm certainly trying to achieve something weird here, but I want to fake the date locally for a shell session on GNU/Linux. I need to black-box test how a program behaves at different dates, and ...
4
votes
2answers
537 views

Shell scripting and regex: Which one is better to match numbers, [[:digit:]] or [0-9]?

As the title suggests, which one is better to match numbers, [[:digit:]] or [0-9]? I'm using the bash shell Thanks :)
4
votes
1answer
1k views

Using a shell script to check if rsync made any changes

I've got a bash script that rsync's two directories. Sometimes there's a change, odds are there's nothing. I want to run a command only if rsync actually made a change (add/update a file). ...
4
votes
2answers
481 views

How do I prevent bash $ substitution?

I'm trying to preserve $if below and would like the following to output $if bash is getting in the way by doing $ substitution $ sed -e 's:\\$:\\$:g' <<ENDOFFILE > $if > ...
3
votes
3answers
6k views

compressing dd backup on the fly

Maybe this will sound like dumb question but the way i'm trying to do it doesn't work. I'm on livecd, drive is unmounted, etc. When i do backup this way sudo dd if=/dev/sda2 ...
3
votes
3answers
3k views

How does cd command work? (unix) [closed]

Could anybody explain to me how cd - command work? man cd tells me that An argument of - is equivalent to $OLDPWD. Then I found on the net that $OLDPWD is the previous working directory as set by the ...
3
votes
1answer
167 views

“Threading” in Shell Scripts

I have a situation where I need to: Do some preamble setup in Script A Start Scripts B, C, D and E together, so they run concurrently When all four scripts have exited, do some cleanup in Script A ...
3
votes
4answers
129 views

Is there a way to prevent output from backgrounded tasks from covering the command line in a shell?

I would like to be able to run task(s) in the background of a shell and not have their output to stdout or stderr cover the command line at the bottom. Frequently I need to run other commands to ...
2
votes
3answers
321 views

putty aborts process while shutting down

I'm newby so the question is simple. After I connected to server via putty I want to execute some command. Suppose that command will be performed for long time (e.g. extracting files from large ...
2
votes
6answers
4k views

How to check a file exists

How do I determine that a file exists using a shell script? I.e: #!/bin/sh if [ Does File Exist? ] then do this thing fi
2
votes
3answers
1k views

sudo and sudo -i access features

What are privilege differences between sudo and sudo -i? With sudo it's $sudo echo "search foo.bar.baz" >> /etc/resolv.conf bash: /etc/resolv.conf: Permission denied ...and with sudo ...
2
votes
3answers
996 views

grep - recognize carriage return as new line

I want to search a webserver running unix for php-files containing a specific string. Usually I use these commands to accomplish this: find . -name "*.php" -print0 | xargs -0 grep -H -i "the string ...
2
votes
3answers
3k views

How to ls and know the target of symbolic links in one command line?

I need to get the folder contents in one command line, right now if I do stat or ls, it tells me file type is Symbolic Link but it doesn't tell me if it's a file or a folder. I'm using this; stat -c ...
2
votes
3answers
2k views

Unix Linux directory compare

I have a known good directory structure that I'd like to compare owner/group and permissions against another server and flag any files/folders that need to be changed. Since I wont have access to both ...
2
votes
1answer
369 views

'ls' taking a long time to list 20 subdirectories

I have a directory (my_dir) which has 20 sub directories. Every time I run 'ls' or try to autocomplete a file name in this directory my IO usage goes to 100% and it takes very long time (10 mins) to ...
2
votes
6answers
374 views

Last command issued on a GNU/Linux box

Someone asked at the mailing list of my local LUG if there is any way of learning the last command issued on a GNU/Linux system. We're talking last command in a system-wide fashion I guess. After ...
2
votes
3answers
83 views

No shell and launch application on login

I am working on migrating an application from OpenVMS to RedHat Linux 6. The application is a green screen terminal application. The users will log into Linux via SSH and the application should ...
2
votes
3answers
113 views

Will uploading modified version of a KSH script affect processes that are currently running the script?

Let say I have a KSH script my_script.ksh that performs complex operations including but not limited to invoking SQLPLUS to manipulate large number (millions) of records in an Oracle database. The ...
2
votes
4answers
488 views

tcsh : path of sourced file

I am sourcing a file under tcsh. This file could be anywhere on the filesystem. How can I retrieve the path of my sourced file ? $0 won't work : I don't execute the file, I source it. Many thanks !
2
votes
2answers
1k views

How to change VGA mode after boot and login with ubuntu?

Is there a way to change the screen resolution of the console after the system has been booted? I've seen plenty on setting the vga= line in the boot and in the grub config but I'd like to be able to ...
2
votes
2answers
968 views

How can I kill and wait for background processes to finish in a shell script when I Ctrl+C it?

I'm trying to set up a shell script so that it runs background processes, and when I ctrl+C the shell script, it kills the children, then exits. The best that I've managed to come up with is this. It ...
2
votes
5answers
2k views

Search and delete lines matching a pattern along with comments in previous line if any

I have a requirement to write a shell script in csh to search and delete lines matching a pattern along with comments in previous line if any. For example if my file has the following lines Shell ...
1
vote
5answers
11k views

How do i find out which Fedora version I'm running from the cli (not uname -a)?

I want to know if the box is Fedora Core 4 or Redhat 9, or CentOS, etc... not if it has Kernel 2.6.x
1
vote
5answers
1k views

Is there any browser utility I can use in SSH for Linux

Is there a text-based browser available for Linux (CentsOS) which I can use when I SSH to my server. I use CentOS release 5.5. My server do not have graphic interface. It would be nice if it ...
1
vote
5answers
450 views

selective backup script in bash

I've been using this simple command (that's all I can do :) to backup the whole tree from my user data in NAS server for a year. cp -r /STORAGE /BACKUP-STORAGE/YYYY-MM-DD Unfortunately, after a ...
1
vote
5answers
1k views

bash script - print from line N to EOF

I want to be able to print the number of lines from bash as such: Line number (as counted from the top) -> end of the file It seems tail will only count lines from the bottom. Does anyone know how ...
1
vote
3answers
221 views

'cd' switch back and forth to previous and current directory

I found cd - can switch back and forth between previous and current directory which is a very handy feature. Also found cd -- works too, but not sure what exactly that's for. Is there any reference ...
1
vote
4answers
889 views

Is there an easy way to insert data/time in front of a log file with just shell scripting?

Say I want to monitor memory usage on a java process overnight. I can do something like top | grep java > out.log I will get a log file with a whole bunch of lines. Is there an easy way to get a ...
1
vote
2answers
2k views

How to encode the rdesktop password parameter in a shell script?

I can connect with this script from linux to a windows RDP session: #!/bin/bash /usr/bin/rdesktop -N -x m -u Administrator -p secret123 -d DOMAIN1 127.0.0.1:33891 (The rdp port of the remote ...
1
vote
1answer
288 views

Picking a single line from a text file by its line number

In a Unix shell, how can I pick a single line from a text file by its line number? Say I want whatever is at line 3 in animals.txt to be written to stdout (bat bat bat). monkey monkey monkey cat cat ...
1
vote
1answer
255 views

Find all the sym links that point to a particular file

I know that ls -l will give you the "number of links" but I'm looking for a command or combination of commands that will give me a list of all the symbolic links that point to a particular file.
1
vote
2answers
167 views

Solaris 8 - directories gone missing; is this housecleaning script the culprit?

Our outsourced IT service provider runs the following script via cron to clean up Oracle core and trace files. It clearly is not a well-written script, but my question for the Serverfault crowd is ...
1
vote
1answer
506 views

How to batch edit a list of files?

I have a list of files where I need to remove some lines that have been added yesterday by a spambot. The section I want to remove looks like this: ^M <script>[...] bunch of malware code ...
1
vote
1answer
304 views

How to combine files with unix cat command based on file name, then rename?

I have a bunch of CSV files in a directory like: modfinalak_1.csv modfinalal_1.csv modfinalal_2.csv modfinalal_3.csv modfinalar_1.csv modfinalar_2.csv so it's one or multiple files per each US state ...
1
vote
2answers
268 views

Unix/Linux command to view available servers

Situation: I'm inspired to work from home this evening. So I download some source from work's svn repo. Unfortunately, I find some lib files are missing. Not a problem, I'll remote in to my desktop at ...
1
vote
1answer
24 views

curl is giving wrong result via ssh

Curl is working fine on the node itself: [ec2-user@smokebase1 ~]$ curl -s -I --retry 3 --header 'Host: smoke-base.dev-test.com' ...
1
vote
2answers
48 views

Rotatelogs rotating log files mid log entry

I have a c++ tool that outputs to STDOUT via printf i.e. printf ("%s\n", logline); I then pipe that to rotatelogs i.e. tool | rotatelogs /tmp/logs/log_%s 60 Everything works great, but ...
1
vote
1answer
104 views

Error when using mv

I am receiving an error when trying to mv some files that really doesn't make sense. I receive this error: mv: cannot move `thatDir' to a subdirectory of itself, ...
1
vote
3answers
224 views

Getting different values of particular variable from a file in UNIX

I have a file which I'd like to parse to extract certain values from it. I don't know what command and syntax I should use (maybe sed?). Below are 2 sample lines which I might expect to find in the ...
1
vote
1answer
140 views

Java command not going to background with &

I'm running a java command: java weblogic.Admin -adminurl t3://URL:POST -username username -password password START $SERVER & on an Aix machine. The problem is that the shell still halts ...
1
vote
1answer
145 views

force unix program output redirect

I'm new to shell-scripting and I guess this should be something quite easy. Anyway I don't know how to force redirect a program's output to the input of another program. I know about the pipe, where ...
1
vote
1answer
60 views

Sent command-line output as an arguments to other command

1) Here is the command to install special package (for example system/header) #pkg install system/header 2) ALso we can install several packages #pkg install system/header network/ssh package/rpm ...
1
vote
0answers
36 views

runas or sudo equivalent on AS400 ibm iSeries (invoke it via java code) [duplicate]

Possible Duplicate: “runas” or “sudo” equivalent on AS400 IBM iSeries I am trying to invoke a program to run as another user(by getting input user/pwd) in AS400 OS ...