When programs conclude they return an exit status.
- 0 is success, else is failure
- positive integers represent an error state, usually 1 is used
- in Bash,
$?can be used to access last commands exit status
A helpful resources outside of man pages:
- tldr.sh
- web client tldr.inbrowser.app
Where Should Programs Go?
/usr- all system-wide, read-only files installed by (or provided by) the OS/usr/local- system-wide, read-only files installed by the local administrator (usually, you). And that's why most directory names from/usrare duplicated here./opt- an atrocity meant for system-wide, read-only and self-contained software. That is, software that does not split their files overbin,lib,share,includelike well-behaved software should.~/.local- the per-user counterpart of/usr/local, that is: software installed by (and for) each user. Like/usr, it has its own~/.local/share,~/.local/bin,~/.local/lib.~/.local/opt- the per-user counterpart of/opt
Useful Programs
apropos <search>- searches man page titles
cut [-d <delim>] -f <fields to remain> <files>- takes ASCII structured file separated by a delimiter like
TABand cut returns the fields indicated cut -d "," -f 1,5-7 datafile.csv
- takes ASCII structured file separated by a delimiter like
paste [-d <sep>] <files>- steps through multiple files in parallel
- delimiter is what separates each line from each file e.g.
tr <options> <string1> <string>- converts characters in first string to characters in the second string
- takes from stdin
-ccomplement the first string-ssqueeze character repetitions of string1 characters into a single occurrence ("####" -> "#")tr '[A-Z]' '[a-z]' < file.txt
comm [<output options>] <file1> <file2>- two sorted files are compared, 3 columns are produced
- col 1 contains only lines unique to file1
- col 2 contains only lines unique to file2
- col 3 contains common lines
-1suppress col 1-2duh-3duh
uniq <file>- compresses adjacent repeated lines into a single line
-coutputs the counts of the number of copies
sort [options] <file>- outputs to stdout
-uremoves duplicate entries-t <char>used as field separator,TABis default-kcan sort on a particular column of structured file
basename /path/file.txt- strips the directory and file extensions from a path
grep [options] <pattern string> <file>- searches for patterns in one or more files
- returns matches to stdout
- returns 0 on successful find, else 1
test <expression>- does conditional checks for a number of common operations
- some examples
-e FileNameFileName exists-b FilenameReturns a True exit value if the specified FileName exists and is a block special file-c FileName- FileName is a character special file-d FileNameFileName is a directory-f FileNameFileName is a regular file-g FileNameFileName's Set Group ID bit is set-h FileNameFileName is a symbolic link-k FileNameFileName's sticky bit is set-L FileNameFileName is a symbolic link-p FileNameFileName is a named pipe (FIFO)-r FileNameFileName is readable by the current process-s FileNameFileName has a size greater than 0-t FileDescriptorFileDescriptor is open and associated with a terminal-u FileNameFileName's Set User ID bit is set
find [options] <path> [<expression>]- recursively searches for file patterns
-name <pattern>test file name matches pattern-type <c>type of file is specified byd/f/l-newer <file>test file has been accessed more recently than<file>was modified-printprints the full path name of file-exec <command>execute command on all files found (like JavaScript.map())- command terminated with
\; {}refers to file found
- command terminated with
-ok <command>same as command except user is prompted first-perm <mode>finds only files with certain permissionsmodecan be octal or symbolic
diff <file1> <file2>- shows the differences between to files
grep [<options>] <regex> <file>-icase insensitive-nprepend numbers of matching lines-vinvert match so only non-matching lines reported
- sed
headandtail- display n lines from top or bottom of
-n <number|-number>shownlines, if negative show all but finalnlines
Interesting Links
- Unix Program Design
- Rob Pike and Brian W. Kernighan on the
catprogram and how it is a good example of Unix program philosphy.
- Rob Pike and Brian W. Kernighan on the