Python

Olmo S. Zavala Romero

Welcome

Computers system Super basics of terminal Commands man Olmo S. Zavala Romero Center of Atmospheric Sciences, UNAM Ex1 August 9, 2017 Regular expres- sions Ex2 Python

Olmo S. 1 Welcome Zavala Romero 2 Computers

Welcome 3 File system Computers File system 4 Commands Commands man man pwd pwd ls ls cd mkdir cd touch mkdir rm touch mv Ex1 rm Regular mv expres- sions Ex1 grep Regular expressions Ex2 More grep Ex2 More Welcome to this course!

Python

Olmo S. Zavala Romero

Welcome

Computers

File system

Commands 1 am I? man pwd 2 Syllabus ls cd 3 Intro survey https://goo.gl/forms/SD6BM6KHKRlDOpZx1 mkdir 4 touch Homework 1 due this Sunday. rm mv Ex1 Regular expres- sions grep Ex2 More How does a computer works?

Python

Olmo S. Zavala Romero

Welcome

Computers

File system

Commands man pwd ls cd mkdir touch rm mv Ex1 Regular 1 CPU Central Processing Unit. All the computations happen there. expres- sions 2 HD Hard Drive. Stores persistent information in binary . grep 3 RAM Random Access Memory. Faster memory, closer to the CPU, not persistent. Ex2 More 4 GPU Graphics Processing Unit. Used to process graphics.

https://teentechdaily.files.wordpress.com/2015/06/computer-parts-diagram.jpg What is a file?

Python

Olmo S. Zavala Romero

Welcome

Computers

File system

Commands man pwd ls cd mkdir touch rm mv Section inside the HD with 0’s and 1’s. Ex1 Regular File extension is used to identify the meaning of those 0’s and 1’s. expres- sions Examples of file extextensions: png, jpg, py, doc, txt, cpp grep Ex2 http://www.clker.com/cliparts/U/F/n/1/i/2/binary-file-md.png More What is the file system?

Python

Olmo S. Zavala Romero

Welcome

Computers

File system

Commands man pwd ls cd mkdir touch rm mv Ex1 Regular expres- structure (for each partition in disc) sions grep It contains folders and files Ex2 http://cdn.ttgtmedia.com/rms/onlineImages/TT_tree_desktop.jpg More Linux file system?

Python

Olmo S. Zavala Romero

Welcome

Computers

File system

Commands man pwd ls cd mkdir touch rm mv Ex1 Regular expres- sions grep Ex2 More Basic linux terminal commands

Python

Olmo S. Zavala Romero

Welcome

Computers

File system

Commands WHERE TO PRACTICE OUTSIDE THE CLASSROOM: man http://www.webminal.org/ pwd https://www.tutorialspoint.com/unix_terminal_online.php ls cd 1 man Shows the documentation of other terminal commands. mkdir 2 pwd Shows the current position in the terminal. touch rm 3 ls List the files and folders and its information. mv 4 cd Moves within the file system tree structure. Ex1 Regular 5 mkdir Creates directories. expres- 6 touch Creates files. sions grep 7 rm Removes files (and directories). Ex2 8 Copies files and folders to other locations. More 9 mv Moves files and folders to other locations. 10 grep Searches for files and folders.

https://teentechdaily.files.wordpress.com/2015/06/computer-parts-diagram.jpg man

Python An interface to the on-line reference manuals Olmo S. Zavala 1 Inside the manual page use: Romero h For Welcome j Down Computers k Up

File system space Forward one window Backward one window Commands /pattern Search pattern inside manual man pwd G Go to the end ls q Quit cd Examples: mkdir touch rm man command # Shows the reference manual of command mv man -f command # Summary of the command Ex1 man -help # Help for the man command Regular expres- sions grep Ex2 More pwd

Python Prints name of current Olmo S. Zavala Examples: Romero

Welcome pwd #:)

Computers

File system

Commands man pwd ls cd mkdir touch rm mv Ex1 Regular expres- sions grep Ex2 More ls

Python List directory contents Olmo S. Zavala It can use Globbing for file expansion. Check this website: . Romero Examples: Welcome

Computers ls # Lists files and folders

File system ls -a # Lists also hidden files(what are hidden files?) ls folder # Lists content of specific folder Commands ls -l # List in vertically man pwd ls *.txt # List all files that end with.txt ls ls Important* # List all files that with important cd mkdir touch rm mv Ex1 Regular expres- sions grep Ex2 More cd

