Introduction to UNIX Command Line Files and directories Some useful commands (echo, cat, grep, find, diff, tar) Redirection Pipes Variables Background processes Remote connections (e.g. ssh, curl) Scripts
The Command Line What is it? An interface to UNIX You type commands, things happen Also referred to as a shell We'll use the bash 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.c analyze.py report.tex
Files and Directories Get a pre-made set of directories and files to work with We'll talk about what these commands do later The $ is the command prompt (yours might differ). Type what's listed after it, then press enter. $ curl curl -L -L -o -o playground.tar 'http://bit.ly/2swz1ef' $ tar tar xvf xvf playground.tar
Files and directories $ pwd pwd /home/abenson $ cd cd playground $ pwd pwd /home/abenson/playground animals documents science $ mkdir mystuff animals documents mystuff science $ cd cd animals/mammals badger.txt porcupine.txt -l -l total 8 -rw-r--r--. 1 abenson abenson 1944 1944 May May 31 31 18:03 badger.txt -rw-r--r--. 1 abenson abenson 1347 1347 May May 31 31 18:05 porcupine.txt
Files and directories Present Working Directory $ pwd pwd Shows the full path of your current /home/abenson location in the filesystem. $ cd cd playground $ pwd pwd /home/abenson/playground animals documents science $ mkdir mystuff animals documents mystuff science $ cd cd animals/mammals badger.txt porcupine.txt -l -l total 8 -rw-r--r--. 1 abenson abenson 1944 1944 May May 31 31 18:03 badger.txt -rw-r--r--. 1 abenson abenson 1347 1347 May May 31 31 18:05 porcupine.txt
Files and directories $ pwd pwd Change Directory /home/abenson $ cd cd playground Change to a new directory relative to $ pwd pwd current location unless you give a full /home/abenson/playground path animals documents science $ mkdir mystuff animals documents mystuff science $ cd cd animals/mammals badger.txt porcupine.txt -l -l total 8 -rw-r--r--. 1 abenson abenson 1944 1944 May May 31 31 18:03 badger.txt -rw-r--r--. 1 abenson abenson 1347 1347 May May 31 31 18:05 porcupine.txt
Files and directories $ pwd pwd /home/abenson $ cd cd playground $ pwd pwd LiSt /home/abenson/playground List the content of the current directory. animals documents science Shows both directories and files. $ mkdir mystuff animals documents mystuff science $ cd cd animals/mammals badger.txt porcupine.txt -l -l total 8 -rw-r--r--. 1 abenson abenson 1944 1944 May May 31 31 18:03 badger.txt -rw-r--r--. 1 abenson abenson 1347 1347 May May 31 31 18:05 porcupine.txt
Files and directories $ pwd pwd /home/abenson $ cd cd playground $ pwd pwd /home/abenson/playground MaKe DIRectory animals documents science $ mkdir mystuff Make a new directory in the current $ ls directory ls animals documents mystuff science $ cd cd animals/mammals badger.txt porcupine.txt -l -l total 8 -rw-r--r--. 1 abenson abenson 1944 1944 May May 31 31 18:03 badger.txt -rw-r--r--. 1 abenson abenson 1347 1347 May May 31 31 18:05 porcupine.txt
Files and directories $ pwd pwd /home/abenson $ cd cd playground $ pwd pwd /home/abenson/playground MaKe DIRectory animals documents science $ mkdir mystuff Make a new directory in the current $ ls directory ls animals documents mystuff science $ cd cd animals/mammals badger.txt porcupine.txt -l -l total 8 -rw-r--r--. 1 abenson abenson 1944 1944 May May 31 31 18:03 badger.txt -rw-r--r--. 1 abenson abenson 1347 1347 May May 31 31 18:05 porcupine.txt
Files and directories $ pwd pwd /home/abenson $ cd cd playground $ pwd pwd /home/abenson/playground animals documents science $ mkdir mystuff animals documents mystuff science $ cd cd animals/mammals Options -l to ls requests a long badger.txt porcupine.txt listing. -l -l total 8 -rw-r--r--. 1 abenson abenson 1944 1944 May May 31 31 18:03 badger.txt -rw-r--r--. 1 abenson abenson 1347 1347 May May 31 31 18:05 porcupine.txt
Files and directories $ pwd pwd /home/abenson $ cd cd playground $ pwd pwd /home/abenson/playground animals documents science $ mkdir mystuff animals documents mystuff science $ cd cd animals/mammals Options -l to ls requests a long badger.txt porcupine.txt listing. -l -l total 8 -rw-r--r--. 1 abenson abenson 1944 1944 May May 31 31 18:03 badger.txt -rw-r--r--. 1 abenson abenson 1347 1347 May May 31 31 18:05 porcupine.txt
Files and directories $ pwd pwd /home/abenson $ cd cd playground $ pwd pwd /home/abenson/playground animals documents science $ mkdir mystuff animals documents mystuff science $ cd cd animals/mammals badger.txt porcupine.txt -l -l total 8 -rw-r--r--. 1 abenson abenson 1944 1944 May May 31 31 18:03 badger.txt -rw-r--r--. 1 abenson abenson 1347 1347 May May 31 31 18:05 porcupine.txt Permissions User Group Size in bytes Creation time File name
Files and directories -a -a..... badger.txt porcupine.txt $ cd cd. $ pwd pwd /home/abenson/playground/animals/mammals $ cd cd.... $ pwd pwd /home/abenson/playground/animals $ cd cd $ pwd pwd /home/abenson $ cd cd ~ $ pwd pwd /home/abenson
Files and directories $ cd cd ~/playground/animals/mammals/ badger.txt porcupine.txt -l -l total 8 -rw-r--r--. 1 abenson abenson 1944 1944 May May 31 31 18:03 badger.txt -rw-r--r--. 1 abenson abenson 1347 1347 May May 31 31 18:05 porcupine.txt $ chmod go+w go+w badger.txt -l -l total 8 -rw-rw-rw-. 1 abenson abenson 1944 1944 May May 31 31 18:03 badger.txt -rw-r--r--. 1 abenson abenson 1347 1347 May May 31 31 18:05 porcupine.txt $ cp cp badger.txt super_badger.txt badger.txt porcupine.txt super_badger.txt $ mv mv super_badger.txt super_mellivorinae.txt badger.txt porcupine.txt super_mellivorinae.txt
Files and directories $ cd cd ~/playground/animals/mammals/ badger.txt porcupine.txt CHange MODe -l -l total 8 Changes permissions for the file: -rw-r--r--. 1 abenson abenson u 1944 = user 1944 May May 31 31 18:03 badger.txt -rw-r--r--. 1 abenson abenson g 1347 = group 1347 May May 31 31 18:05 porcupine.txt $ chmod go+w go+w badger.txt o = other -l -l total 8 +-= add, remove, set -rw-rw-rw-. 1 abenson abenson 1944 1944 May May 31 31 18:03 badger.txt -rw-r--r--. 1 abenson abenson rwx 1347 1347 read, May May write, 31 31 18:05 execute porcupine.txt $ cp cp badger.txt super_badger.txt badger.txt porcupine.txt super_badger.txt $ mv mv super_badger.txt super_mellivorinae.txt badger.txt porcupine.txt super_mellivorinae.txt
Files and directories $ cd cd ~/playground/animals/mammals/ CoPy badger.txt porcupine.txt Make a copy of a file you give the -l -l name of the original file, followed total 8 by the new file. -rw-r--r--. 1 abenson abenson 1944 1944 May May 31 31 18:03 badger.txt -rw-r--r--. 1 abenson abenson 1347 1347 May May 31 31 18:05 porcupine.txt $ chmod go+w go+w badger.txt -l -l total 8 -rw-rw-rw-. 1 abenson abenson 1944 1944 May May 31 31 18:03 badger.txt -rw-r--r--. 1 abenson abenson 1347 1347 May May 31 31 18:05 porcupine.txt $ cp cp badger.txt super_badger.txt badger.txt porcupine.txt super_badger.txt $ mv mv super_badger.txt super_mellivorinae.txt badger.txt porcupine.txt super_mellivorinae.txt
Files and directories $ cd cd ~/playground/animals/mammals/ badger.txt porcupine.txt -l -l total 8 MoVe -rw-r--r--. 1 abenson abenson 1944 1944 May May 31 31 18:03 badger.txt -rw-r--r--. 1 abenson abenson Move 1347 (rename) 1347 May May 31 a 31 18:05 file you porcupine.txt give the $ chmod go+w go+w badger.txt name of the original file, followed -l by the new name. -l total 8 -rw-rw-rw-. 1 abenson abenson 1944 1944 May May 31 31 18:03 badger.txt -rw-r--r--. 1 abenson abenson 1347 1347 May May 31 31 18:05 porcupine.txt $ cp cp badger.txt super_badger.txt badger.txt porcupine.txt super_badger.txt $ mv mv super_badger.txt super_mellivorinae.txt badger.txt porcupine.txt super_mellivorinae.txt
Useful Commands $ echo echo "Hello? Can Can you you hear hear me?" me?" Hello? Can Can you you hear hear me? me? $ cat cat badger.txt Badgers are are short-legged omnivores... $ cat cat badger.txt porcupine.txt Badgers are are short-legged omnivores... Porcupines are are rodents with with a coat coat of of sharp spines... $ more more badger.txt Badgers are are short-legged omnivores... $ less less badget.txt Badgers are are short-legged omnivores... $ man man less less NAME NAME less less - opposite of of more more SYNOPSIS less less -? -? less less --help
Useful Commands $ echo echo "Hello? Can Can you you hear hear me?" me?" Hello? Can Can you you hear hear me? me? $ cat cat badger.txt Badgers are are short-legged omnivores... $ cat cat badger.txt porcupine.txt Badgers are are short-legged omnivores... Porcupines are are rodents with with a coat coat of of sharp spines... $ more more badger.txt Badgers are are short-legged omnivores... $ less less badget.txt Badgers are are short-legged omnivores $ man man less less NAME NAME echo less less - opposite of of more more Write the given text to screen (or SYNOPSIS somewhere else more of this less less -? -? later). less less --help
Useful Commands $ echo echo "Hello? Can Can you you hear hear me?" me?" Hello? Can Can you you hear hear me? me? $ cat cat badger.txt Badgers are are short-legged omnivores... $ cat cat badger.txt porcupine.txt Badgers are are short-legged omnivores... Porcupines are are rodents with with a coat coat of of sharp spines... $ more more badger.txt Badgers are are short-legged omnivores... $ less less badget.txt Badgers are are short-legged omnivores $ man man less less NAME NAME concatenate less less - opposite of of more more Take the content of all files listed, SYNOPSIS join them together, and write it out. less less -? -? less less --help
Useful Commands $ echo echo "Hello? Can Can you you hear hear me?" me?" Hello? Can Can you you hear hear me? me? $ cat cat badger.txt Badgers are are short-legged omnivores... $ cat cat badger.txt porcupine.txt Badgers are are short-legged omnivores... Porcupines are are rodents with with a coat coat of of sharp spines... $ more more badger.txt Badgers are are short-legged omnivores... $ less less badget.txt Badgers are are short-legged omnivores $ man man less less NAME NAME concatenate less less - opposite of of more more Take the content of all files listed, SYNOPSIS join them together, and write it out. less less -? -? less less --help
Useful Commands $ echo echo "Hello? Can Can you you hear hear me?" me?" Hello? Can Can you you hear hear me? me? $ cat cat badger.txt Badgers are are short-legged omnivores... $ cat cat badger.txt porcupine.txt Badgers are are short-legged omnivores... Porcupines are are rodents with with a coat coat of of sharp spines... $ more more badger.txt Badgers are are short-legged omnivores... $ less less badget.txt Badgers are are short-legged omnivores $ man man less less NAME NAME more less less - opposite of of more more Display contents of a file to terminal SYNOPSIS with pagination (use return or space less less -? -? to step through). less less --help
Useful Commands $ echo echo "Hello? Can Can you you hear hear me?" me?" Hello? Can Can you you hear hear me? me? $ cat cat badger.txt Badgers are are short-legged omnivores... $ cat cat badger.txt porcupine.txt Badgers are are short-legged omnivores... Porcupines are are rodents with with a coat coat of of sharp spines... $ more more badger.txt Badgers are are short-legged omnivores... $ less less badget.txt Badgers are are short-legged omnivores $ man man less less NAME NAME less less less - opposite of of more more Fancy version of more. Scroll SYNOPSIS forward and backward. Search ( / ), less less -? -? etc. less less --help
Useful Commands $ echo echo "Hello? Can Can you you hear hear me?" me?" Hello? Can Can you you hear hear me? me? $ cat cat badger.txt MANual Badgers are are short-legged omnivores... $ cat cat badger.txt porcupine.txt Show documentation for a command. Badgers are are short-legged omnivores... Porcupines are are rodents with with a coat coat of of sharp spines... $ more more badger.txt Badgers are are short-legged omnivores... $ less less badget.txt Badgers are are short-legged omnivores $ man man less less NAME NAME less less - opposite of of more more SYNOPSIS less less -? -? less less --help
Useful Commands $ grep grep skunk badger.txt members of of the the skunk family, placing $ grep grep rodent *.txt porcupine.txt:porcupines are are rodents porcupine.txt:porcupines are are the the third-largest of of the the rodents, $ cd cd $ find find playground -name "*.txt" playground/animals/mammals/super_mellivorinae.txt playground/animals/mammals/badger.txt playground/animals/mammals/porcupine.txt playground/animals/reptiles/caiman.txt $ find find playground -type d playground playground/documents playground/animals playground/animals/mammals playground/animals/reptiles playground/science
Useful Commands $ grep grep skunk badger.txt members of of the the skunk family, placing $ grep grep rodent *.txt porcupine.txt:porcupines are are rodents porcupine.txt:porcupines are are the the third-largest of of the the rodents, $ cd cd $ find find playground -name "*.txt" playground/animals/mammals/super_mellivorinae.txt Get Regualr ExPression playground/animals/mammals/badger.txt playground/animals/mammals/porcupine.txt Search for a word (or words) in a file. playground/animals/reptiles/caiman.txt $ find find playground -type d playground playground/documents playground/animals playground/animals/mammals playground/animals/reptiles playground/science
Useful Commands $ grep grep skunk badger.txt members of of the the skunk family, placing $ grep grep rodent *.txt porcupine.txt:porcupines are are rodents porcupine.txt:porcupines are are the the third-largest of of the the rodents, $ cd cd $ find find playground -name "*.txt" playground/animals/mammals/super_mellivorinae.txt playground/animals/mammals/badger.txt playground/animals/mammals/porcupine.txt playground/animals/reptiles/caiman.txt $ find find playground -type d playground Wildcards playground/documents playground/animals * matches any sequence of characters playground/animals/mammals? matches any single character playground/animals/reptiles playground/science
Useful Commands $ grep grep skunk badger.txt members of of the the skunk family, placing $ grep grep rodent *.txt porcupine.txt:porcupines are are rodents porcupine.txt:porcupines are are the the third-largest of of the the rodents, $ cd cd $ find find playground -name "*.txt" playground/animals/mammals/super_mellivorinae.txt playground/animals/mammals/badger.txt playground/animals/mammals/porcupine.txt playground/animals/reptiles/caiman.txt $ find find playground -type d playground find playground/documents playground/animals Search a path for files/directories that playground/animals/mammals match some specification playground/animals/reptiles playground/science
Redirection $ rm rm super_mellivorinae.txt badger.txt porcupine.txt $ cd cd playground/animals/mammals/ $ cat cat badger.txt > another_badger.txt another_badger.txt badger.txt porcupine.txt $ cat cat > list_of_mammals.txt bat bat cat cat ocelot camel ^D ^D $ cat cat list_of_mammals.txt bat bat cat cat ocelot camel
Useful Commands $ tar tar cvf cvf playground.tar playground playground/ playground/documents/ playground/mystuff/ playground/animals/ playground/animals/mammals/ playground/animals/mammals/super_mellivorinae.txt playground/animals/mammals/badger.txt playground/animals/mammals/porcupine.txt playground/animals/reptiles/ playground/animals/reptiles/caiman.txt playground/science/ playground playground.tar
Useful Commands $ tar tar cvf cvf playground.tar playground playground/ playground/documents/ playground/mystuff/ playground/animals/ playground/animals/mammals/ playground/animals/mammals/super_mellivorinae.txt Tape ARchive playground/animals/mammals/badger.txt playground/animals/mammals/porcupine.txt Combine all files (and directories) into playground/animals/reptiles/ one archive file. Useful for sharing playground/animals/reptiles/caiman.txt data, archiving etc. playground/science/ Use: playground playground.tar tar xvf playground.tar to re-extract.
Redirection $ rm rm super_mellivorinae.txt badger.txt porcupine.txt $ cd cd playground/animals/mammals/ $ cat cat badger.txt > another_badger.txt another_badger.txt badger.txt ReMove porcupine.txt $ cat cat > list_of_mammals.txt bat bat Delete a file. THERE IS NO UNDO!!! cat cat ocelot Add -r option to recursively remove all camel files in a directory. ^D ^D $ cat cat list_of_mammals.txt THERE IS NO UNDO!!!!!!!!!!!!! bat bat cat cat ocelot camel
Redirection $ rm rm super_mellivorinae.txt badger.txt porcupine.txt $ cd cd playground/animals/mammals/ $ cat cat badger.txt > another_badger.txt another_badger.txt badger.txt porcupine.txt $ cat cat > list_of_mammals.txt bat bat cat cat Redirection ocelot camel > sends output to named file instead ^D ^D of to the terminal. So, this was a way $ cat cat list_of_mammals.txt to make a copy of our file. bat bat cat cat ocelot camel
Redirection $ rm rm super_mellivorinae.txt badger.txt porcupine.txt $ cd cd playground/animals/mammals/ $ cat cat badger.txt > another_badger.txt another_badger.txt badger.txt porcupine.txt $ cat cat > list_of_mammals.txt bat bat cat cat ocelot camel ^D ^D Redirection $ cat cat list_of_mammals.txt bat bat No input file given.. Terminal waits for cat cat you to type input. Whatever you type ocelot goes into the file. camel
Redirection $ echo echo "More badger stuff here here later." >> >> another_badger.txt $ cat cat badger.txt... More More badger stuff to to go go here here later. $ diff diff badger.txt another_badger.txt 7a8 7a8 > More More badger stuff to to go go here here later.
Redirection $ echo echo "More badger stuff here here later." >> >> another_badger.txt $ cat cat badger.txt... More More badger stuff to to go go here here later. $ diff diff badger.txt another_badger.txt 7a8 7a8 Append > More More badger stuff to to go go here here later. Like >, but appends instead of over-writing.
Redirection $ echo echo "More badger stuff here here later." >> >> another_badger.txt $ cat cat badger.txt... More More badger stuff to to go go here here later. $ diff diff badger.txt another_badger.txt 7a8 7a8 > More More badger stuff to to go go here here later. DIFFerence Show differences between two files.
Redirection and Pipes (and Sorting) $ sort sort list_of_mammals.txt bat bat camel cat cat ocelot $ sort sort < list_of_mammals.txt bat bat camel cat cat ocelot $ cat cat list_of_mammals.txt sort sort bat bat camel cat cat ocelot
Redirection and Pipes (and Sorting) $ sort sort list_of_mammals.txt bat bat camel cat cat ocelot $ sort sort < list_of_mammals.txt bat Sort bat camel cat Sort input into alphanumerical order. cat ocelot $ cat cat list_of_mammals.txt sort sort bat bat camel cat cat ocelot
Redirection and Pipes (and Sorting) $ sort sort list_of_mammals.txt bat bat camel cat cat ocelot $ sort sort < list_of_mammals.txt bat bat camel cat cat ocelot $ cat cat list_of_mammals.txt sort sort bat bat camel Redirect input cat cat ocelot Redirects input from a file into a command.
Redirection and Pipes (and Sorting) $ sort sort list_of_mammals.txt bat bat camel cat cat ocelot $ sort sort < list_of_mammals.txt bat bat camel cat cat ocelot $ cat cat list_of_mammals.txt sort sort bat bat camel cat cat ocelot Pipe takes output from first command and sends it as input to second.
Variables $ echo echo $SHELL /bin/bash $ echo echo $USER abenson $ echo echo $HOME /home/abenson $ workpath=$home/playground $ cd cd $workpath $ pwd pwd /home/abenson/playground
Variables $ echo echo $SHELL /bin/bash $ echo echo $USER abenson Environment Variables $ echo echo $HOME /home/abenson $ means replace following with the $ workpath=$home/playground value of the named variable. $ cd cd $workpath $ pwd pwd The shell sets up many environment /home/abenson/playground variables, such as those shown.
Variables $ echo echo $SHELL /bin/bash $ echo echo $USER abenson $ echo echo $HOME /home/abenson $ workpath=$home/playground $ cd cd $workpath $ pwd pwd /home/abenson/playground User Variables Define your own variables and then use them in the command line.
Background Processes $./job.sh $ ^C ^C $./job.sh $ ^Z ^Z $ jobs jobs $ fg fg $ ^Z ^Z $ bg bg $ jobs jobs
Background Processes $./job.sh $ ^C ^C $./job.sh $ ^Z ^Z $ jobs jobs $ fg fg $ ^Z ^Z $ bg bg $ jobs jobs A script we ll learn more about scripts soon this one just writes annoying messages
Background Processes $./job.sh $ ^C ^C $./job.sh $ ^Z ^Z Cancel [1]+ [1]+ Stopped./job.sh $ jobs jobs ^C cancels the running command [1]+ [1]+ Stopped./job.sh $ fg fg $./job.sh $ ^Z ^Z [1]+ [1]+ Stopped./job.sh $ bg bg [1]+ [1]+./job.sh & $ jobs jobs [1]+ [1]+ Running./job.sh & $./job.sh & [2] [2] 21194
Background Processes $./job.sh $ ^C ^C $./job.sh $ ^Z ^Z [1]+ [1]+ Stopped./job.sh $ jobs jobs Suspend [1]+ [1]+ Stopped./job.sh $ fg fg ^Z suspends the running command $./job.sh $ ^Z ^Z [1]+ [1]+ Stopped./job.sh $ bg bg [1]+ [1]+./job.sh & $ jobs jobs [1]+ [1]+ Running./job.sh & $./job.sh & [2] [2] 21194
Background Processes $./job/.sh $ ^C ^C $./job/.sh $ ^Z ^Z [1]+ [1]+ Stopped./job.sh $ jobs jobs [1]+ [1]+ Stopped./job.sh $ fg fg Jobs $./job/.sh $ ^Z ^Z Shows a list of jobs running or [1]+ [1]+ Stopped suspended./job.sh $ bg bg [1]+ [1]+./job.sh & $ jobs jobs [1]+ [1]+ Running./job.sh & $./job/.sh & [2] [2] 21194
Background Processes $./job.sh $ ^C ^C $./job.sh $ ^Z ^Z [1]+ [1]+ Stopped./job.sh $ jobs jobs [1]+ [1]+ Stopped./job.sh $ fg fg $./job.sh $ ^Z ^Z ForeGround [1]+ [1]+ Stopped./job.sh $ bg bg Bring the last suspended job back into [1]+ [1]+./job.sh & the foregound (i.e. start running again). $ jobs jobs [1]+ [1]+ Running./job.sh & $./job.sh & [2] [2] 21194
Background Processes $./job.sh $ ^C ^C $./job.sh $ ^Z ^Z [1]+ [1]+ Stopped./job.sh $ jobs jobs [1]+ [1]+ Stopped./job.sh $ fg fg $./job.sh $ ^Z ^Z [1]+ [1]+ Stopped./job.sh $ bg bg [1]+ [1]+./job.sh & $ jobs jobs BackGround [1]+ [1]+ Running./job.sh & $./job.sh & Run the last suspended job in the [2] [2] 21194 background.
Background Processes $./job.sh $ ^C ^C $./job.sh $ ^Z ^Z [1]+ [1]+ Stopped./job.sh $ jobs jobs [1]+ [1]+ Stopped./job.sh $ fg fg $./job.sh $ ^Z ^Z [1]+ [1]+ Stopped./job.sh $ bg bg [1]+ [1]+./job.sh & $ jobs jobs & [1]+ [1]+ Running./job.sh & $./job.sh & Start the command in the background. [2] [2] 21194
Network and Remote Connections $ hostname dhcp225.obs.carnegiescience.edu $ ssh ssh testuser@mies.stanford.edu Last Last login: Thu Thu Jun Jun 2 14:03:01 2016 2016 from from ociw.edu testuser@mies ~] ~] hostname obs-ssh.ad.ciw.edu testuser@mies ~] ~] exit exit Connection to to mies.stanford.edu closed. $ cd cd animals/mammals $ scp scp badger.txt testuser@mies.stanford.edu:myname.txt badger.txt 100% 100% 1944 1944 1.9KB/s 00:00 $ ssh ssh testuser@mies.stanford.edu Last Last login: Thu Thu Jun Jun 2 14:03:01 2016 2016 from from ociw.edu testuser@mies ~] ~] ls ls badger.txt testuser@mies ~] ~] rm rm myname.txt testuser@mies ~] ~] exit exit Connection to to mies.stanford.edu closed.
Network and Remote Connections $ hostname dhcp225.obs.carnegiescience.edu $ ssh ssh testuser@mies.stanford.edu Last Last login: Thu Thu Jun Jun 2 14:03:01 2016 2016 from from ociw.edu testuser@mies ~] ~] hostname obs-ssh.ad.ciw.edu testuser@mies ~] ~] exit exit Secure SHell Connection to to ssh.obs.carnegiescience.edu closed. $ cd cd animals/mammals Open a shell on a remote server. $ scp scp badger.txt testuser@mies.stanford.edu: badger.txt 100% 100% 1944 1944 Password 1.9KB/s is: HvtTc6Bw 00:00 $ ssh ssh testuser@mies.stanford.edu Last Last login: Thu Thu Jun Jun 2 14:03:01 2016 2016 from from ociw.edu testuser@mies ~] ~] ls ls badger.txt testuser@mies ~] ~] rm rm badger.txt testuser@mies ~] ~] exit exit Connection to to ssh.obs.carnegiescience.edu closed.
Network and Remote Connections $ hostname dhcp225.obs.carnegiescience.edu $ ssh ssh testuser@mies.stanford.edu Last Last login: Thu Thu Jun Jun 2 14:03:01 2016 2016 from from ociw.edu testuser@mies ~] ~] hostname obs-ssh.ad.ciw.edu testuser@mies ~] ~] exit exit Connection to to ssh.obs.carnegiescience.edu closed. $ cd cd animals/mammals $ scp scp badger.txt testuser@mies.stanford.edu: badger.txt 100% 100% 1944 1944 1.9KB/s 00:00 $ ssh ssh testuser@mies.stanford.edu Secure CoPy Last Last login: Thu Thu Jun Jun 2 14:03:01 2016 2016 from from ociw.edu testuser@mies ~] ~] ls ls Copy a file to a remote server. Or from badger.txt remote server to your laptop testuser@mies ~] ~] rm rm badger.txt testuser@mies ~] ~] exit exit Password is: HvtTc6Bw Connection to to ssh.obs.carnegiescience.edu closed.
Network and Remote Connections $ curl curl -L -L -o -o playground1.tar 'http://bit.ly/2swz1ef' curl Download a file from a URL. Useful for downloading big datasets on a remote server.
Scripts #!/bin/sh echo echo This This is is a script. echo echo Hello user user $USER echo echo Here Here are are all all the the files I can can find find find. -type f exit exit
Scripts $ cd cd ~/playground $./script.sh This This is is a script... Hello user user abensonca Here Here are are all all the the files I can can find./script.sh./animals/mammals/badger.txt./animals/mammals/porcupine.txt./animals/reptiles/caiman.txt
Scripts:.bashrc The script in ~/.bashrc gets run every time you log in Use it to configure the environment the way you want it to be For example, you could add an alias: $ alias up='cd..'..' $ cd cd ~/playground/animals $ pwd pwd /home/abenson/playground/animals $ up up $ pwd pwd /home/abenson/playground
Bonus: Text Editing with EMACS There are many text editors in Unix Use whichever you prefer One option available everywhere is EMACS $ emacs playground/animals/reptiles/caiman.txt & [1] [1] 29575
Bonus: Text Editing with EMACS Open file ^X^F Save file ^X^S Cut ^W Paste ^Y Close file ^X^K Search forward ^S Exit EMACS ^X^C Search backward ^R