R 2 Academy Command Line Crash Course www.r-squared.in/gi t-hub - - PowerPoint PPT Presentation

r 2 academy
SMART_READER_LITE
LIVE PREVIEW

R 2 Academy Command Line Crash Course www.r-squared.in/gi t-hub - - PowerPoint PPT Presentation

R 2 Academy Command Line Crash Course www.r-squared.in/gi t-hub Connect With Us Rsquared Academy Website Free Online R Courses R Packages Shiny Apps Blog GitHub YouTube Twitter Facebook Linkedin


slide-1
SLIDE 1

www.r-squared.in/gi t-hub

R2 Academy

Command Line Crash Course

slide-2
SLIDE 2

Connect With Us Rsquared Academy

→ Website → Free Online R Courses → R Packages → Shiny Apps → Blog → GitHub → YouTube → Twitter → Facebook → Linkedin

www.rsquaredacademy.com

2

slide-3
SLIDE 3

Resources Rsquared Academy

→ Slides → Code & Data → RStudio Cloud → Online Course

www.rsquaredacademy.com

3

slide-4
SLIDE 4

Agenda Rsquared Academy

→ Launch Terminal/Shell → macOS → Windows → Linux → Shell Commands → File management → System management → Navigating file system → Help/Documentation → Input/Output → Search & Regular expression → Use RStudio terminal → Run commands from R

www.rsquaredacademy.com

4

slide-5
SLIDE 5

What is shell? Rsquared Academy

www.rsquaredacademy.com

5

Shell is a text based application for viewing, handling and manipulating files. It takes in commands and passes them on to the operating system. It is also known as: ➔ CLI (Command Line Interface) ➔ Terminal ➔ Bash (Bourne Again Shell) It is sufficient to know a handful of commands to get started with the shell.

slide-6
SLIDE 6

Applications Rsquared Academy

www.rsquaredacademy.com

6

Cloud Services Version Control

slide-7
SLIDE 7

Launch Terminal - macOS Rsquared Academy

www.rsquaredacademy.com

7

  • Applications -> Utilities -> Terminal
slide-8
SLIDE 8

Launch Terminal - Windows Rsquared Academy

www.rsquaredacademy.com

8

slide-9
SLIDE 9

Launch Terminal - Windows Rsquared Academy

www.rsquaredacademy.com

9

slide-10
SLIDE 10

Launch Terminal - Linux Rsquared Academy

www.rsquaredacademy.com

10

  • Applications -> Accessories -> Terminal
  • Applications -> System -> Terminal
slide-11
SLIDE 11

RStudio Terminal Rsquared Academy

www.rsquaredacademy.com

11

slide-12
SLIDE 12

Get Started Rsquared Academy

www.rsquaredacademy.com

12

Command Description whoami List files & folders date Print working directory cal Create directory clear Remove/delete directory

slide-13
SLIDE 13

Navigating File System Rsquared Academy

www.rsquaredacademy.com

13

Command Description ls List files & folders cd/pwd Print working directory mkdir Create directory rmdir Remove/delete directory

slide-14
SLIDE 14

List Directory Contents Rsquared Academy

www.rsquaredacademy.com

14

Command Description ls List directory contents ls -l List files one per line ls -a List all files, including hidden files ls - la Display permission, ownership, size & modification date ls -lh Long format with size displayed in human readable units ls -lS Long format list sorted by size ls -ltr Long format list sorted by modification date

slide-15
SLIDE 15

File Management Rsquared Academy

www.rsquaredacademy.com

15

Command Description touch Create empty file/change timestamp cp Copy file(s) mv Rename/move file rm Remove/delete file diff Compare files

slide-16
SLIDE 16

Move or Rename Files Rsquared Academy

www.rsquaredacademy.com

16

Command Description mv Move or rename files & directories mv -f Do not prompt for confirmation before overwriting files mv -i Prompt for confirmation before overwriting files mv -n Do not overwrite existing files mv -v Move files in verbose mode

slide-17
SLIDE 17

Remove/Delete Files Rsquared Academy

www.rsquaredacademy.com

17

Command Description rm Remove files or directories rm -r Recursively remove a directory & all its subdirectories rm -rf Forcibly remove directory without prompting for confirmation or showing error messages rm -i Interactively remove multiple files, with a prompt before every removal rm -v Remove files in verbose mode, printing a message for each removed file

