Show Menu
Cheatography

Linux Tutorial Cheat Sheet by

A cheat sheet for the impact cluster and data processing in linux

Cluster commands

qstat
print list of all your jobs
qsub <s­cri­pt>
submit <s­cri­pt> as a job
qlogin
login to an intera­ctive session on the cluster
qdel <job ids>
delete the jobs (<job ids> can be a pattern)

Browsing files

cd <d­est­ina­tio­n>
change directory
ls [patt­ern]
list all files or match pattern
pwd
print current directory
You can return to your home directory by using cd ~

Modifying files

rm [patt­ern]
remove files (-r for recursive)
mv [sour­ces] [dest­ina­tion]
move / rename file(s) or folder(s)
cp [sour­ces] [dest­ina­tion]
copy file(s) (-r to create desina­tion)

Modifying direct­ories

mv [sour­ces] [dest­ina­tion]
rename / move directory
mkdir <d­ire­cto­ry>
create a directory
rmdir <d­ire­cto­ry>
remove a directory
rm -rf <d­ire­cto­ry>
remove directory and all subdir­ect­ories

Finding files

find . -file -name "­*.t­xt"
Find all .txt files in the current directory and below and print
locate [patt­ern]
match files with pattern anywhere in the full path and print
Can combine with | grep. locate may require sudo updatedb from time to time, and won't work on cluster without some modifi­cation.

Viewing files

head [file­names]
print first 10 lines of file
tail [file­names]
print last 10 lines of file
cat [file­names]
concat­enate files and print

Task management

ps
See all of your active processes
top
Constantly updating list of ordered (by resources) processes
time <c­omm­and­>
print time taken to complete after command finishes running
kill <p­id>
terminate process with id <p­id>
 

Name Expansions

{a..z} or {1..1­00}
expands to the series e.g a b c d ...
*
expands to match anything, any number of times
?
Match anything once
$((2 + 2))
Arithmetic expansion (evaluates to 2)
$(­<c­omm­and­>)
expands to the result of the command
~
absolute path to home directory
ls *.txt - list all .txt files
cp *{0..9} - list files which end in a number between 0 and 9

Processing stdout

awk -F "­," '{print $<c­olumn number­>}'
print only column n of files
sort (-n)
sort alphab­eti­cally (alpha­num­eri­cally)
uniq (-c)
print only one instance of repeated lines (with count of lines)
grep (-i) [patt­ern]
print lines which contain pattern (ignore case)
wc -l
print number of lines
sed /<­pat­ter­n>­/<­rep­lac­eme­nt>/g
replace all instances matching <p­att­ern­> with <r­epl­ace­men­t>
To use on a collection of files, all commands would be prefixed by:
cat [files] |

Remote Managment

ssh <u­ser­nam­e>­@<­hos­t>
login to multi-user machine
scp <u­ser­nam­e>­@<­hos­t>­:[­remote source] <l­oca­l>
Cope file(s) from <h­ost­> to <l­oca­l> destin­ation.
rsync -t <u­ser­nam­e>­@<­hos­t>­:[­remote source] <l­oca­l>
only copy updated files from <h­ost­> to <l­oca­l>
For the multi-user linux machine, <h­ost­> should be stem-s­su-­linux

Useful

chmod +x <f­ile­>
give executable priveleges to <f­ile­>
seq <s­tar­t> <st­ep> <st­op>
print sequence of numbers from <s­tar­t> to <s­top­> in increments of <s­tep­>
man <c­omm­and­>
open the manual page for man
more <f­ile­>
print output in naviga­teable pages
fdisk -l
list all the connected drives and partitions
mount <p­art­iti­on> <d­ire­cto­ry>
directory will now lead to the partiton (useful for usb storage)
stdout can be piped into more to make long outputs readable.

Help Us Go Positive!

We offset our carbon usage with Ecologi. Click the link below to help us!

We offset our carbon footprint via Ecologi
 

Comments

No comments yet. Add yours below!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

          Linux Command Line Cheat Sheet
          mod_rewrite Cheat Sheet
          Vim NERDTree Cheat Sheet