12.07.2015 Views

Advanced Bash-Scripting Guide

Advanced Bash-Scripting Guide

Advanced Bash-Scripting Guide

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

ash$ ls -ltotal 0<strong>Advanced</strong> <strong>Bash</strong>-<strong>Scripting</strong> <strong>Guide</strong>The double-dash is also used in conjunction with set.-set -- $variable (as in Example 14-18)redirection from/to stdin or stdout [dash].bash$ cat -abcabc...Ctl-DAs expected, cat - echoes stdin, in this case keyboarded user input, to stdout. But, does I/Oredirection using - have real-world applications?(cd /source/directory && tar cf - . ) | (cd /dest/directory && tar xpvf -)# Move entire file tree from one directory to another# [courtesy Alan Cox , with a minor change]# 1) cd /source/directory# Source directory, where the files to be moved are.# 2) &&# "And-list": if the 'cd' operation successful,# then execute the next command.# 3) tar cf - .# The 'c' option 'tar' archiving command creates a new archive,# the 'f' (file) option, followed by '-' designates the target file# as stdout, and do it in current directory tree ('.').# 4) |# Piped to ...# 5) ( ... )# a subshell# 6) cd /dest/directory# Change to the destination directory.# 7) &&# "And-list", as above# 8) tar xpvf -# Unarchive ('x'), preserve ownership and file permissions ('p'),# and send verbose messages to stdout ('v'),# reading data from stdin ('f' followed by '-').## Note that 'x' is a command, and 'p', 'v', 'f' are options.## Whew!# More elegant than, but equivalent to:# cd source/directory# tar cf - . | (cd ../dest/directory; tar xpvf -)## Also having same effect:# cp -a /source/directory/* /dest/directory# Or:# cp -a /source/directory/* /source/directory/.[^.]* /dest/directory# If there are hidden files in /source/directory.Chapter 3. Special Characters 20

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!