slide-18
SLIDE 18

Compare Files Rsquared Academy

www.rsquaredacademy.com

18

Command Description diff Compare files & directories diff -w Compare files; ignoring white spaces diff -y Compare files; showing differences side by side diff -u Compare files; show differences in unified format diff -r Compare directories recursively diff -rq Compare directories; show the names of files that differ

slide-19
SLIDE 19

Input/Output Rsquared Academy

www.rsquaredacademy.com

19

Command Description echo Display messages cat Prints content of a file head Prints the first 10 lines of a file by default tail Prints the last 10 lines of a file by default more Display more less Display less sort Sort a file in ascending order

slide-20
SLIDE 20

Display Messages Rsquared Academy

www.rsquaredacademy.com

20

Command Description echo Print text message echo -n Without the trailing newline echo > file Write message to a file echo >> file Append a message to a file echo -e Enable interpretation of special characters

slide-21
SLIDE 21

Print & Concatenate Files Rsquared Academy

www.rsquaredacademy.com

21

Command Description cat Print and concatenate files cat > Concatenate several files into the target file cat >> Append several files to the target file cat -n Number all output lines

slide-22
SLIDE 22

Head Rsquared Academy

www.rsquaredacademy.com

22

Command Description head Output the first parts of a file head -n Output the first n lines of a file head -c Output the first c bytes of a file head -n -5 file Output everything but the last 5 lines of a file head -c -3 file Output everything but the last 3 bytes of a file

slide-23
SLIDE 23

Tail Rsquared Academy

www.rsquaredacademy.com

23

Command Description tail Display the last part of a file tail -n num file Show the last num lines of a file tail -n +num file Show all file since num line tail -c num file Show last num bytes in a file tail -f file Keep reading file until Ctrl + C tail -f file Keep reading file until Ctrl + C; even if the file is rotated

slide-24
SLIDE 24

More Rsquared Academy

www.rsquaredacademy.com

24

Command Description more Open a file for interactive reading; allowing scrolling & search space Page down /search Search for a string; press n to go to the next match q Quit

slide-25
SLIDE 25

Less Rsquared Academy

www.rsquaredacademy.com

25

Command Description less Open a file for interactive reading; allowing scrolling & search space Page down b Page up G Go to end of file g Go to start of file /search Forward search ?search Backward search n Go to next match N Go to previous match q Exit

slide-26
SLIDE 26

Sort Rsquared Academy

www.rsquaredacademy.com

26

Command Description sort file-name Sort lines of text files sort -r file-name Sort a file in descending order sort –-ignore-case file-name Ignore case sort -n file-name Use numeric order for sorting sort -u file-name Preserve only unique lines

slide-27
SLIDE 27

Search & Regular Expression Rsquared Academy

www.rsquaredacademy.com

27

Command Description grep Search for a given string in a file find Find files using filenames which Search for binary executable files

slide-28
SLIDE 28

grep Rsquared Academy

www.rsquaredacademy.com

28

Command Description grep Matches patterns in input text grep -i Ignore case grep -RI Search recursively for an exact string grep -E Use extended regular expression grep -Hn Print file name & corresponding line number for each match grep -v Invert match for excluding specific strings

slide-29
SLIDE 29

grep Rsquared Academy

www.rsquaredacademy.com

29

Command Description find Find files or directories under the given directory; recursively find directory -name '*.txt' Find files by extension find directory -type d -iname folder_name Find directories matching a given name, in case-insensitive mode: find directory -type d -name folder_name Find directories matching a given name, in case-sensitive mode:

slide-30
SLIDE 30

Keyboard Shortcuts Rsquared Academy

www.rsquaredacademy.com

30

Command Description Ctrl + C Halts the current command Ctrl + D Logout of current session (exit) Ctrl + W Erases one word in current line Ctrl + U Erases whole line Ctrl + R Bring up a recent command

slide-31
SLIDE 31

Network Rsquared Academy

www.rsquaredacademy.com

31

Command Description wget Download from the internet curl Download files from the internet hostname Name of current host ping Ping a remote host nslookup Name server and ip details

slide-32
SLIDE 32

wget Rsquared Academy

www.rsquaredacademy.com

32

