<<

Introduction to Line

● Files and directories ● Some useful commands (, , , , , ) ● ● Pipes ● Variables ● Background processes ● Remote connections (e.g. ssh, ) ● Scripts

The Command Line

● What is it? ● An interface to UNIX ● You commands, things happen ● Also referred to as a “” ● We'll use the shell – check you're using it by typing (you'll see what this means later): ● echo $SHELL ● If it doesn't say “bash”, then type bash to get into the bash shell

Files and Directories

/

home var usr

mcuser abenson drmentor

science catvideos stuff

data code report

M51.fits simulate. analyze.py report.tex

Files and Directories

● Get a pre-made set of directories and files to work with ● We'll about what these commands do later ● The “$” is the command prompt (yours might differ). Type what's listed after hit, then press enter.

$$ wgetwget http://bit.ly/1TXIZSJhttp://bit.ly/1TXIZSJ -O-O playground.tarplayground.tar

$$ tartar xvfxvf playground.tarplayground.tar

Files and directories

$$ pwdpwd /home/abenson/home/abenson $$ cdcd playgroundplayground $$ pwdpwd /home/abenson/playground/home/abenson/playground $$ lsls animalsanimals documentsdocuments sciencescience $$ mkdirmkdir mystuffmystuff $$ lsls animalsanimals documentsdocuments mystuffmystuff sciencescience $$ cdcd animals/mammalsanimals/mammals $$ lsls badger.txtbadger.txt porcupine.txtporcupine.txt $$ lsls -l-l totaltotal 88 -rw---r--.-rw-r--r--. 11 abensonabenson abensonabenson 19441944 MayMay 3131 18:0318:03 badger.txtbadger.txt -rw-r--r--.-rw-r--r--. 11 abensonabenson abensonabenson 13471347 MayMay 3131 18:0518:05 porcupine.txtporcupine.txt

Files and directories

“Present Working

$$ pwdpwd Shows the full of your current /home/abenson/home/abenson location in the filesystem. $$ cdcd playgroundplayground $$ pwdpwd /home/abenson/playground/home/abenson/playground $$ lsls animalsanimals documentsdocuments sciencescience $$ mkdirmkdir mystuffmystuff $$ lsls animalsanimals documentsdocuments mystuffmystuff sciencescience $$ cdcd animals/mammalsanimals/mammals $$ lsls badger.txtbadger.txt porcupine.txtporcupine.txt $$ lsls -l-l totaltotal 88 -rw-r--r--.-rw-r--r--. 11 abensonabenson abensonabenson 19441944 MayMay 3131 18:0318:03 badger.txtbadger.txt -rw-r--r--.-rw-r--r--. 11 abensonabenson abensonabenson 13471347 MayMay 3131 18:0518:05 porcupine.txtporcupine.txt

Files and directories

$$ pwdpwd “Change Directory” /home/abenson/home/abenson $$ cdcd playgroundplayground Change to a new directory – relative to $$ pwdpwd current location unless you give a full /home/abenson/playground/home/abenson/playground path $$ lsls animalsanimals documentsdocuments sciencescience $$ mkdirmkdir mystuffmystuff $$ lsls animalsanimals documentsdocuments mystuffmystuff sciencescience $$ cdcd animals/mammalsanimals/mammals $$ lsls badger.txtbadger.txt porcupine.txtporcupine.txt $$ lsls -l-l totaltotal 88 -rw-r--r--.-rw-r--r--. 11 abensonabenson abensonabenson 19441944 MayMay 3131 18:0318:03 badger.txtbadger.txt -rw-r--r--.-rw-r--r--. 11 abensonabenson abensonabenson 13471347 MayMay 3131 18:0518:05 porcupine.txtporcupine.txt

Files and directories

$$ pwdpwd /home/abenson/home/abenson $$ cdcd playgroundplayground $$ pwdpwd “LiSt” /home/abenson/playground/home/abenson/playground $$ lsls List the content of the current directory. animalsanimals documentsdocuments sciencescienceShows both directories and files. $$ mkdirmkdir mystuffmystuff $$ lsls animalsanimals documentsdocuments mystuffmystuff sciencescience $$ cdcd animals/mammalsanimals/mammals $$ lsls badger.txtbadger.txt porcupine.txtporcupine.txt $$ lsls -l-l totaltotal 88 -rw-r--r--.-rw-r--r--. 11 abensonabenson abensonabenson 19441944 MayMay 3131 18:0318:03 badger.txtbadger.txt -rw-r--r--.-rw-r--r--. 11 abensonabenson abensonabenson 13471347 MayMay 3131 18:0518:05 porcupine.txtporcupine.txt

Files and directories

$$ pwdpwd /home/abenson/home/abenson $$ cdcd playgroundplayground $$ pwdpwd “LiSt” /home/abenson/playground/home/abenson/playground $$ lsls List the content of the current directory. animalsanimals documentsdocuments sciencescienceShows both directories and files. $$ mkdirmkdir mystuffmystuff $$ lsls animalsanimals documentsdocuments mystuffmystuff sciencescience $$ cdcd animals/mammalsanimals/mammals $$ lsls badger.txtbadger.txt porcupine.txtporcupine.txt $$ lsls -l-l totaltotal 88 -rw-r--r--.-rw-r--r--. 11 abensonabenson abensonabenson 19441944 MayMay 3131 18:0318:03 badger.txtbadger.txt -rw-r--r--.-rw-r--r--. 11 abensonabenson abensonabenson 13471347 MayMay 3131 18:0518:05 porcupine.txtporcupine.txt

Files and directories

$$ pwdpwd /home/abenson/home/abenson $$ cdcd playgroundplayground $$ pwdpwd /home/abenson/playground/home/abenson/playground “ DIRectory” $$ lsls animalsanimals documentsdocuments sciencescience Make a new directory in the current $$ mkdirmkdir mystuffmystuff directory $$ lsls animalsanimals documentsdocuments mystuffmystuff sciencescience $$ cdcd animals/mammalsanimals/mammals $$ lsls badger.txtbadger.txt porcupine.txtporcupine.txt $$ lsls -l-l totaltotal 88 -rw-r--r--.-rw-r--r--. 11 abensonabenson abensonabenson 19441944 MayMay 3131 18:0318:03 badger.txtbadger.txt -rw-r--r--.-rw-r--r--. 11 abensonabenson abensonabenson 13471347 MayMay 3131 18:0518:05 porcupine.txtporcupine.txt

Files and directories

$$ pwdpwd /home/abenson/home/abenson $$ cdcd playgroundplayground $$ pwdpwd /home/abenson/playground/home/abenson/playground “MaKe DIRectory” $$ lsls animalsanimals documentsdocuments sciencescience Make a new directory in the current $$ mkdirmkdir mystuffmystuff directory $$ lsls animalsanimals documentsdocuments mystuffmystuff sciencescience $$ cdcd animals/mammalsanimals/mammals $$ lsls badger.txtbadger.txt porcupine.txtporcupine.txt $$ lsls -l-l totaltotal 88 -rw-r--r--.-rw-r--r--. 11 abensonabenson abensonabenson 19441944 MayMay 3131 18:0318:03 badger.txtbadger.txt -rw-r--r--.-rw-r--r--. 11 abensonabenson abensonabenson 13471347 MayMay 3131 18:0518:05 porcupine.txtporcupine.txt

Files and directories

$$ pwdpwd /home/abenson/home/abenson $$ cdcd playgroundplayground $$ pwdpwd /home/abenson/playground/home/abenson/playground $$ lsls animalsanimals documentsdocuments sciencescience $$ mkdirmkdir mystuffmystuff $$ lsls animalsanimals documentsdocuments mystuffmystuff sciencescience $$ cdcd animals/mammalsanimals/mammals $$ lsls Options “-l” to requests a long badger.txtbadger.txt porcupine.txtporcupine.txt listing. $$ lsls -l-l totaltotal 88 -rw-r--r--.-rw-r--r--. 11 abensonabenson abensonabenson 19441944 MayMay 3131 18:0318:03 badger.txtbadger.txt -rw-r--r--.-rw-r--r--. 11 abensonabenson abensonabenson 13471347 MayMay 3131 18:0518:05 porcupine.txtporcupine.txt

Files and directories

$$ pwdpwd /home/abenson/home/abenson $$ cdcd playgroundplayground $$ pwdpwd /home/abenson/playground/home/abenson/playground $$ lsls animalsanimals documentsdocuments sciencescience $$ mkdirmkdir mystuffmystuff $$ lsls animalsanimals documentsdocuments mystuffmystuff sciencescience $$ cdcd animals/mammalsanimals/mammals $$ lsls Options “-l” to ls requests a long badger.txtbadger.txt porcupine.txtporcupine.txt listing. $$ lsls -l-l totaltotal 88 -rw-r--r--.-rw-r--r--. 11 abensonabenson abensonabenson 19441944 MayMay 3131 18:0318:03 badger.txtbadger.txt -rw-r--r--.-rw-r--r--. 11 abensonabenson abensonabenson 13471347 MayMay 3131 18:0518:05 porcupine.txtporcupine.txt

Files and directories

$$ pwdpwd /home/abenson/home/abenson $$ cdcd playgroundplayground $$ pwdpwd /home/abenson/playground/home/abenson/playground $$ lsls animalsanimals documentsdocuments sciencescience $$ mkdirmkdir mystuffmystuff $$ lsls animalsanimals documentsdocuments mystuffmystuff sciencescience $$ cdcd animals/mammalsanimals/mammals $ ls e $ ls s es m on yt ti e badger.txtbadger.txtsi porcupine.txtporcupine.txt b n m is p in tio a $ ls m-l r u e a n $ lser -l se ro iz re ile totaltotalP 88 U G S C F -rw-r--r--.-rw-r--r--. 11 abensonabenson abensonabenson 19441944 MayMay 3131 18:0318:03 badger.txtbadger.txt -rw-r--r--.-rw-r--r--. 11 abensonabenson abensonabenson 13471347 MayMay 3131 18:0518:05 porcupine.txtporcupine.txt

Files and directories

$$ lsls -a-a ...... badger.txtbadger.txt porcupine.txtporcupine.txt $$ cdcd .. $$ pwdpwd /home/abenson/playground/animals/mammals/home/abenson/playground/animals/mammals $$ cdcd .... $$ pwdpwd /home/abenson/playground/animals/home/abenson/playground/animals $$ cdcd $$ pwdpwd /home/abenson/home/abenson $$ cdcd ~~ $$ pwdpwd /home/abenson/home/abenson

Files and directories

$$ cdcd ~/playground/animals/mammals/~/playground/animals/mammals/ $$ lsls badger.txtbadger.txt porcupine.txtporcupine.txt $$ lsls -l-l totaltotal 88 -rw-r--r--.-rw-r--r--. 11 abensonabenson abensonabenson 19441944 MayMay 3131 18:0318:03 badger.txtbadger.txt -rw-r--r--.-rw-r--r--. 11 abensonabenson abensonabenson 13471347 MayMay 3131 18:0518:05 porcupine.txtporcupine.txt $$ chmodchmod go+wgo+ badger.txtbadger.txt $$ lsls -l-l totaltotal 88 -rw-rw-rw-.-rw-rw-rw-. 11 abensonabenson abensonabenson 19441944 MayMay 3131 18:0318:03 badger.txtbadger.txt -rw-r--r--.-rw-r--r--. 11 abensonabenson abensonabenson 13471347 MayMay 3131 18:0518:05 porcupine.txtporcupine.txt $$ cpcp badger.txtbadger.txt super_badger.txtsuper_badger.txt $$ lsls badger.txtbadger.txt porcupine.txtporcupine.txt super_badger.txtsuper_badger.txt $$ mvmv super_badger.txtsuper_badger.txt super_mellivorinae.txtsuper_mellivorinae.txt $$ lsls badger.txtbadger.txt porcupine.txtporcupine.txt super_mellivorinae.txtsuper_mellivorinae.txt

Files and directories

$$ cdcd ~/playground/animals/mammals/~/playground/animals/mammals/ $ ls $ ls “CHange MODe” badger.txtbadger.txt porcupine.txtporcupine.txt $ ls -l $ ls -l Changes permissions for the : totaltotal 88 u = user -rw-r--r--.-rw-r--r--. 11 abensonabenson abensonabenson 19441944 MayMay 3131 18:0318:03 badger.txtbadger.txt g = group -rw-r--r--.-rw-r--r--. 11 abensonabenson abensonabenson 13471347 MayMay 3131 18:0518:05 porcupine.txtporcupine.txt = other $$ chmodchmod go+wgo+w badger.txtbadger.txt o $$ lsls -l-l totaltotal 88 +-= – add, remove, set -rw-rw-rw-.-rw-rw-rw-. 11 abensonabenson abensonabenson 19441944 MayMay 3131 18:0318:03 badger.txtbadger.txt -rw-r--r--.-rw-r--r--. 11 abensonabenson abensonabenson rwx13471347 – read,MayMay ,3131 18:0518:05 execute porcupine.txtporcupine.txt $$ cpcp badger.txtbadger.txt super_badger.txtsuper_badger.txt $$ lsls badger.txtbadger.txt porcupine.txtporcupine.txt super_badger.txtsuper_badger.txt $$ mvmv super_badger.txtsuper_badger.txt super_mellivorinae.txtsuper_mellivorinae.txt $$ lsls badger.txtbadger.txt porcupine.txtporcupine.txt super_mellivorinae.txtsuper_mellivorinae.txt

Files and directories

$$ cdcd ~/playground/animals/mammals/~/playground/animals/mammals/“” $$ lsls badger.txtbadger.txt porcupine.txtporcupine.txt Make a copy of a file – you give the $$ lsls -l-l name of the original file, followed totaltotal 88 by the new file. -rw-r--r--.-rw-r--r--. 11 abensonabenson abensonabenson 19441944 MayMay 3131 18:0318:03 badger.txtbadger.txt -rw-r--r--.-rw-r--r--. 11 abensonabenson abensonabenson 13471347 MayMay 3131 18:0518:05 porcupine.txtporcupine.txt $$ chmodchmod go+wgo+w badger.txtbadger.txt $$ lsls -l-l totaltotal 88 -rw-rw-rw-.-rw-rw-rw-. 11 abensonabenson abensonabenson 19441944 MayMay 3131 18:0318:03 badger.txtbadger.txt -rw-r--r--.-rw-r--r--. 11 abensonabenson abensonabenson 13471347 MayMay 3131 18:0518:05 porcupine.txtporcupine.txt $$ cpcp badger.txtbadger.txt super_badger.txtsuper_badger.txt $$ lsls badger.txtbadger.txt porcupine.txtporcupine.txt super_badger.txtsuper_badger.txt $$ mvmv super_badger.txtsuper_badger.txt super_mellivorinae.txtsuper_mellivorinae.txt $$ lsls badger.txtbadger.txt porcupine.txtporcupine.txt super_mellivorinae.txtsuper_mellivorinae.txt

Files and directories

$$ cdcd ~/playground/animals/mammals/~/playground/animals/mammals/ $$ lsls badger.txtbadger.txt porcupine.txtporcupine.txt $ ls -l $ ls -l “” totaltotal 88 -rw-r--r--. 1 abenson abenson 1944 May 31 18:03 badger.txt -rw-r--r--. 1 abenson abensonMove 1944 (rename) May 31 a file18:03 – you badger.txt give the -rw-r--r--.-rw-r--r--. 11 abensonabenson abensonabenson 13471347 MayMay 3131 18:0518:05 porcupine.txtporcupine.txt $ go+w badger.txt name of the original file, followed $ chmod go+w badger.txt by the new name. $$ lsls -l-l totaltotal 88 -rw-rw-rw-.-rw-rw-rw-. 11 abensonabenson abensonabenson 19441944 MayMay 3131 18:0318:03 badger.txtbadger.txt -rw-r--r--.-rw-r--r--. 11 abensonabenson abensonabenson 13471347 MayMay 3131 18:0518:05 porcupine.txtporcupine.txt $$ cpcp badger.txtbadger.txt super_badger.txtsuper_badger.txt $$ lsls badger.txtbadger.txt porcupine.txtporcupine.txt super_badger.txtsuper_badger.txt $$ mvmv super_badger.txtsuper_badger.txt super_mellivorinae.txtsuper_mellivorinae.txt $$ lsls badger.txtbadger.txt porcupine.txtporcupine.txt super_mellivorinae.txtsuper_mellivorinae.txt

Useful Commands

$$ echoecho "Hello?"Hello? CanCan youyou hearhear me?"me?" Hello?Hello? CanCan youyou hearhear me?me? $$ catcat badger.txtbadger.txt BadgersBadgers areare short-leggedshort-legged omnivores...omnivores... $$ catcat badger.txtbadger.txt porcupine.txtporcupine.txt BadgersBadgers areare short-leggedshort-legged omnivores...omnivores... PorcupinesPorcupines areare rodentsrodents withwith aa coatcoat ofof sharpsharp spines...spines... $$ moremore badger.txtbadger.txt BadgersBadgers areare short-leggedshort-legged omnivores...omnivores... $$ lessless badget.txtbadget.txt BadgersBadgers areare short-leggedshort-legged omnivores...omnivores... $$ manman lessless NAMENAME lessless -- oppositeopposite ofof moremore

SYNOPSISSYNOPSIS lessless -?-? lessless ----help

Useful Commands

$$ echoecho "Hello?"Hello? CanCan youyou hearhear me?"me?" Hello?Hello? CanCan youyou hearhear me?me? $$ catcat badger.txtbadger.txt BadgersBadgers areare short-leggedshort-legged omnivores...omnivores... $$ catcat badger.txtbadger.txt porcupine.txtporcupine.txt BadgersBadgers areare short-leggedshort-legged omnivores...omnivores... PorcupinesPorcupines areare rodentsrodents withwith aa coatcoat ofof sharpsharp spines...spines... $$ moremore badger.txtbadger.txt BadgersBadgers areare short-leggedshort-legged omnivores...omnivores... $$ lessless badget.txtbadget.txt BadgersBadgers areare short-leggedshort-legged omnivores…omnivores… $$ manman lessless “echo” NAMENAME lessless -- oppositeopposite ofof moremore Write the given text to screen (or somewhere else – of this SYNOPSISSYNOPSIS later). lessless -?-? lessless --help--help

Useful Commands

$$ echoecho "Hello?"Hello? CanCan youyou hearhear me?"me?" Hello?Hello? CanCan youyou hearhear me?me? $$ catcat badger.txtbadger.txt BadgersBadgers areare short-leggedshort-legged omnivores...omnivores... $$ catcat badger.txtbadger.txt porcupine.txtporcupine.txt BadgersBadgers areare short-leggedshort-legged omnivores...omnivores... PorcupinesPorcupines areare rodentsrodents withwith aa coatcoat ofof sharpsharp spines...spines... $$ moremore badger.txtbadger.txt BadgersBadgers areare short-leggedshort-legged omnivores...omnivores... $$ lessless badget.txtbadget.txt BadgersBadgers areare short-leggedshort-legged omnivores…omnivores… $$ manman lessless “conCATenate” NAMENAME lessless -- oppositeopposite ofof moremore Take the content of all files listed, them together, and write it out. SYNOPSISSYNOPSIS lessless -?-? lessless --help--help

Useful Commands

$$ echoecho "Hello?"Hello? CanCan youyou hearhear me?"me?" Hello?Hello? CanCan youyou hearhear me?me? $$ catcat badger.txtbadger.txt BadgersBadgers areare short-leggedshort-legged omnivores...omnivores... $$ catcat badger.txtbadger.txt porcupine.txtporcupine.txt BadgersBadgers areare short-leggedshort-legged omnivores...omnivores... PorcupinesPorcupines areare rodentsrodents withwith aa coatcoat ofof sharpsharp spines...spines... $$ moremore badger.txtbadger.txt BadgersBadgers areare short-leggedshort-legged omnivores...omnivores... $$ lessless badget.txtbadget.txt BadgersBadgers areare short-leggedshort-legged omnivores…omnivores… $$ manman lessless “conCATenate” NAMENAME lessless -- oppositeopposite ofof moremore Take the content of all files listed, join them together, and write it out. SYNOPSISSYNOPSIS lessless -?-? lessless --help--help

Useful Commands

$$ echoecho "Hello?"Hello? CanCan youyou hearhear me?"me?" Hello?Hello? CanCan youyou hearhear me?me? $$ catcat badger.txtbadger.txt BadgersBadgers areare short-leggedshort-legged omnivores...omnivores... $$ catcat badger.txtbadger.txt porcupine.txtporcupine.txt BadgersBadgers areare short-leggedshort-legged omnivores...omnivores... PorcupinesPorcupines areare rodentsrodents withwith aa coatcoat ofof sharpsharp spines...spines... $$ moremore badger.txtbadger.txt BadgersBadgers areare short-leggedshort-legged omnivores...omnivores... $$ lessless badget.txtbadget.txt BadgersBadgers areare short-leggedshort-legged omnivores…omnivores… $$ manman lessless “more” NAMENAME lessless -- oppositeopposite ofof moremore Display contents of a file to with pagination (use return or space SYNOPSISSYNOPSIS to step through). lessless -?-? lessless --help--help

Useful Commands

$$ echoecho "Hello?"Hello? CanCan youyou hearhear me?"me?" Hello?Hello? CanCan youyou hearhear me?me? $$ catcat badger.txtbadger.txt BadgersBadgers areare short-leggedshort-legged omnivores...omnivores... $$ catcat badger.txtbadger.txt porcupine.txtporcupine.txt BadgersBadgers areare short-leggedshort-legged omnivores...omnivores... PorcupinesPorcupines areare rodentsrodents withwith aa coatcoat ofof sharpsharp spines...spines... $$ moremore badger.txtbadger.txt BadgersBadgers areare short-leggedshort-legged omnivores...omnivores... $$ lessless badget.txtbadget.txt BadgersBadgers areare short-leggedshort-legged omnivores…omnivores… $$ manman lessless “” NAMENAME lessless -- oppositeopposite ofof moremore Fancy version of more. Scroll SYNOPSISSYNOPSIS forward and backward. Search (“/”), lessless -?-? etc. lessless --help--help

Useful Commands

$$ echoecho "Hello?"Hello? CanCan youyou hearhear me?"me?" Hello?Hello? CanCan youyou hearhear me?me? $$ catcat badger.txtbadger.txt “MANual” BadgersBadgers areare short-leggedshort-legged omnivores...omnivores... $$ catcat badger.txtbadger.txt porcupine.txtporcupine.txtShow documentation for a command. BadgersBadgers areare short-leggedshort-legged omnivores...omnivores... PorcupinesPorcupines areare rodentsrodents withwith aa coatcoat ofof sharpsharp spines...spines... $$ moremore badger.txtbadger.txt BadgersBadgers areare short-leggedshort-legged omnivores...omnivores... $$ lessless badget.txtbadget.txt BadgersBadgers areare short-leggedshort-legged omnivores…omnivores… $$ manman lessless NAMENAME lessless -- oppositeopposite ofof moremore

SYNOPSISSYNOPSIS lessless -?-? lessless --help--help

Useful Commands

$$ grepgrep skunkskunk badger.txtbadger.txt membersmembers ofof thethe skunkskunk family,family, placingplacing $$ grepgrep rodentrodent *.txt*.txt porcupine.txt:Porcupinesporcupine.txt:Porcupines areare rodentsrodents porcupine.txt:Porcupinesporcupine.txt:Porcupines areare thethe third-largestthird-largest ofof thethe rodents,rodents, $$ cdcd $$ findfind playgroundplayground -name-name "*.txt""*.txt" playground/animals/mammals/super_mellivorinae.txtplayground/animals/mammals/super_mellivorinae.txt playground/animals/mammals/badger.txtplayground/animals/mammals/badger.txt playground/animals/mammals/porcupine.txtplayground/animals/mammals/porcupine.txt playground/animals/reptiles/caiman.txtplayground/animals/reptiles/caiman.txt $$ findfind playgroundplayground -type-type playgroundplayground playground/documentsplayground/documents playground/animalsplayground/animals playground/animals/mammalsplayground/animals/mammals playground/animals/reptilesplayground/animals/reptiles playground/scienceplayground/science

Useful Commands

$$ grepgrep skunkskunk badger.txtbadger.txt membersmembers ofof thethe skunkskunk family,family, placingplacing $$ grepgrep rodentrodent *.txt*.txt porcupine.txt:Porcupinesporcupine.txt:Porcupines areare rodentsrodents porcupine.txt:Porcupinesporcupine.txt:Porcupines areare thethe third-largestthird-largest ofof thethe rodents,rodents, $$ cdcd $ find playground -name "*.txt" $ find playground -name "*.txt" “Get Regualr ExPression” playground/animals/mammals/super_mellivorinae.txtplayground/animals/mammals/super_mellivorinae.txt playground/animals/mammals/badger.txt playground/animals/mammals/badger.txtSearch for a word (or words) in a file. playground/animals/mammals/porcupine.txtplayground/animals/mammals/porcupine.txt playground/animals/reptiles/caiman.txtplayground/animals/reptiles/caiman.txt $$ findfind playgroundplayground -type-type dd playgroundplayground playground/documentsplayground/documents playground/animalsplayground/animals playground/animals/mammalsplayground/animals/mammals playground/animals/reptilesplayground/animals/reptiles playground/scienceplayground/science

Useful Commands

$$ grepgrep skunkskunk badger.txtbadger.txt membersmembers ofof thethe skunkskunk family,family, placingplacing $$ grepgrep rodentrodent *.txt*.txt porcupine.txt:Porcupinesporcupine.txt:Porcupines areare rodentsrodents porcupine.txt:Porcupinesporcupine.txt:Porcupines areare thethe third-largestthird-largest ofof thethe rodents,rodents, $$ cdcd $$ findfind playgroundplayground -name-name "*.txt""*.txt" playground/animals/mammals/super_mellivorinae.txtplayground/animals/mammals/super_mellivorinae.txt playground/animals/mammals/badger.txtplayground/animals/mammals/badger.txt playground/animals/mammals/porcupine.txtplayground/animals/mammals/porcupine.txt playground/animals/reptiles/caiman.txtplayground/animals/reptiles/caiman.txt $$ findfind playgroundplayground -type-type dd playgroundplayground Wildcards playground/documentsplayground/documents playground/animalsplayground/animals “*” matches any sequence of characters playground/animals/mammalsplayground/animals/mammals “?” matches any single character playground/animals/reptilesplayground/animals/reptiles playground/scienceplayground/science

Useful Commands

$$ grepgrep skunkskunk badger.txtbadger.txt membersmembers ofof thethe skunkskunk family,family, placingplacing $$ grepgrep rodentrodent *.txt*.txt porcupine.txt:Porcupinesporcupine.txt:Porcupines areare rodentsrodents porcupine.txt:Porcupinesporcupine.txt:Porcupines areare thethe third-largestthird-largest ofof thethe rodents,rodents, $$ cdcd $$ findfind playgroundplayground -name-name "*.txt""*.txt" playground/animals/mammals/super_mellivorinae.txtplayground/animals/mammals/super_mellivorinae.txt playground/animals/mammals/badger.txtplayground/animals/mammals/badger.txt playground/animals/mammals/porcupine.txtplayground/animals/mammals/porcupine.txt playground/animals/reptiles/caiman.txtplayground/animals/reptiles/caiman.txt $$ findfind playgroundplayground -type-type dd playgroundplayground “find” playground/documentsplayground/documents playground/animalsplayground/animals Search a path for files/directories that playground/animals/mammalsplayground/animals/mammals match some specification playground/animals/reptilesplayground/animals/reptiles playground/scienceplayground/science

Redirection

$$ rmrm super_mellivorinae.txtsuper_mellivorinae.txt $$ lsls badger.txtbadger.txt porcupine.txtporcupine.txt $$ cdcd playground/animals/mammals/playground/animals/mammals/ $$ catcat badger.txtbadger.txt >> another_badger.txtanother_badger.txt $$ lsls another_badger.txtanother_badger.txt badger.txtbadger.txt porcupine.txtporcupine.txt $$ catcat >> list_of_mammals.txtlist_of_mammals.txt batbat catcat ocelotocelot camelcamel ^D^D $$ catcat list_of_mammals.txtlist_of_mammals.txt batbat catcat ocelotocelot camelcamel

Useful Commands

$$ tartar cvfcvf playground.tarplayground.tar playgroundplayground playground/playground/ playground/documents/playground/documents/ playground/mystuff/playground/mystuff/ playground/animals/playground/animals/ playground/animals/mammals/playground/animals/mammals/ playground/animals/mammals/super_mellivorinae.txtplayground/animals/mammals/super_mellivorinae.txt playground/animals/mammals/badger.txtplayground/animals/mammals/badger.txt playground/animals/mammals/porcupine.txtplayground/animals/mammals/porcupine.txt playground/animals/reptiles/playground/animals/reptiles/ playground/animals/reptiles/caiman.txtplayground/animals/reptiles/caiman.txt playground/science/playground/science/ $$ lsls playgroundplayground playground.tarplayground.tar

Useful Commands

$$ tartar cvfcvf playground.tarplayground.tar playgroundplayground playground/playground/ playground/documents/playground/documents/ playground/mystuff/playground/mystuff/ playground/animals/playground/animals/ playground/animals/mammals/playground/animals/mammals/ playground/animals/mammals/super_mellivorinae.txtplayground/animals/mammals/super_mellivorinae.txt“Tape ARchive” playground/animals/mammals/badger.txtplayground/animals/mammals/badger.txt playground/animals/mammals/porcupine.txtplayground/animals/mammals/porcupine.txtCombine all files (and directories) into playground/animals/reptiles/playground/animals/reptiles/ one archive file. Useful for sharing playground/animals/reptiles/caiman.txtplayground/animals/reptiles/caiman.txtdata, archiving etc. playground/science/playground/science/ $$ lsls Use: playgroundplayground playground.tarplayground.tar tar xvf playground.tar

to re-extract.

Redirection

$$ rmrm super_mellivorinae.txtsuper_mellivorinae.txt $$ lsls badger.txtbadger.txt porcupine.txtporcupine.txt $$ cdcd playground/animals/mammals/playground/animals/mammals/ $$ catcat badger.txtbadger.txt >> another_badger.txtanother_badger.txt $$ lsls another_badger.txtanother_badger.txt badger.txtbadger.txt“ R eporcupine.txtMporcupine.txtove” $$ catcat >> list_of_mammals.txtlist_of_mammals.txt batbat Delete a file. THERE IS NO UNDO!!! catcat ocelotocelot Add -r option to recursively remove all camelcamel files in a directory. ^D^D $$ catcat list_of_mammals.txtlist_of_mammals.txt THERE IS NO UNDO!!!!!!!!!!!!! batbat catcat ocelotocelot camelcamel

Redirection

$$ rmrm super_mellivorinae.txtsuper_mellivorinae.txt $$ lsls badger.txtbadger.txt porcupine.txtporcupine.txt $$ cdcd playground/animals/mammals/playground/animals/mammals/ $$ catcat badger.txtbadger.txt >> another_badger.txtanother_badger.txt $$ lsls another_badger.txtanother_badger.txt badger.txtbadger.txt porcupine.txtporcupine.txt $$ catcat >> list_of_mammals.txtlist_of_mammals.txt batbat catcat Redirection ocelotocelot camelcamel “>” sends output to named file instead ^D^D of to the terminal. So, this was a way $$ catcat list_of_mammals.txtlist_of_mammals.txt to make a copy of our file. batbat catcat ocelotocelot camelcamel

Redirection

$$ rmrm super_mellivorinae.txtsuper_mellivorinae.txt $$ lsls badger.txtbadger.txt porcupine.txtporcupine.txt $$ cdcd playground/animals/mammals/playground/animals/mammals/ $$ catcat badger.txtbadger.txt >> another_badger.txtanother_badger.txt $$ lsls another_badger.txtanother_badger.txt badger.txtbadger.txt porcupine.txtporcupine.txt $$ catcat >> list_of_mammals.txtlist_of_mammals.txt batbat catcat ocelotocelot camelcamel ^D^D Redirection $$ catcat list_of_mammals.txtlist_of_mammals.txt batbat No input file given….. Terminal waits for catcat you to type input. Whatever you type ocelotocelot goes into the file. camelcamel

Redirection

$$ echoecho "More"More badgerbadger stuffstuff herehere later."later." >>>> another_badger.txtanother_badger.txt $$ catcat badger.txtbadger.txt ...... MoreMore badgerbadger stuffstuff toto gogo herehere later.later. $$ diffdiff badger.txtbadger.txt another_badger.txtanother_badger.txt 7a87a8 >> MoreMore badgerbadger stuffstuff toto gogo herehere later.later.

Redirection

$$ echoecho "More"More badgerbadger stuffstuff herehere later."later." >>>> another_badger.txtanother_badger.txt $$ catcat badger.txtbadger.txt ...... MoreMore badgerbadger stuffstuff toto gogo herehere later.later. $$ diffdiff badger.txtbadger.txt another_badger.txtanother_badger.txt 7a87a8 >> MoreMore badgerbadger stuffstuff toto gogo herehere later.later. Like “>”, but appends instead of over-writing.

Redirection

$$ echoecho "More"More badgerbadger stuffstuff herehere later."later." >>>> another_badger.txtanother_badger.txt $$ catcat badger.txtbadger.txt ...... MoreMore badgerbadger stuffstuff toto gogo herehere later.later. $$ diffdiff badger.txtbadger.txt another_badger.txtanother_badger.txt 7a87a8 >> MoreMore badgerbadger stuffstuff toto gogo herehere later.later.

“DIFFerence”

Show differences between two files.

Redirection and Pipes (and Sorting)

$$ sortsort list_of_mammals.txtlist_of_mammals.txt batbat camelcamel catcat ocelotocelot $$ sortsort << list_of_mammals.txtlist_of_mammals.txt batbat camelcamel catcat ocelotocelot $$ catcat list_of_mammals.txtlist_of_mammals.txt || sortsort batbat camelcamel catcat ocelotocelot

Redirection and Pipes (and Sorting)

$$ sortsort list_of_mammals.txtlist_of_mammals.txt batbat camelcamel catcat ocelotocelot $ < list_of_mammals.txt $ sort < list_of_mammals.txt “Sort” batbat camel camel Sort input into alphanumerical order. catcat ocelotocelot $$ catcat list_of_mammals.txtlist_of_mammals.txt || sortsort batbat camelcamel catcat ocelotocelot

Redirection and Pipes (and Sorting)

$$ sortsort list_of_mammals.txtlist_of_mammals.txt batbat camelcamel catcat ocelotocelot $$ sortsort << list_of_mammals.txtlist_of_mammals.txt batbat camelcamel catcat ocelotocelot $$ catcat list_of_mammals.txtlist_of_mammals.txt || sortsort batbat camelcamel Redirect input catcat ocelotocelot Redirects input from a file into a command.

Redirection and Pipes (and Sorting)

$$ sortsort list_of_mammals.txtlist_of_mammals.txt batbat camelcamel catcat ocelotocelot $$ sortsort << list_of_mammals.txtlist_of_mammals.txt batbat camelcamel catcat ocelotocelot $$ catcat list_of_mammals.txtlist_of_mammals.txt || sortsort batbat camelcamel cat cat Pipe ocelotocelot “|” takes output from first command and sends it as input to second.

Variables

$$ echoecho $SHELL$SHELL /bin/bash/bin/bash $$ echoecho $USER$USER abensonabenson $$ echoecho $HOME$HOME /home/abenson/home/abenson $$ workPath=$HOME/playgroundworkPath=$HOME/playground $$ cdcd $workPath$workPath $$ pwdpwd /home/abenson/playground/home/abenson/playground

Variables

$$ echoecho $SHELL$SHELL /bin/bash/bin/bash $$ echoecho $USER$USER abensonabenson Environment Variables $$ echoecho $HOME$HOME /home/abenson/home/abenson “$” means following with the $$ workPath=$HOME/playgroundworkPath=$HOME/playgroundvalue of the named variable. $$ cdcd $workPath$workPath $$ pwdpwd The shell sets up many environment /home/abenson/playground/home/abenson/playgroundvariables, such as those shown.

Variables

$$ echoecho $SHELL$SHELL /bin/bash/bin/bash $$ echoecho $USER$USER abensonabenson $$ echoecho $HOME$HOME /home/abenson/home/abenson $$ workPath=$HOME/playgroundworkPath=$HOME/playground $$ cdcd $workPath$workPath $$ pwdpwd /home/abenson/playground /home/abenson/playground User Variables

Define your own variables and then use them in the command line.

Background Processes

$$ sleepsleep 3030 $$ ^C^C $$ sleepsleep 3030 $$ ^Z^Z $$ jobsjobs $$ fgfg $$ ^Z^Z $$ bgbg $$ jobsjobs

Background Processes

$$ sleepsleep 3030 $$ ^C^C $$ sleepsleep 3030 Do Nothing….. $$ ^Z^Z $$ jobsjobs just waits for the given number $$ fgfg of seconds. $$ ^Z^Z $$ bgbg $$ jobsjobs

Background Processes

$$ sleepsleep 3030 $$ ^C^C $$ sleepsleep 3030 $$ ^Z^Z Cancel [1]+[1]+ StoppedStopped sleepsleep 3030 $$ jobsjobs ^C cancels the running command [1]+[1]+ StoppedStopped sleepsleep 3030 $$ fgfg $$ sleepsleep 3030 $$ ^Z^Z [1]+[1]+ StoppedStopped sleepsleep 3030 $$ bgbg [1]+[1]+ sleepsleep 3030 && $$ jobsjobs [1]+[1]+ RunningRunning sleepsleep 3030 && $$ sleepsleep 3030 && [2][2] 2119421194

Background Processes

$$ sleepsleep 3030 $$ ^C^C $$ sleepsleep 3030 $$ ^Z^Z [1]+[1]+ StoppedStopped sleepsleep 3030 Suspend $$ jobsjobs [1]+[1]+ StoppedStopped sleepsleep 3030 suspends the running command $$ fgfg ^Z $$ sleepsleep 3030 $$ ^Z^Z [1]+[1]+ StoppedStopped sleepsleep 3030 $$ bgbg [1]+[1]+ sleepsleep 3030 && $$ jobsjobs [1]+[1]+ RunningRunning sleepsleep 3030 && $$ sleepsleep 3030 && [2][2] 2119421194

Background Processes

$$ sleepsleep 3030 $$ ^C^C $$ sleepsleep 3030 $$ ^Z^Z [1]+[1]+ StoppedStopped sleepsleep 3030 $$ jobsjobs [1]+[1]+ StoppedStopped sleepsleep 3030 $$ fgfg Jobs $$ sleepsleep 3030 $$ ^Z^Z Shows a list of jobs running or [1]+[1]+ StoppedStopped suspended sleepsleep 3030 $$ bgbg [1]+[1]+ sleepsleep 3030 && $$ jobsjobs [1]+[1]+ RunningRunning sleepsleep 3030 && $$ sleepsleep 3030 && [2][2] 2119421194

Background Processes

$$ sleepsleep 3030 $$ ^C^C $$ sleepsleep 3030 $$ ^Z^Z [1]+[1]+ StoppedStopped sleepsleep 3030 $$ jobsjobs [1]+[1]+ StoppedStopped sleepsleep 3030 $$ fgfg $$ sleepsleep 3030 $$ ^Z^Z “ForeGround” [1]+[1]+ StoppedStopped sleepsleep 3030 $$ bgbg Bring the last suspended job back into [1]+[1]+ sleepsleep 3030 && the foregound (i.e. running again). $$ jobsjobs [1]+[1]+ RunningRunning sleepsleep 3030 && $$ sleepsleep 3030 && [2][2] 2119421194

Background Processes

$$ sleepsleep 3030 $$ ^C^C $$ sleepsleep 3030 $$ ^Z^Z [1]+[1]+ StoppedStopped sleepsleep 3030 $$ jobsjobs [1]+[1]+ StoppedStopped sleepsleep 3030 $$ fgfg $$ sleepsleep 3030 $$ ^Z^Z [1]+[1]+ StoppedStopped sleepsleep 3030 $$ bgbg [1]+[1]+ sleepsleep 3030 && $$ jobsjobs “BackGround” [1]+[1]+ RunningRunning sleepsleep 3030 && $$ sleepsleep 3030 && Run the last suspended job in the [2][2] 2119421194 background.

Background Processes

$$ sleepsleep 3030 $$ ^C^C $$ sleepsleep 3030 $$ ^Z^Z [1]+[1]+ StoppedStopped sleepsleep 3030 $$ jobsjobs [1]+[1]+ StoppedStopped sleepsleep 3030 $$ fgfg $$ sleepsleep 3030 $$ ^Z^Z [1]+[1]+ StoppedStopped sleepsleep 3030 $$ bgbg [1]+[1]+ sleepsleep 3030 && $$ jobsjobs “&” [1]+[1]+ RunningRunning sleepsleep 3030 && $$ sleepsleep 3030 && Start the command in the background. [2][2] 2119421194

Network and Remote Connections

$$ hostnamehostname dhcp225.obs.carnegiescience.edudhcp225.obs.carnegiescience.edu $$ sshssh [email protected]@mies.stanford.edu LastLast login:login: ThuThu JunJun 22 14:03:0114:03:01 20162016 fromfrom ociw.eduociw.edu testuser@miestestuser@mies ~]~] hostnamehostname obs-ssh.ad.ciw.eduobs-ssh.ad.ciw.edu testuser@miestestuser@mies ~]~] exitexit ConnectionConnection toto mies.stanford.edumies.stanford.edu closed.closed. $$ cdcd animals/mammalsanimals/mammals $$ scpscp badger.txtbadger.txt [email protected]:[email protected]:myname.txt badger.txtbadger.txt 100%100% 19441944 1.9KB/s1.9KB/s 00:0000:00 $$ sshssh [email protected]@mies.stanford.edu LastLast login:login: ThuThu JunJun 22 14:03:0114:03:01 20162016 fromfrom ociw.eduociw.edu testuser@miestestuser@mies ~]~] lsls badger.txtbadger.txt testuser@miestestuser@mies ~]~] rmrm myname.txtmyname.txt testuser@miestestuser@mies ~]~] exitexit ConnectionConnection toto mies.stanford.edumies.stanford.edu closed.closed.

