I really wanted a place to look for some very common Unix commands. This post is credited to:

Frank McCown, Ph.D.
Assistant Professor
Computer Science Department
Harding University


System related

uptime 	Show how long the system has been up
uname -a 	Show the OS name and version
hostname 	Shows the machine's name
ps -f -u username 	Lists all the processes I'm running
echo $0 	Shows what shell I'm using
echo $path 	Shows my path (or any environment variable)

Network related

netstat 	List all TCP connections
netstat -a 	List all active ports
nslookup host 	Get IP addr for host
ping host 	See if a host is accessible
telnet domain_name 80 	Use telnet to make an HTTP request
Example to view http://www.harding.edu/comp/:
telnet www.harding.edu 80
GET /comp/ HTTP/1.1
Host: www.harding.edu

Disk space

df 	Shows the amount of disk space in use
df /node_or_dirname 	Shows detailed information about the file system node or dir name
du 	Shows the amount of disk space used in every dir from current location
du -ks ~fmccown 	Shows the amount of disk space user fmccown is using (in KB)
cd;du -k | sort -nr | more 	Shows the disk space used (in KB) for every directory in sorted order

File processing

file myfile 	Short summary of what type of file myfile is
cat file1 file2 > file3 	Concatenates file1 and file2 and stores the result in file3
sort file.txt 	Sorts a file
uniq file.txt 	Remove duplicate lines from a sorted file
wc file.txt 	Counts number of lines, words, and characters in a file
grep search_str file.txt 	Search for a search_str in a files
tail -f file.txt 	List the contents of a file as it is being added to
tail -n 100 file.txt 	List the last 100 lines of a file
find . -name "*html" 	Find all files named *html starting in the current dir
find . -exec grep "hello" '{}' \; -print 	Run grep on all files starting in the current dir
cat myfile | hexdump -C 	Produce a hexdump of myfile

File compression

tar cfz my.tar.gz *.html 	Creates a gzipped tar file for all .html files
tar -tzf my.tar.gz 	Lists the contents of my.tar.gz
tar xvfz my.tar.gz 	Uncompresses and untars my.tar.gz
gzip myfile.txt 	Compresses myfile.txt creating myfile.txt.gz
gzip -d myfile.txt.gz 	Uncompresses myfile.txt.gz creating myfile.txt
bzip2 myfile.txt 	Compresses myfile.txt creating myfile.txt.bz2 (Use -k to keep myfile.txt)
bzip2 -d myfile.txt.bz2 	Uncompresses myfile.txt.bz2 creating myfile.txt

I/O redirection

cmd > log.txt 	Redirect cmd output (stdout) to log.txt
cmd >> log.txt 	Append stdout to log.txt
cmd 1> out_log.txt  2> err_log.txt 	Send stdout to out_log.txt and stderr to err_log.txt
cmd &> log.txt 	Redirect stdout and stderr to log.txt. Note: use >& for C shell.

Running processes

./cmd & 	Run process in the background
nohup ./cmd & 	Run process in the background, and don't terminate when shell is terminated

BTW: If you know how to make the pre:hover css attribute expand the <pre> tag versus the scrolling, I would love to hear your comment. I’ll hack it later, but I have to get back to coding right now.

/* I am using the wp-syntax plugin for my code examples to solve the css issue. If you write about code I recommend it. It can be found at the plugin database on WordPress extensions site.


Leave a Reply

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