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 <sc­rip­t>
submit <sc­rip­t> 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 <de­sti­nat­ion>
change directory
ls [pattern]
list all files or match pattern
pwd
print current directory
You can return to your home directory by using cd ~

Modifying files

rm [pattern]
remove files (-r for recursive)
mv [sources] [desti­nation]
move / rename file(s) or folder(s)
cp [sources] [desti­nation]
copy file(s) (-r to create desina­tion)

Modifying direct­ories

mv [sources] [desti­nation]
rename / move directory
mkdir <di­rec­tor­y>
create a directory
rmdir <di­rec­tor­y>
remove a directory
rm -rf <di­rec­tor­y>
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 [pattern]
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 [filen­ames]
print first 10 lines of file
tail [filen­ames]
print last 10 lines of file
cat [filen­ames]
concat­enate files and print

Task management

ps
See all of your active processes
top
Constantly updating list of ordered (by resources) processes
time <co­mma­nd>
print time taken to complete after command finishes running
kill <pi­d>
terminate process with id <pi­d>
 

Name Expansions

{a..z} or {1..100}
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)
$(<co­mma­nd>)
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) [pattern]
print lines which contain pattern (ignore case)
wc -l
print number of lines
sed /<pa­tte­rn>/<re­pla­cem­ent>/g
replace all instances matching <pa­tte­rn> with <re­pla­cem­ent>
To use on a collection of files, all commands would be prefixed by:
cat [files] |

Remote Managment

ssh <us­ern­ame>@<ho­st>
login to multi-user machine
scp <us­ern­ame>@<ho­st>:[remote source] <lo­cal>
Cope file(s) from <ho­st> to <lo­cal> destin­ation.
rsync -t <us­ern­ame>@<ho­st>:[remote source] <lo­cal>
only copy updated files from <ho­st> to <lo­cal>
For the multi-user linux machine, <ho­st> should be stem-s­su-­linux

Useful

chmod +x <fi­le>
give executable priveleges to <fi­le>
seq <st­art> <st­ep> <st­op>
print sequence of numbers from <st­art> to <st­op> in increments of <st­ep>
man <co­mma­nd>
open the manual page for man
more <fi­le>
print output in naviga­teable pages
fdisk -l
list all the connected drives and partitions
mount <pa­rti­tio­n> <di­rec­tor­y>
directory will now lead to the partiton (useful for usb storage)
stdout can be piped into more to make long outputs readable.
 

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