Network and Remote Connections

$$ hostnamehostname dhcp225.obs.carnegiescience.edudhcp225.obs.carnegiescience.edu $$ sshssh [email protected]@mies.stanford.edu LastLast login:login: ThuThu JunJun 22 14:03:0114:03:01 20162016 fromfrom ociw.eduociw.edu testuser@miestestuser@mies ~]~] hostnamehostname obs-ssh.ad.ciw.eduobs-ssh.ad.ciw.edu testuser@miestestuser@mies ~]~] exitexit “Secure SHell” ConnectionConnection toto ssh.obs.carnegiescience.edussh.obs.carnegiescience.edu closed.closed. $$ cdcd animals/mammalsanimals/mammals Open a shell on a remote server. $$ scpscp badger.txtbadger.txt [email protected]:[email protected]: badger.txtbadger.txt 100%100% 19441944 Password1.9KB/s1.9KB/s is: HvtTc6Bw00:0000:00 $$ sshssh [email protected]@mies.stanford.edu LastLast login:login: ThuThu JunJun 22 14:03:0114:03:01 20162016 fromfrom ociw.eduociw.edu testuser@miestestuser@mies ~]~] lsls badger.txtbadger.txt testuser@miestestuser@mies ~]~] rmrm badger.txtbadger.txt testuser@miestestuser@mies ~]~] exitexit ConnectionConnection toto ssh.obs.carnegiescience.edussh.obs.carnegiescience.edu closed.closed.

