Questions tagged [unix-shell]

124 questions
42
votes
4 answers

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 modifying the system-wide date can have unwanted side…
nicoulaj
  • 1,155
  • 2
  • 10
  • 12
34
votes
4 answers

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?
John
  • 7,153
  • 22
  • 61
  • 86
31
votes
4 answers

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 of=/media/disk/sda2-backup-10august09.ext3 bs=64k ...normally it would…
Phil
  • 1,839
  • 6
  • 27
  • 33
28
votes
2 answers

When to use single quotes, double quotes, or no quotes 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 the above forms work but others do not. Does it make…
TheLameProgrammer
16
votes
7 answers

portable unix way to join strings with separator

Is there a portable unix shellscripting way of joining a number of strings together with a given separator, like so: $ strjoin --- foo bar baz quux foo---bar---baz---quux Sure I could use a $scripting_language one liner or an ugly explicit loop in…
JanKanis
  • 473
  • 1
  • 5
  • 11
14
votes
5 answers

Copy file permissions, but not files in Unix

(From : https://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 both (one version may have a couple extra or missing…
Mariano Paniga
  • 261
  • 2
  • 8
14
votes
7 answers

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 suppose I could execute the mount command and manually…
smokris
  • 685
  • 3
  • 13
  • 27
14
votes
9 answers

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 but it then tells me that the directory still has…
Kate Bertelsen
  • 243
  • 2
  • 6
13
votes
6 answers

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
Zak
  • 1,032
  • 2
  • 15
  • 25
12
votes
2 answers

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 roche_454_transfer]$ ls -l /source_dir total 71348 -rwxrwxrwx 1…
tmark
  • 121
  • 1
  • 1
  • 6
12
votes
9 answers

'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 also tried: ls…
icelizard
  • 732
  • 3
  • 9
  • 20
10
votes
1 answer

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). Otherwise I want to just skip it. Is there a return…
raccettura
  • 141
  • 2
  • 7
7
votes
2 answers

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 on? It turns out these scripts were suddenly now…
drench
  • 205
  • 1
  • 7
6
votes
2 answers

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' < $if > ENDOFFILE or $ tr '$' '\$' < $if > ENDOFFILE …
user27164
6
votes
3 answers

How does cd command work? (unix)

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 cd command. And when I do cd - on my unix I get…
Radek
  • 1,133
  • 4
  • 26
  • 38
1
2 3
8 9