The tag has no wiki summary.

learn more… | top users | synonyms

13
votes
5answers
880 views

Copy file permissions, but not files in Unix

(From : http://stackoverflow.com/questions/15245144/copy-file-permissions-but-not-files, closed because off-topic) I have two copies of the same directory tree. They almost have the same files in ...
12
votes
2answers
11k 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 ...
11
votes
6answers
3k 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 ...
8
votes
7answers
4k 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 ...
7
votes
4answers
8k 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?
7
votes
9answers
14k 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 ...
7
votes
2answers
659 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 ...
6
votes
4answers
2k 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 ...
5
votes
3answers
10k 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 ...
5
votes
3answers
5k 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 ...
4
votes
2answers
712 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
2k 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
1k 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 > ...
4
votes
1answer
247 views

cp -p will preserve times for some files but not all?

I have a source directory on a machine with a bunch of files, all with the same permissions, that I want to copy to another directory, that is mounted via SMB. [tmark@dexter JR09141045 ...
3
votes
5answers
14k 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
3
votes
2answers
176 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: ...
3
votes
1answer
168 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
1answer
30 views

Editing the PATH in PASE

I am doing a some PHP development on an IBMi running ZendServer6. I have to call PHP by its full path of /usr/local/zendsvr6/bin/php-cli. Is there a dotfile I can edit in my home directory or some ...
3
votes
4answers
139 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
395 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
6k 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
4answers
1k 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 ...
2
votes
1answer
287 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.
2
votes
3answers
2k 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
4k 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
3k 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
668 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
381 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
226 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
125 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
794 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
2k 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
3k 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 ...
2
votes
1answer
60 views

How to improve the efficiency of gnu parallel to read from a compressed stream?

Is another question extended from the previous one [1] I have a compressed file and stream them to feed into a python program, e.g. bzcat data.bz2 | parallel --no-notice -j16 --pipe python parse.py ...
1
vote
5answers
3k 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
469 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
2k 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
242 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
5answers
5k views

Counting number of items in a single-row CSV file?

I have a file containing a long comma-delimited list of numbers, like this: 2,8,42,75,101 What's the simplest command (from a Unix shell) to get the count of numbers in this file? In the example ...
1
vote
2answers
3k 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
510 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
2answers
210 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
2answers
458 views

Is it possible to pass a shell variable from linux to windows via winexe?

I want to pass a shell variable called $test to windows from linux via winexe. For example: winexe -W WORKGROUP -U user%password //192.160.13.13 'cmd.exe /C move D:\restore_db\$test D:\Restore\' Is ...
1
vote
1answer
557 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
2answers
2k views

Kill all currently running cron jobs

For some reason my cron job scripts aren't exiting cleanly and they're backing up my server. There are currently a couple hundred processes running for one of my users. I can use the following command ...
1
vote
1answer
2k views

How to pipe and echo the result that is being processed? [closed]

I'd like to execute this command: find /apps/ -type f -print0 | grep -z log$ | xargs -0 grep 'this->aForm' And in parallel, I'd like to see which files are being processed. How to to this?
1
vote
1answer
636 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
1answer
63 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' ...