

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Basic commands in unix you need to know before hand
Typology: Cheat Sheet
1 / 2
This page cannot be seen from the preview
Don't miss anything!


Carnegie Observatories Summer Research Program Every command and filename is CaSe sEnSiTiVe!
Command Description Examples and Options
. Current directory. cd. .. Directory one level up. cd .. ~ Home directory. cd ~
chmod
Change file permissions. rwx = read, write, execute. ugoa = user, group, other, all.
chmod a+rwx badger.txt chmod o-wx badger.txt chmod u+x myscript.sh Viewing Files in Terminal less View files in terminal window. less foo.txt cat Concatenate files. cat foo1.txt foo2.txt head Display first 10 lines. head -20 foo.txt tail Display last 10 lines. tail -f logfile.txt Searching
grep Search for word(s) in a file.
grep myvarname *.txt grep rodent *.txt grep "Hello World" *.txt
find Search a path for files/directories that match some specification.
find playground -name ".txt" find playground -type d find playground -not -name ".txt" Environment Variables $HOME Home directory. workpath=$HOME/playground $SHELL Shell name. echo $SHELL $USER User name. echo $USER $PATH Paths to look in for executables. PATH=${PATH}:/my/new/program/path/bin env List environment vars and values. env | less
Command Description Examples and Options File Manipulation wc Word count. wc -l mycode.py sort Sort input alphanumerically.
| Pipe/filter output through another program.
cat foo.txt | less sort myfile.txt | grep mykeyword
Redirect standard output to. Over- writes existing file.
cat foo.txt > foo2.txt
Redirect standard output and con- catenate to.
cat foo.txt >> foo2.txt
< Redirect standard input from. less < foo.txt awk Advanced operations by column. sed Advanced operations by row. Job/process Manipulation & Run process in background. ./run_job.sh & jobs Show your current processes jobs ps Show processes (more flexible) ps -u username top Show top active processes top -u username kill Stop a job kill processid Ctrl-z Pause current job ./run_job.sh; Ctrl-z Ctrl-c Cancel current job ./run_job.sh; Ctrl-c bg Resume process in background ./run_job.sh; Ctrl-z; bg % fg Bring process to foreground fg % Remote Connections ssh Secure shell login. ssh -Y [email protected] scp Secure copy. scp [email protected]:path/to/file.txt. wget Download file from remote URL. wget www.google.com -O google.html Ctrl-d Exit login. Sometimes disabled. Can also use exit, logout Miscellaneous man Manual for other commands. man cat sleep Do nothing sleep 30 touch Create empty file/update timestamp touch newfile.txt whoami Print current user. whoami du Disk usage. du -shc mydirectory/* df Disk free. df -h diff Shows differences between two files. diff -w file1.txt file2.txt echo Write text to screen. echo "Hello? Can you hear me?" which Find path for command. which gcc
tar Compress/uncompress files. tar -zcvf files.tar.gz a.txt b.fits tar -zxvf downloadedstuff.tar.gz history See command history. history | grep myscript.py alias Create command shortcut. alias lrt='ls -lhrt' source Execute file in shell. source ˜/.bash_profile