rm
rm ecluding files:
$rm !(*.foo|*.bar|*.baz)
tar
Copy Files and keep dir structure
Example: Back up all *.pl and *.sh files to a new directory with timestamp and keep the original directory structure.
ArchT60::/tmp
kent$ tree /tmp/test
/tmp/test
|-- a.txt
|-- b.pl
|-- c.pl
`-- one
|-- one.pl
|-- one.txt
`-- two
|-- two.pl
`-- two.sh
ArchT60::/tmp/bak
kent$ tree /tmp/bak
/tmp/bak
0 directories, 0 files
ArchT60::/tmp
kent$ mkdir -p /tmp/bak/bak$(date +%Y%m%d) && find /tmp/test -regex ".*.[pl|sh]" -print | xargs tar -cf - | tar -xf - -C /tmp/bak/bak$(date +%Y%m%d)
ArchT60::/tmp
kent$ tree /tmp/bak
/tmp/bak
`-- bak20110306
`-- tmp
`-- test
|-- b.pl
|-- c.pl
`-- one
|-- one.pl
`-- two
|-- two.pl
`-- two.sh
Transfer files/dirs to remote (ssh)
**-** is the key. (standard input)
tar -cf - /home/kent/Desktop/tmp/myFile |ssh user@host "cd someDir; tar -xf - "
cp & rm
-
backup copy
cp test{,_`date +%F`}.log test_2011-12-10.log copied. cp test.log{,.`date +%F`} test.log.2011-12-12 copied
- rm excluding files
#bash: shopt -s extglob $ rm !(*.foo|*.bar|*.baz) `
Zsh also has its own extended globs:
setopt extended_glob rm -rf ^var_(opt|log)
tee
kent$ cat t.txt this is the first line now comes the 2nd line kent$ cat t.txt|tee >(sed -n 1p >a.txt) >(sed -n 2p >b.txt) this is the first line now comes the 2nd line kent$ cat a.txt this is the first line ArchT60::/tmp kent$ cat b.txt now comes the 2nd line
sort
-
-mmerge sorted file- sort reads a line from each file.
- It orders these lines and selects the one which should come first. This line gets sent to the output, and a new line is read from the file which contained this line.
- Repeat step 2 until there are no more lines in any file. -At this point, the output should be a perfectly sorted file.
-
-Msort month likeJAN, DEC