You are on page 1of 2

UNIX/LINUXCommandReferenceSheet

FileCommands

cat concatenatesanddisplaysfiles
cat > file placesstandardinputintofile
cd changecurrentdirectory
cmp comparestwofiles
cp copiesafileoradirectory
cut removescolumnsorfieldsfromthespecified
file(s)
diff displayslinebylinedifferencesbetweentwo
textfiles
head displaysthefirstlinesofthespecifiedfile(s)
join joinstwofiles
jot printsequentialorrandomdata
ln makehardorsymboliclinkstofiles
ls -al formattedlistingwithhiddenfiles
ls directorylisting
mkdir dir createadirectory dir
more/less outputthecontentsofthespecified
file(s)inpages
mv renameormoveafile
nl putlinenumbersonafile
od sequentiallycopieseachfiletostandardoutput,
displayingitaccordingtothespecifiedarguments;for
example,inhexadecimal(oftenusefulinconjunction
withdiff)
paste mergesamelinesofseveralfilesor
subsequentlinesofonefile
pr producesaprintedlistingofoneormorefiles
suitableforprinting
pwd printcurrentworkingdirectory
rm removethespecifiedfile(s);usingthe-rfflag
allowsadirectorytoberemoved1
sort sort,mergeorsequencechecktextfiles
split splitafileintopieces
tail displaysthelastlinesofthespecifiedfile(s)
tail -f file outputthecontentsoffileasit
grows,startingwiththelast10lines
touch changefileaccessandmodificationtimes;
canbeusedtocreateanew0byte(empty)file
tr translatecharactersfromonestringtoanother
uniq reportorfilteroutrepeatedlinesinafile
wc displayacountoflines,wordsandcharactersin
afile

SSH&SecureFileCopying

scp copiesfilesbetweenhostsonanetwork
sftp aninteractivefiletransferprogram
ssh user@host connectto hostasuser
ssh-copy-id user@host addyourkeyto
hostforusertoenableakeyedorpasswordless
login

1Use with extreme caution!

ProcessManagement
at/batchexecutecommandsatalatertime
bg listsstoppedorbackgroundjobs;resumea
stoppedjobinthebackground
cron clockdaemonthatexecutescommandsat
specifieddatesandtimes
crontab modifiestheuser'scrontabfile,whichis
usedbycron
fg bringsthespecifiedjobtoforeground
kill pid killprocessid pid
killall proc killallprocessesnamedproc1
nice invokeacommandwithanalteredscheduling
priority
ps displayyourcurrentlyactiveprocesses
renice alterpriorityofrunningprocesses
top displayallrunningprocesses

File&GroupPermissions

chmod octal file changethepermissionsof


filetooctal,whichcanbefoundseparatelyfor
user,group,andworldbyadding:
4read(r)
2write(w)
1execute(x)
Examples:
chmod 777 read,write,executeforall
chmod 755rwxforowner,rxforgroupandworld
Formoreoptions,see man chmod.
chgrp changethegroupIDofthespecifiedfilesor
directories
groups showgroupmemberships

Searching

grep searchforapatterninthespecifiedfiles
command | grep patternsearchforpattern
intheoutputofcommand
find file findallinstancesoffile (UNIX)
locate file findallinstancesoffile
xargs constructargumentlistsandinvokeutility

Compression

Youcanfindanumberofcompressionand
decompressionutilities.Checkthemanpagesfortar,
compress/uncompress,gzip/gunzipand
zip/unzip.Othersarealsoavailable.

tar cf file.tar files createatarnamed


file.tarcontainingfiles
tar xf file.tar extractthefilesfrom
file.tar
gzip file compressesfileandrenamesitto
file.gz
gunzip file.gz decompresses file.gzback
tofile

UNIX/LINUXCommandReferenceSheet
VersionControl
Seethemanualpagesforcvs,svnorrcs.

SystemInformation

absolute (CSCF/MFCFonly)convertfilenamesto
absolutepathnames
absolute `which app` (CSCF/MFCFonly)
showthefullpathtothe appthatwillberunby
default
cal showthismonth'scalendar
chfn changetheuser'sfingerinformation
date showthecurrentdateandtime
diskquota (CSCF/MFCFonly)displaytheuser's
diskquota
du showdiskusageofeachfile,recursively
finger user displayinformationabout user
history displaysthelistofrecentlyentered
commands
hostselect consultaconfigurationfiletoreturn
anoptimalhostnamebaseduponthespecified
attribute
lpr submitaprintrequest
lpq displaythecontentsofaprintqueue
man command showthemanualforcommand
mesg permitordenymessages
passwd changetheuser'spassword
ruptime showcurrentuptimeofotherhosts
uname -a showkernelinformation
uptime showcurrentuptime
w displaywhoisonline
whereis app showpossiblelocationsofapp
which app showwhichappwillberunbydefault
whoami whoyouareloggedinas

Compilation&Debugging

ddd graphicalfrontendtogdb
gcc GNUprojectCandC++compiler
g++ frontendtogcctoexplicitlycompileC++code
gdb GNUdebugger
gmake GNUversionofmake
make utilitytomaintaingroupsofprograms
xxgdb graphicalfrontendtogdb;existsoncpulinux

GenerallyUsefulTools
MFCF FAQ locatedat

http://webtest.mfcf.uwaterloo.ca/wiki/index.php/
MFCF_FAQ
http://www.cs.uwaterloo.ca/cscf/student/hosts

alistoftheserversavailableintheundergraduate
environment,highlightingtheroundrobinserver
names(recommendedforaccesstoaparticularserver
type)

.snapshot (CSCF/MFCFonly)Abackupsystemis
inplaceinthestudent.mathandstudent.cs
environmentswherehourly,daily,weeklyand
monthlybackupsaremade.See
http://webtest.mfcf.uwaterloo.ca/wiki/index.php/
Snapshots

alias createapseudonymforacommandor
seriesofcommands
aproposlocatecommandsbykeywordlookup
clear cleartheterminalscreen,ifpossible
dos2unixconverttextfilefromDOSformattoISO
format
init_home (CSCF/MFCFonly)reinitializeyour
homedirectory
ispell interactivespellingchecking
lock lockaterminalwhenyouareaway
man ascii displaysthemapoftheASCII
characterset
oed lookthingsupintheOxfordEnglishDictionary
script makesatypescriptofeverythingprinted
onyourterminal.
scriptfix cleanupscriptoutputfiles
spell outputswordsfromthenameddocuments
thatarenotinthespellinglistnorderivablefrom
wordsinthespellinglist
unalias removeapseudonymforacommandor
seriesofcommands
unix2dos converttextfilefromISOformatto
DOSformat
xlocklocksthelocalXdisplayuntilapasswordis
entered

Shortcuts

Ctrl+C haltsthecurrentcommand
Ctrl+Z stopsthecurrentcommand,resumewith
fgintheforegroundorbginthebackground
Ctrl+D logoutofcurrentsession,similarto
exit;usedtosignalendoffilewhenrunningan
applicationthatreadsfromstandardinput
Ctrl+W erasesonewordinthecurrentline
Ctrl+U erasesthewholeline
Ctrl+R typetobringuparecentcommand
^pre1^pre2 repeatsthelastcommandwith
leadingtextpre1replacedwithpre2
!:gs/pre1/pre2repeatsthelastcommandwith
alloccurrencesoftextpre1replacedwithpre2
!! repeatsthelastcommand
!comrepeatsthemostrecentcommandenteredthat
canbeuniquelyidentifiedasstartingwithcom
!num repeatsthecommandnumberednum
exit logoutofcurrentsession

You might also like