Ubuntu/Linux File Commands
return to DevLinuxTar-Zip Directory
# zip /path/to/dir $ cd /path/to $ tar -zcvf dir.tar.gz dir # unzip $ tar -zxvf dir.tar.gz # list files in zipped archive $ tar -tvf dir.tar.gz | less # read content of zipped file (without unzipping) $ zcat file.gz | less
Find Largest Files / Directories
Files
Favorite methods with sample output$ find . -size +200k -type f -print0 | xargs -0 ls -Ssh1 | head
2.4M ./foo/bar/some.log
616K ./sample.txt
280K ./another/snafu.zip
$ find . -size +200k -exec du -sk {} \; | sort -nr | less
2364 ./foo/bar/some.log
616 ./sample.txt
280 ./another/snafu.zipDirectories
$ du -B M --max-depth=5 . | sort -n -r | less 898M ./hg 536M ./tmp 362M ./hg/foo
Find Files
Basic Example
# basic find: find ROOT_DIR -name FILE_NAME $ find . -name *.log
Find Image Files
$ find . -type f -name *.jpg -o -name *.png -o -name *.gif | less
Grep By File Type
ref: http://www.unix.com/302166849-post3.html$ find . -type f -name '*.log' -exec grep -Hn 'foo' {} \; | lessFind/Chmod
# chmod only dirs
$ find /dir/to/chmod -type d -exec chmod 755 {} \;
# chmod only files
$ find /dir/to/chmod -type f -exec chmod 644 {} \;Diff
Directories
# with preferred (hg) diff syntax server:/opt/foo# diff -u conf/ /tmp/foo-conf-back/ diff: conf/cron: No such file or directory diff: /tmp/foo-conf-back/cron: No such file or directory Common subdirectories: conf/cron.d and /tmp/foo-conf-back/cron.d diff -u conf/emailserver.properties /tmp/foo-conf-back/emailserver.properties --- conf/emailserver.properties 2011-04-14 10:04:47.000000000 -0700 +++ /tmp/foo-conf-back/emailserver.properties 2011-05-03 09:53:42.000000000 -0700 @@ -1,3 +1 @@ -EmailServer=monty.python.com -EmailTo=mpalin@mailhost.monty.python.com +diff test Only in /tmp/foo-conf-back/: lol.conf # list only files that have changed server:/opt/foo# diff -q conf/ /tmp/foo-conf-back/ diff: conf/cron: No such file or directory diff: /tmp/foo-conf-back/cron: No such file or directory Common subdirectories: conf/cron.d and /tmp/foo-conf-back/cron.d Files conf/emailserver.properties and /tmp/foo-conf-back/emailserver.properties differ Only in /tmp/foo-conf-back/: lol.conf
References
Using "find" (codecoffee.com)Finding Large Files (cognitivesandbox.com)
Compress a Whole Linux Directory (cyberciti.biz)
[There are no comments on this page]