Network and Remote Connections

$$ hostnamehostname dhcp225.obs.carnegiescience.edudhcp225.obs.carnegiescience.edu $$ sshssh [email protected]@mies.stanford.edu LastLast login:login: ThuThu JunJun 22 14:03:0114:03:01 20162016 fromfrom ociw.eduociw.edu testuser@miestestuser@mies ~]~] hostnamehostname obs-ssh.ad.ciw.eduobs-ssh.ad.ciw.edu testuser@miestestuser@mies ~]~] exitexit ConnectionConnection toto ssh.obs.carnegiescience.edussh.obs.carnegiescience.edu closed.closed. $$ cdcd animals/mammalsanimals/mammals $$ scpscp badger.txtbadger.txt [email protected]:[email protected]: badger.txtbadger.txt 100%100% 19441944 1.9KB/s1.9KB/s 00:0000:00 $$ sshssh [email protected]@mies.stanford.edu LastLast login:login: ThuThu JunJun 22 14:03:0114:03:01 20162016 fromfrom ociw.eduociw.edu testuser@miestestuser@mies ~]~] lsls “Secure CoPy” badger.txtbadger.txt testuser@miestestuser@mies ~]~] rmrm badger.txtbadger.txtCopy a file to a remote server. Or from testuser@miestestuser@mies ~]~] exitexit remote server to your laptop. ConnectionConnection toto ssh.obs.carnegiescience.edussh.obs.carnegiescience.edu closed.closed.

