Press s for speaker notes
var="some value" export ENVAR="some global value" command_out=$(some command) echo $var echo $ENVAR echo $command_out
command -l # short form flags command -la # 2 short form flags command --long # long form flags command --input INPUT # example of input
Prints the current directory
$ pwd
change directory
$ cd ~/your/directory $ pwd /home/$USER/your/directory $ cd ~ # cd /home/$USER $ pwd /home/jeet $ cd .. $ pwd /home
list the current directory’s contents
$ ls $ ls -a $ ls -l $ ls -la
$ touch file $ touch existing-file -d month/day/year
$ mv SOURCE DESTINATION $ ls file1 $ mv file1 file2 $ ls file2 $ ls dir1 dir2 $ mv dir1 dir2 mv: cannot move 'dir1' ro 'dir2' : Directory not empy $ mv dir1 dir2 -f $ ls dir2
$ cp SOURCE DEST $ ls file1 $ cp file1 file2 $ ls file1 file2
$ ln source-file dest-file $ ls -l -rw-rw-r-- jeet jeet ... source-file -rw-rw-r-- jeet jeet ... dest-file $ ln source-file dest-file -s $ ls -l -rw-rw-r-- jeet jeet ... source-file lrwxrwxrwx jeet jeet ... dest-file -> source-file
$ rm file -i rm: remove regular file 'file'? # your input here # no more file $ rm dir rm: cannot remove 'dir' : Is a directory $ rm dir -r # all good
$ mkdir dir $ mkdir dir1/dir2/dir2 mkdir: cannot create directory 'dir1/dir2/dir3': No such file or directory $ mkdir dir1/dir2/dir2 -p
$ cat file # contense of file $ cat file1 file2 # contense of both files
$ head file -n 20
$ tail file -n 20
$ ls -l -rw-rw-r-- ... file $ chmod +x file $ ls -l -rwxrwxr-x ... file $ chmod -rwx file ---------- ... file
echo "a string" a string echo -e "this is a \n multiline string " this is a multiline string echo $VAR # contense of VAR
$ cat file fox fax fex $ grep "fox" file fox $ grep "f.x" file $ grep "fox" file -v fax fex
$ sed 's/REGEX/REPLACEMENT/FLAG' file $ cat file the fox did fox things to say fox you to big fox $ sed 's/fox/wolf/' file the wolf did fox things to say fox you to big fox $ sed 's/fox/wolf/g' file the wolf did wolf things to say wolf you to big wolf $ sed 's/fox/wolf/g' file -i $ cat file the wolf did wolf things to say wolf you to big wolf
some-pattern { some action } another-pattern { a different action } { all lines match this action } $0 ~ /some regex/ { print $1, $2 # for example } $1 == 18 { print $2, $1 }
$ cat file this file is has space seperated words it has multiple lines $ awk '{print $0}' file # we just made a slower less convenient cat! this file is has space seperated words $ awk '{print $1}' file # print the first element of each line this it $ cat file.csv name,age,job Jeet,18,Being a Nerd $ awk -F, '{printf("name:%s job:%s age:%s", $1, $3, $2)}' file.csv name:Jeet job:Being a nerd age:18
$ cat file-o-numbers 1 15 2 30 $ sort -n file-o-numbers 1 2 15 30
$ cat file this this has some some duplicates $ uniq file this has some duplicates
$ cat file line 1 line 2 line 3 $ wc file 3 6 24 $ wc -l 3 $ wc -w 6 $ wc -c 24
$ apt update Permission denied $ sudo apt update # works
$ w 02:26:18 up 8:52, 2 users, load average: 0.94, 1.29, 1.15 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT jeet :1 :1 17:34 ?xdm? 4:07m 0.01s /usr/libexec/gdm-x-session --run-script env GNOME_SHELL_SESSION_MODE=pop /usr/bin/gnome-session --session=pop root tty4 - 02:24 1:52 0.02s 0.01s -bash
$ pgrep emacs 23878 23878 $ pgrep firefox 6997
$ pkill emacs # waits for emacs to finish $ pkill 23878 -9 # kills emacs instantly
$ htop
$ man command
$ cat file1 file2 > file1+file2 $ cat non-existant-file 2> /dev/null # no errors and no output
$ some-output >> some-log-file
$ cat file Jeet,18 Jen,19 Jeff,20 Jerome,16 Dan,18 Mark,17 $ cat file | grep -i "j." | sort -d | awk -F, '$2 >= 18 {print "name:", $1, "age:", $2}' name: Jeet age: 18 name: Jen age: 19
gist_list=$(gh gist list) gist_to_find=$(echo "$gist_list" | awk '{print $2}' | fzf --layout=reverse) gh gist edit $(echo "$gist_list" | grep $gist_to_find | awk '{print $1}')