UNIX Commands

This post follows on from the UNIX Structure which introduced commands. Below is a list of the basic commands that can be used in a UNIX environment.  


Command/SyntaxWhat it will do

man [command]the standard UNIX documentation system

info [command]the GNU alternative to man

whatis [command]command description from whatis database

whereis [command]locates the command’s binary and manual pages associated with it

which [command]locates where a command is executed from

who or wshows who is logged on

whoamishows the current user’s login name

write [user]sends a message to another user

wallsends a message to everyone

unameprints basic system information

uname –adisplays all information

uname –odisplays the operating system’s name

uname – rdisplays the kernel version

uname –pdisplays the processor type

uname –idisplays hardware platform

hostnamedisplays the system’s host name

locate [text string]lists all files in its DB that match pattern

updatedbupdates locate’s DB

   Directory navigation and control commands in UNIX

Command/SyntaxWhat it will do

cd [directory]change directory

cd ../..change to parent directory two levels up

cd /change to system’s root

cd ~change to user’s home directory

ls [options] [directory or file]list directory contents

ls –lshow list of attributes

ls –ashow all files even hidden ones

ls –tshow files ordered by time

ls -rshow file list reversed

mkdir [options] directorymake a directory

mkdir -pcreates intermediate directories

mkdir –m 777sets the directory’s permissions to the specified value

pwdprint working (current) directory

treedisplays content in a tree like format

rmdir directorydelete a directory



File maintenance commands

Command/SyntaxWhat it will do

chgrp [options] group filechange the group of the file

chmod [options] filechange file or directory access permissions

chown [options] owner filechange the ownership of a file; can only be done by the superuser

cp [options] file1 file2copy file1 into file2; command creates or overwrites file2

cp –pcopies files with original permissions

cp –rcopies directory/ies recursively

mv [options] file1 file2move file1 into file2

rm [options] fileremove (delete) a file or directory

rm –r filerecursively deletes the directory and its contents

rm –f fileremoves a file or directory without asking for confirmation


 Display commands

Command/SyntaxWhat it will do

cat [options] fileconcatenate (list) a file

echo [text string]echo the text string to stdout

head [-number] filedisplayes the first number lines of a file

more, lesspage through a text file

tail [-number] filedisplays the last number lines of a file

tail -f filecontinuously displays the last 10 lines of file until <Ctrl>+C is pressed

zcat, bzcat filesame as cat but process compressed files

zless filesame as less but process compressed files

zmore filesame as more but process compressed files


  File archiving, compression


Command/SyntaxWhat it will do

tar [arg] destination sourcearchives source files/directories into destination-file archive

tar ccreate archive

tar zcompress archive using zip algorithm

tar vverbosely list files being processed

tar fwrite output to a file

tar xextract files from archive

zip, gzippackage and compress files (.gz)

gunzipuncompress .gz files

bzip2package and compress files (bz2)

bunzip2uncompress .bz2 files

 Remote connections

Command/SyntaxWhat it will do

telnet host portcommunicates with remote host using telnet protocol

ssh user@hostsecurely logs into remote machine and executes command on it

ftp hosttransfers files from remote host to local

scp file user@host:/pathsecurely transfers file between machines


 Text processing

Command/SyntaxWhat it will do

cutremove sections from each line of a file or standard input

cut -d “char”field separator

cut -f  num - num2outputs only listed fields

ciffcompare two text files line by line

grep [options] ‘search string’ filesearch argument file or standard input for all occurrences of the search string and lists them

grep -vselects non-matching lines

grep -iignore case

grep -A numprints num lines of trailing context

grep -B numprints num lines of leading context

egrep ‘pattern1|pattern2’ filesearch argument file or standard input for pattern1 OR pattern2 and lists them

zgrep, zegrepsame as grep and egrep but searches in compressed (.gz) files

sortsort lines of text files

uniqremove duplicate lines from input

uniq -cprecede each output line with the count of the number of times the line occurred in input

wcword/line/byte count in input text

wc -wcounts words in input text

wc -lcounts line in input text

wc -bcounts bytes in input text

sedpowerful stream editor

sed 's/foo/bar/'replaces 1st instance in a line

sed 's/foo/bar/4'replaces 4th instance in a line

sed 's/foo/bar/g'replace every instance in a line

sed 10qprint first 10 lines

sed 1,10ddelete lines between line 1 and 10

sed -n '/regexp/p'print only lines that match reg exp (emulate grep)

sed -n '/regexp/,$p'print section from reg exp till end of file

sed -n '/Foo/,/Bar/p'print section between reg exp

 File system utilities

Command/SyntaxWhat it will do

ln [target] [link name]link one file or directory to another

ln -screates a symbolic link to a file

stat [file]displays file status

touchcreates a new file or updates modification time if existed

dfdisplays free space

df -hhuman readable output

df -llist local partitions only

df -kdisplay values in Kilobytes

df -mdisplay values in Megabytes

dusummarise disk usage of each file, recursively for directories

du -mdisplay values in Megabytes

du -sdisplay values in file list

findsearch for files through a directory hierarchy

find . -name [string] search recursively starting from current directory

find / -printprints result

find / -type b,c,d,p,f,l,ssearch for files of a given type

find / -mtime + - [value]search for files with given mtime

find / -exec [command] {}\;execute command on result files


  Other commands

Command/SyntaxWhat it will do

datedisplays current date and time

kill [PID]sends signals to processes

kill -HUP [PID]restarts process forcing it to re-read its own config files

kill -9 [PID]terminates process

pkill stringsends signal to processes based on name or other attributes

psreports process status

ps -aselect all process with a tty

ps -uselect by effective user ID

ps -xselect process without tty

ps -efsame as ps -aux; useful on SunOS

passwd [user]changes password for self or given user

useradd -d home dir -p password -s shell [login]creates a user with given parameters

userdel -r [login]removes account from system along with user’s home directory

script filemakes a typescript of everything printed onto terminal

script -aappend output to file

script -c [command]executes command instead of running an interactive shell

su [user]switches between users

su - [user]forces shell to do a full login

host [IP] or [domain]DNS lookup utility

digDNS lookup utility