Network and Remote Connections

$$ wgetwget http://bit.ly/1TXIZSJhttp://bit.ly/1TXIZSJ -O-O playground1.tarplayground1.tar

wget

Download a file from a URL. Useful for downloading big datasets on a remote server.

Scripts

#!/bin/sh#!/bin/sh

echoecho ThisThis isis aa ….script…. echoecho HelloHello useruser $USER$USER echoecho HereHere areare allall thethe filesfiles II cancan find…find… findfind .. -type-type ff exitexit

Scripts

$$ cdcd ~/playground~/playground $$ ./script.sh./script.sh ThisThis isis aa script...script... HelloHello useruser abensonabenson HereHere areare allall thethe filesfiles II cancan find…find… ./script.sh./script.sh ./animals/mammals/badger.txt./animals/mammals/badger.txt ./animals/mammals/porcupine.txt./animals/mammals/porcupine.txt ./animals/reptiles/caiman.txt./animals/reptiles/caiman.txt

Scripts: .bashrc

● The script in ~/.bashrc gets run every you log in ● Use it to configure the environment the way you want it to be ● For example, you could add an :

$$ aliasalias up='cdup=' ..'..' $$ cdcd ~/playground/animals~/playground/animals $$ pwdpwd /home/abenson/playground/animals/home/abenson/playground/animals $$ upup $$ pwdpwd /home/abenson/playground/home/abenson/playground

Bonus: Text Editing with

● There are many text editors in Unix ● Use whichever you prefer ● One option available everywhere is EMACS

$$ emacsemacs playground/animals/reptiles/caiman.txtplayground/animals/reptiles/caiman.txt && [1][1] 2957529575

Bonus: Text Editing with EMACS

Open file ^X^F ^W

Save file ^X^S ^Y

Close file ^X^K Search forward ^S

Search backward ^R EMACS ^X^C