Command Description wget Download files from the web wget url Download contents of a url to a file wget -o file_name url Download contents of a url to a file wget -c url Continue an incomplete download wget -P folder_name -i urls.txt Download all urls stored in a text file to a specific directory wget –-limit-rate=300 Limit download speed wget –-tries=100 Limit number of retries

slide-33
SLIDE 33

wget Rsquared Academy

www.rsquaredacademy.com

33

Command Description curl Transfers data from or to a server curl url Download the contents of a url curl url -o file_name Download the contents of a url to a file

slide-34
SLIDE 34

User Information Rsquared Academy

www.rsquaredacademy.com

34

Command Description finger Information about user last login, home directory & full name groups Which groups a user is member of? who List the currently logged in users whoami Get username & group information

slide-35
SLIDE 35

File Compression Rsquared Academy

www.rsquaredacademy.com

35

Command Description tar Create, extract or view tar archive unzip To extract a zip file gzip Compress file

slide-36
SLIDE 36

tar Rsquared Academy

www.rsquaredacademy.com

36

Command Description tar Archiving utility tar -cf target.tar file1 file2 Create an archive from file tar -czf target.tar.gz file1 file2 Create a gzipped archive tar -xf target.tar -C folder_name Extract an archive in a target directory tar -xzf target.tar.gz Extract a gzipped archive in the current directory tar -tvf target.tar List the contents of a tar file

slide-37
SLIDE 37

gzip & unzip Rsquared Academy

www.rsquaredacademy.com

37

Command Description unzip files Extract zip files unzip zipped_files -d target_directory Extract zip files to a given path gzip file.ext Compress a file gzip -d file.ext.gz Decompress a file gzip -c file.ext > compress_file Compress a file and specify the output file name

slide-38
SLIDE 38

System Management Rsquared Academy

www.rsquaredacademy.com

38

Command Description uname Display important information about the system free Display free, used, swap memory in the system df Display file system disk space usage exit Exit the terminal sudo Run command as super user shutdown Shutdown the system

slide-39
SLIDE 39

uname Rsquared Academy

www.rsquaredacademy.com

39

Command Description uname Print details about the current machine and the operating system running on it uname -mp Hardware related information; machine & processor uname -srv Software related information; operating system, release number and version uname -n Nodename of the system uname -a Print all available information system uname Print details about the current machine and the operating system running on it

slide-40
SLIDE 40

Others Rsquared Academy

www.rsquaredacademy.com

40

Command Description time See how long a command takes to execute sleep Delay activity in seconds sleep 1m Delay activity in minutes sleep 1h Delay activity in hours history Display command history list with line numbers history -c Clear the command history list

slide-41
SLIDE 41

Funny Commands Rsquared Academy

www.rsquaredacademy.com

41

Command Description fortune Poignant, inspirational and silly phrases yes Output a string repeatedly until killed banner ASCII banner rev Reverse each character

slide-42
SLIDE 42

system() Rsquared Academy

www.rsquaredacademy.com

42

slide-43
SLIDE 43

system() Rsquared Academy

www.rsquaredacademy.com

43

slide-44
SLIDE 44

Summary Rsquared Academy

→ Shell is a text based application for viewing, handling and manipulating files

→ It is also known by the following names: → CLI (Command Line Interface) → Terminal → Bash (Bourne Again Shell)

→ Useful in several scenarios including:

→ Version Control → Cloud Services

→ RStudio includes a Terminal

→ Use system() in R to run commands

www.rsquaredacademy.com

44

slide-45
SLIDE 45

What we have not covered Rsquared Academy

→ Shell scripting

→ Editing files → Using sudo → File Permission → User Information → Pipes → awk → sed

www.rsquaredacademy.com

45

slide-46
SLIDE 46

References Rsquared Academy

→ http://www2.imm.dtu.dk/courses/02333/cygwin_tutorial/index.html → https://tutorial.djangogirls.org/en/intro_to_command_line/ → https://ss64.com/ → https://www.learnenough.com/command-line-tutorial → https://blog.rstudio.com/2017/08/11/rstudio-v1-1-preview-terminal/ → https://support.rstudio.com/hc/en-us/articles/115010737148-Using-the-RStudio-Terminal

www.rsquaredacademy.com

46

slide-47
SLIDE 47