Python Change the working directory Olmo S. Zavala Examples: Romero

Welcome cd folder # to the specified folder cd .. # Move one folder up in the tree Computers cd ˜ # Move the user HOME folder File system

Commands man pwd ls cd mkdir touch rm mv Ex1 Regular expres- sions grep Ex2 More mkdir

Python directories Olmo S. Zavala Examples: Romero

Welcome mkdir folderName # Creates the directory folderName

Computers

File system

Commands man pwd ls cd mkdir touch rm mv Ex1 Regular expres- sions grep Ex2 More touch

Python Simple way to make text files (if the file exists, it updates its timestamp) Olmo S. Zavala Examples: Romero

Welcome touch file.txt # Creates the file file.txt

Computers

File system

Commands man pwd ls cd mkdir touch rm mv Ex1 Regular expres- sions grep Ex2 More rm

Python Remove files or directories Olmo S. Zavala It can use Globbing for file expansion. Check this website: LINK. Romero Examples: Welcome

Computers rm file # Removes the specified file

File system rm -r folder # Removes the specified folder and all its files rm *.txt # Removes all the files that end with.txt Commands man pwd ls cd mkdir touch rm mv Ex1 Regular expres- sions grep Ex2 More mv

Python Move or rename files and folders Olmo S. Zavala It can use Globbing for file expansion. Check this website: LINK. Romero Examples: Welcome

Computers mv fileOrigin fileDest # Moves fileOrigin as fileDest

File system mv - fileOrigin fileDest # Makea backup if fileDest already exists mv *.txt folder # Moves all the.txt files intoa different folder Commands man pwd ls cd mkdir touch rm mv Ex1 Regular expres- sions grep Ex2 More 2 Move Two.txt into the Thesis folder with the name Three.txt 3 Move the folder Data into a new directory called RootData 4 Delete the Tools folder 5 Rename the Thesis folder to DoneThesis 6 Move to the Stats folder, from there Three.txt (inside DoneThesis) into the Old folder with the name OldThree.csv.

Excercises

Python

Olmo S. Zavala Romero

Welcome

Computers

File system

Commands man pwd ls cd mkdir touch rm mv Ex1 1 Copy One.txt inside Format folder Regular expres- sions grep Ex2 More 3 Move the folder Data into a new directory called RootData 4 Delete the Tools folder 5 Rename the Thesis folder to DoneThesis 6 Move to the Stats folder, from there copy Three.txt (inside DoneThesis) into the Old folder with the name OldThree.csv.

Excercises

Python

Olmo S. Zavala Romero

Welcome

Computers

File system

Commands man pwd ls cd mkdir touch rm mv Ex1 1 Copy One.txt inside Format folder Regular 2 Move Two.txt into the Thesis folder with the name Three.txt expres- sions grep Ex2 More 4 Delete the Tools folder 5 Rename the Thesis folder to DoneThesis 6 Move to the Stats folder, from there copy Three.txt (inside DoneThesis) into the Old folder with the name OldThree.csv.

Excercises

Python

Olmo S. Zavala Romero

Welcome

Computers

File system

Commands man pwd ls cd mkdir touch rm mv Ex1 1 Copy One.txt inside Format folder Regular 2 Move Two.txt into the Thesis folder with the name Three.txt expres- sions 3 Move the folder Data into a new directory called RootData grep Ex2 More 5 Rename the Thesis folder to DoneThesis 6 Move to the Stats folder, from there copy Three.txt (inside DoneThesis) into the Old folder with the name OldThree.csv.

Excercises

Python

Olmo S. Zavala Romero

Welcome

Computers

File system

Commands man pwd ls cd mkdir touch rm mv Ex1 1 Copy One.txt inside Format folder Regular 2 Move Two.txt into the Thesis folder with the name Three.txt expres- sions 3 Move the folder Data into a new directory called RootData grep 4 Delete the Tools folder Ex2 More 6 Move to the Stats folder, from there copy Three.txt (inside DoneThesis) into the Old folder with the name OldThree.csv.

Excercises

Python

Olmo S. Zavala Romero

Welcome

Computers

File system

Commands man pwd ls cd mkdir touch rm mv Ex1 1 Copy One.txt inside Format folder Regular 2 Move Two.txt into the Thesis folder with the name Three.txt expres- sions 3 Move the folder Data into a new directory called RootData grep 4 Delete the Tools folder Ex2 More 5 Rename the Thesis folder to DoneThesis Excercises

