UNIX Command Cheat Sheet, Cheat Sheet of Linux skills

Basic commands in unix you need to know before hand

Typology: Cheat Sheet

2020/2021

Uploaded on 04/26/2021

jugnu900
jugnu900 🇺🇸

4.4

(7)

235 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
UNIX Command Cheat Sheet
Carnegie Observatories Summer Research Program
Every command and filename is CaSe sEnSiTiVe!
Command Description Examples and Options
<tab> Attempt to autocomplete Use this to speed up typing/avoid typos
Navigating Directories
ls List the contents of the directory. ls -larth /home/mcuser/science/code
cd Change directory. cd /home/mcuser/science
pwd present working directory. pwd
*Wild card, any number of chars. ls *.txt
?Wild card, 0 or 1 characters. ls foo?.txt
.Current directory. cd .
.. Directory one level up. cd ..
~Home directory. cd ~
-Previous directory. cd -
Modifying Directories and Files
mkdir Make new empty directory. mkdir MyNewDirectory
rmdir Remove empty directory. rmdir MyNewDirectory
mv Move files (overwrites destination). mv -i foo.txt foo2.txt
cp Copy files (overwrites destination). cp -i ../foo.txt .
rm Remove files. CANNOT UNDO! rm -i foo.txt
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
pf2

Partial preview of the text

Download UNIX Command Cheat Sheet and more Cheat Sheet Linux skills in PDF only on Docsity!

UNIX Command Cheat Sheet

Carnegie Observatories Summer Research Program Every command and filename is CaSe sEnSiTiVe!

Command Description Examples and Options Attempt to autocomplete Use this to speed up typing/avoid typos Navigating Directories ls List the contents of the directory. ls -larth /home/mcuser/science/code cd Change directory. cd /home/mcuser/science pwd present w orking d irectory. pwd

  • Wild card, any number of chars. ls *.txt ? Wild card, 0 or 1 characters. ls foo?.txt

. Current directory. cd. .. Directory one level up. cd .. ~ Home directory. cd ~

  • Previous directory. cd - Modifying Directories and Files mkdir Make new empty directory. mkdir MyNewDirectory rmdir Remove empty directory. rmdir MyNewDirectory mv Move files (overwrites destination). mv -i foo.txt foo2.txt cp Copy files (overwrites destination). cp -i ../foo.txt. rm Remove files. CANNOT UNDO! rm -i foo.txt

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