Unix utilities

A list of common Unix utilities with brief, bare-bones examples and links to documentation. All of these utilities are available in Unix, Linux, and OS X systems in one form or another. Feel free to post tips, examples, and corrections or recommend other utilities in the comments.
Note: Remember that OS X Unix utilities will blow out your file’s resource fork, meaning that image previews, file types, and other information will be lost. Some files will refuse to work again. If you want to preserve your files just as they are on your Mac, use the included GUI utilities instead.
###Tar
[GNU tar manual](http://www.gnu.org/software/tar/manual/)
Archive a directory recursively:
tar cvf mydirectory.tar mydirectory
To extract a tarball:
tar xvf mydirectory.tar
To create a compressed directory:
tar cvzf mydirectory.tgz mydirectory
###Gzip
[GNU gzip manual](http://www.gnu.org/software/gzip/manual/gzip.html)
To zip a file called science.txt in place to a file called science.txt.gz:
gzip science.txt
Use gunzip to uncompress the file:
gunzip science.txt.gz
###Grep
[GNU grep manual](http://www.gnu.org/software/grep/doc/grep_toc.html#SEC_Contents)
grep [options] “searchstring” [directory / patterns]
Find the string “wilson” in all files in the current directory:
grep ‘wilson’ *
Find “wilson” only in text files:
grep ‘wilson’ *.txt
Find “wilson” in .txt files in another directory:
grep “serials” ~/Documents/doug/*.txt
Find “wilson”, case-insensitive, print line numbers of results, other directory, .txt files only:
grep -in ‘wilson’ ~/Documents/doug/*.txt

Leave a Reply

Your email address will not be published. Required fields are marked *