Python

Olmo S. Zavala Romero

Welcome

Computers

File system

Commands man pwd ls cd mkdir touch rm mv Ex1 1 Copy One.txt inside Format folder Regular 2 Move Two.txt into the Thesis folder with the name Three.txt expres- sions 3 Move the folder Data into a new directory called RootData grep 4 Delete the Tools folder Ex2 More 5 Rename the Thesis folder to DoneThesis 6 Move to the Stats folder, from there copy Three.txt (inside DoneThesis) into the Old folder with the name OldThree.csv. Regular expressions

Python Regular expressons are a way to do pattern matching. We use them to find Olmo S. Zavala specif within a text. Romero

Welcome

Computers

File system

Commands man pwd ls cd mkdir touch rm mv Ex1 Regular expres- sions grep Ex2 More

http://ryanstutorials.net/linuxtutorial/grep.php grep

Python Searches input files for lines containing a match to the given pattern (or Olmo S. Zavala ) Romero Examples: Welcome

Computers grep'pattern' FILE # Searches the pattern inside FILE

File system grep -i'pattern' FILE # Same as above but case-insensitive grep -n'pattern' FILE # Shows the line number Commands grep -w'pattern' FILE # Patter must bea complete word man pwd grep -r'pattern' FOLDER # Searches the pattern inside all files inside FOLDER ls grep -'pattern' FILE # Searches the lines that do NOT match the pattern cd mkdir touch Specific Examples using regular expressions: rm mv grep -E'd.y' myfile.txt # day, doy, dly, dwy, etc. Ex1 grep -E'ˆ' myfile.txt # Every line that starts witha space Regular grep -E'R{2}' myfile.txt # Lines with least2 Rs together expres- sions grep -E'R{2,2}' myfile.txt # Lines with exactly2 Rs together grep Ex2 More 2 all the words with 4 letters

3 Find all the files without b inside

4 Find the lines that end with k

5 Find the first 2 lines with boo inside

Excercises

Python Assume your file contains: Olmo S. Zavala Romero boot book Welcome booze Computers machine File system boots Commands bungie man bark pwd aardvark ls broken#tuff cd robots mkdir touch rm mv 1 Find all the lines with b insde Ex1 Regular expres- sions grep Ex2 More 3 Find all the files without b inside

4 Find the lines that end with k

5 Find the first 2 lines with boo inside

Excercises

Python Assume your file contains: Olmo S. Zavala Romero boot book Welcome booze Computers machine File system boots Commands bungie man bark pwd aardvark ls broken#tuff cd robots mkdir touch rm mv 1 Find all the lines with b insde Ex1 Regular 2 Find all the words with 4 letters expres- sions grep Ex2 More 4 Find the lines that end with k

5 Find the first 2 lines with boo inside

Excercises

Python Assume your file contains: Olmo S. Zavala Romero boot book Welcome booze Computers machine File system boots Commands bungie man bark pwd aardvark ls broken#tuff cd robots mkdir touch rm mv 1 Find all the lines with b insde Ex1 Regular 2 Find all the words with 4 letters expres- sions 3 Find all the files without b inside grep Ex2 More 5 Find the first 2 lines with boo inside

Excercises

Python Assume your file contains: Olmo S. Zavala Romero boot book Welcome booze Computers machine File system boots Commands bungie man bark pwd aardvark ls broken#tuff cd robots mkdir touch rm mv 1 Find all the lines with b insde Ex1 Regular 2 Find all the words with 4 letters expres- sions 3 Find all the files without b inside grep Ex2 4 Find the lines that end with k More Excercises

Python Assume your file contains: Olmo S. Zavala Romero boot book Welcome booze Computers machine File system boots Commands bungie man bark pwd aardvark ls broken#tuff cd robots mkdir touch rm mv 1 Find all the lines with b insde Ex1 Regular 2 Find all the words with 4 letters expres- sions 3 Find all the files without b inside grep Ex2 4 Find the lines that end with k More 5 Find the first 2 lines with boo inside More

Python There are many more commands in Linux. I strongly suggest you to keep Olmo S. Zavala learning more and more (it will make your life easier along the way). Romero These are some of them: https://sites.tufts.edu/cbi/files/ Welcome 2013/01/linux_cheat_sheet.pdf Computers

File system

Commands man pwd ls cd mkdir touch rm mv Ex1 Regular expres- sions grep Ex2 More