• Command Line Basics for R Users
  • Welcome
  • Preface
    • Outline
    • Topics this book does not cover
    • About this book
    • Using code examples
    • Software information
  • 1 Introduction
    • 1.1 What is Shell/Terminal?
    • 1.2 Launch Terminal
      • 1.2.1 mac
      • 1.2.2 Windows
      • 1.2.3 Linux
      • 1.2.4 Windows Subsystem for Linux
      • 1.2.5 RStudio Terminal
    • 1.3 Prompt
    • 1.4 Get Started
    • 1.5 Help/Documentation
  • 2 Navigating File System
    • 2.1 Introduction
    • 2.2 Change Working Directory
    • 2.3 List Directory Contents
      • 2.3.1 List files one per line
      • 2.3.2 List all files including hidden files
      • 2.3.3 Display file permissions, ownership, size & modification date
      • 2.3.4 Display size in human readable format
      • 2.3.5 Sort list by size
      • 2.3.6 Sort list by modification date
    • 2.4 R Functions
  • 3 File Management
    • 3.1 Create new file
    • 3.2 Copy Files/Folders
      • 3.2.1 Copy files in same folder
      • 3.2.2 Copy files into different folder
      • 3.2.3 Copy folders
    • 3.3 Move/Rename Files
      • 3.3.1 Move files in verbose mode
      • 3.3.2 Do not overwrite existing files
      • 3.3.3 Do not prompt for confirmation before overwriting files
    • 3.4 Remove/Delete Files
      • 3.4.1 Remove files
      • 3.4.2 Recursive Deletion
      • 3.4.3 Force Removal
      • 3.4.4 Verbose Mode
    • 3.5 Compare Files
      • 3.5.1 Compare Files
      • 3.5.2 Side By Side
      • 3.5.3 Unified Format
      • 3.5.4 Compare Recursively
      • 3.5.5 File Details
    • 3.6 R Functions
  • 4 Input/Output
    • 4.1 Display Messages
      • 4.1.1 Print Message
      • 4.1.2 Redirect Output
    • 4.2 Print & Concatenate Files
      • 4.2.1 Print Content
      • 4.2.2 Number All Output Lines
      • 4.2.3 Concatenate Several Files
    • 4.3 Head
      • 4.3.1 Output the first parts of a file
      • 4.3.2 Output the first n lines of a file
      • 4.3.3 Output the first c bytes of a file
      • 4.3.4 Output everything but the last 5 lines of a file
      • 4.3.5 Output everything but the last 3 bytes of a file
    • 4.4 Tail
      • 4.4.1 Display the last parts of a file
      • 4.4.2 Display the last 5 lines of a file
      • 4.4.3 Display all contents from line 10
      • 4.4.4 Display the last 10 bytes of a file
    • 4.5 More
    • 4.6 Less
    • 4.7 Sort
      • 4.7.1 Sort
      • 4.7.2 Descending Order
      • 4.7.3 Ignore case
      • 4.7.4 Numeric Order
      • 4.7.5 Preserve Only Unique Lines
    • 4.8 Word Count
      • 4.8.1 Count words, bytes and lines
      • 4.8.2 Count lines in a file
      • 4.8.3 Count words in a file
      • 4.8.4 Count characters(bytes) in a file
  • 5 Search & Regular Expression
    • 5.1 grep
      • 5.1.1 Match Pattern in Input Text
      • 5.1.2 Ignore Case
      • 5.1.3 Highlight
      • 5.1.4 Print Filename
      • 5.1.5 Print Corresponding Line Number
      • 5.1.6 Print Filename & Line Number
      • 5.1.7 Invert Match
      • 5.1.8 Recursive Search
    • 5.2 find
      • 5.2.1 Search Recursively
      • 5.2.2 Search by Extension
      • 5.2.3 Case-insensitive Mode
      • 5.2.4 Case-sensitive Mode
  • 6 Data Transfer
    • 6.1 wget
      • 6.1.1 Download URL
      • 6.1.2 Specify Filename
      • 6.1.3 Download File
      • 6.1.4 Download Multiple URLs
      • 6.1.5 Quiet
      • 6.1.6 No Verbose
      • 6.1.7 Check Timestamp
    • 6.2 curl
      • 6.2.1 Download URL
      • 6.2.2 Specify File
      • 6.2.3 Download Silently
    • 6.3 R Functions
  • 7 sudo
  • 8 File Compression
    • 8.1 tar
      • 8.1.1 List
      • 8.1.2 Extract
      • 8.1.3 Add
      • 8.1.4 Create
    • 8.2 gzip
      • 8.2.1 Compress
      • 8.2.2 Decompress
      • 8.2.3 Specify Filename
    • 8.3 zip & unzip
      • 8.3.1 List
      • 8.3.2 Extract
      • 8.3.3 Compress
      • 8.3.4 Add
    • 8.4 R Functions
      • 8.4.1 tar & tar.gz
      • 8.4.2 zip & gzip
  • 9 System Info
    • 9.1 uname
      • 9.1.1 Print all available information about the system
      • 9.1.2 Display free, used, swap memory in the system
      • 9.1.3 Display file system disk space usage
    • 9.2 Others
    • 9.3 Funny Commands
    • 9.4 R Functions
  • 10 R & the Shell
    • 10.1 R
    • 10.2 RStudio
    • 10.3 RMarkdown
    • 10.4 Rscript
  • 11 Conclusion
    • 11.1 What we have not covered…
    • 11.2 Summary
    • 11.3 References
      • 11.3.1 Feedback
  • Published with bookdown

Command Line Basics for R Users

Chapter 2 Navigating File System

2.1 Introduction

In this chapter, we will learn commands that will help us

  • navigate between different folders/directories
  • return current working directory
  • list all the files & folders in a directory
  • create and delete directories
Command Description
pwd Print working directory
ls List directory contents
cd Change current working directory
mkdir Create directory
rmdir Remove/delete directory

pwd displays the name of the present working directory.

pwd
## /mnt/j/R/ebooks/bash-intro/cline

ls displays information about files and directories in the current directory along with their associated metadata such as

  • size
  • ownership
  • modification date

With no options, it will list the files and directories in the current directory, sorted alphabetically.

ls
## analysis.R
## bash-tutorial
## bash.R
## bash.Rmd
## bash.sh
## imports_blorr.txt
## imports_olsrr.txt
## lorem-ipsum.txt
## main_project.zip
## myfiles
## mypackage
## myproject
## myproject.zip
## myproject1
## myproject2
## myproject3
## myproject4
## package_names.txt
## packproj.zip
## pkg_names.tar
## pkg_names.txt
## r
## r2
## r_releases
## release_names.tar
## release_names.tar.gz
## release_names.txt
## release_names_18.txt
## release_names_18_19.txt
## release_names_19.txt
## releases.txt.gz
## sept_15.csv.gz
## urls.txt
## zip_example.zip

cd (change directory) changes the current working directory. It is among the most used commands as it allows the user to move around the file system.

cd r
pwd
## /mnt/j/R/ebooks/bash-intro/cline/r

mkdir will create new directory. It will allow you to set file mode (permissions associated with the directory) i.e. who can open/modify/delete the directory.

mkdir rfiles
ls
## analysis.R
## bash-tutorial
## bash.R
## bash.Rmd
## bash.sh
## imports_blorr.txt
## imports_olsrr.txt
## lorem-ipsum.txt
## main_project.zip
## myfiles
## mypackage
## myproject
## myproject.zip
## myproject1
## myproject2
## myproject3
## myproject4
## package_names.txt
## packproj.zip
## pkg_names.tar
## pkg_names.txt
## r
## r2
## r_releases
## release_names.tar
## release_names.tar.gz
## release_names.txt
## release_names_18.txt
## release_names_18_19.txt
## release_names_19.txt
## releases.txt.gz
## rfiles
## sept_15.csv.gz
## urls.txt
## zip_example.zip

rmdir will remove empty directories from the file system. It can be used to remove multiple empty directories as well. If the directory is not empty, rmdir will not remove it and instead display a warning that the directory is not empty.

rmdir rfiles
ls
## analysis.R
## bash-tutorial
## bash.R
## bash.Rmd
## bash.sh
## imports_blorr.txt
## imports_olsrr.txt
## lorem-ipsum.txt
## main_project.zip
## myfiles
## mypackage
## myproject
## myproject.zip
## myproject1
## myproject2
## myproject3
## myproject4
## package_names.txt
## packproj.zip
## pkg_names.tar
## pkg_names.txt
## r
## r2
## r_releases
## release_names.tar
## release_names.tar.gz
## release_names.txt
## release_names_18.txt
## release_names_18_19.txt
## release_names_19.txt
## releases.txt.gz
## sept_15.csv.gz
## urls.txt
## zip_example.zip

2.2 Change Working Directory

Let us focus a bit more on changing working directory. The below table shows commands for changing working directory to

  • up one level
  • previous working directory
  • home directory
  • and root directory
Command Description
cd . Navigate into directory
cd .. Go up one level
cd - Go to previous working directory
cd ~ Change directory to home directory
cd / Change directory to root directory

All files and directories stem from one main directory, the root directory. All the other directories in the system are sub-directories of the root directory and the root directory has no parent directory. It is represented by a single slash (/). cd / will change the current working directory to the root directory.

cd /
pwd
## /

The parent directory i.e. the directory one level up from the current directory which contains the directory we are in now is represented by two dots (..). cd .. will change us into the parent directory of the current directory.

cd ..
pwd
## /mnt/j/R/ebooks/bash-intro

The home directory is the directory we are placed in, by default, when we launch a new terminal session. It is represented by the tilde (~).

cd ~
pwd
## /home/aravind

To change into the previous working directory, use cd -.

cd -
pwd
## /mnt/j/R/ebooks/bash-intro
## /mnt/j/R/ebooks/bash-intro

The current working directory is represented by a single dot (.). cd . will change us into the current directory i.e. it will do nothing.

2.3 List Directory Contents

ls will list the contents of a directory. Using different arguments, we can

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

2.3.1 List files one per line

ls -l
## total 31132
## -rwxrwxrwx 1 aravind aravind       12 Oct 19  2019 analysis.R
## drwxrwxrwx 1 aravind aravind     4096 Jun 27  2020 bash-tutorial
## -rwxrwxrwx 1 aravind aravind      430 Oct 19  2019 bash.R
## -rwxrwxrwx 1 aravind aravind      145 Oct 19  2019 bash.Rmd
## -rwxrwxrwx 1 aravind aravind    16242 Oct 22  2019 bash.sh
## -rwxrwxrwx 1 aravind aravind       35 Oct 16  2019 imports_blorr.txt
## -rwxrwxrwx 1 aravind aravind       34 Oct 16  2019 imports_olsrr.txt
## -rwxrwxrwx 1 aravind aravind    39501 Oct 19  2019 lorem-ipsum.txt
## -rwxrwxrwx 1 aravind aravind     9291 Oct 19  2019 main_project.zip
## drwxrwxrwx 1 aravind aravind     4096 Jun 27  2020 myfiles
## drwxrwxrwx 1 aravind aravind     4096 Oct 22  2019 mypackage
## drwxrwxrwx 1 aravind aravind     4096 Oct 22  2019 myproject
## -rwxrwxrwx 1 aravind aravind     5200 Jun 27  2020 myproject.zip
## drwxrwxrwx 1 aravind aravind     4096 Jun 27  2020 myproject1
## drwxrwxrwx 1 aravind aravind     4096 Jun 27  2020 myproject2
## drwxrwxrwx 1 aravind aravind     4096 Oct 22  2019 myproject3
## drwxrwxrwx 1 aravind aravind     4096 Oct 22  2019 myproject4
## -rwxrwxrwx 1 aravind aravind     1498 Oct 19  2019 package_names.txt
## -rwxrwxrwx 1 aravind aravind     3937 Jun 27  2020 packproj.zip
## -rwxrwxrwx 1 aravind aravind    10240 Jun 27  2020 pkg_names.tar
## -rwxrwxrwx 1 aravind aravind     1082 Oct 19  2019 pkg_names.txt
## drwxrwxrwx 1 aravind aravind     4096 Oct 22  2019 r
## drwxrwxrwx 1 aravind aravind     4096 Jun 20  2020 r2
## drwxrwxrwx 1 aravind aravind     4096 Jun 27  2020 r_releases
## -rwxrwxrwx 1 aravind aravind    10240 Oct 19  2019 release_names.tar
## -rwxrwxrwx 1 aravind aravind      632 Oct 19  2019 release_names.tar.gz
## -rwxrwxrwx 1 aravind aravind      546 Oct 19  2019 release_names.txt
## -rwxrwxrwx 1 aravind aravind       65 Oct 19  2019 release_names_18.txt
## -rwxrwxrwx 1 aravind aravind      118 Jun 27  2020 release_names_18_19.txt
## -rwxrwxrwx 1 aravind aravind       53 Oct 19  2019 release_names_19.txt
## -rwxrwxrwx 1 aravind aravind      383 Jun 27  2020 releases.txt.gz
## -rwxrwxrwx 1 aravind aravind 31754998 Oct 19  2019 sept_15.csv.gz
## -rwxrwxrwx 1 aravind aravind      157 Oct 19  2019 urls.txt
## -rwxrwxrwx 1 aravind aravind     4398 Oct 19  2019 zip_example.zip

2.3.2 List all files including hidden files

ls -a
## .
## ..
## analysis.R
## bash-tutorial
## bash.R
## bash.Rmd
## bash.sh
## imports_blorr.txt
## imports_olsrr.txt
## lorem-ipsum.txt
## main_project.zip
## myfiles
## mypackage
## myproject
## myproject.zip
## myproject1
## myproject2
## myproject3
## myproject4
## package_names.txt
## packproj.zip
## pkg_names.tar
## pkg_names.txt
## r
## r2
## r_releases
## release_names.tar
## release_names.tar.gz
## release_names.txt
## release_names_18.txt
## release_names_18_19.txt
## release_names_19.txt
## releases.txt.gz
## sept_15.csv.gz
## urls.txt
## zip_example.zip

2.3.3 Display file permissions, ownership, size & modification date

ls -la
## total 31132
## drwxrwxrwx 1 aravind aravind     4096 Jun  2 17:13 .
## drwxrwxrwx 1 aravind aravind     4096 Jun  2 17:13 ..
## -rwxrwxrwx 1 aravind aravind       12 Oct 19  2019 analysis.R
## drwxrwxrwx 1 aravind aravind     4096 Jun 27  2020 bash-tutorial
## -rwxrwxrwx 1 aravind aravind      430 Oct 19  2019 bash.R
## -rwxrwxrwx 1 aravind aravind      145 Oct 19  2019 bash.Rmd
## -rwxrwxrwx 1 aravind aravind    16242 Oct 22  2019 bash.sh
## -rwxrwxrwx 1 aravind aravind       35 Oct 16  2019 imports_blorr.txt
## -rwxrwxrwx 1 aravind aravind       34 Oct 16  2019 imports_olsrr.txt
## -rwxrwxrwx 1 aravind aravind    39501 Oct 19  2019 lorem-ipsum.txt
## -rwxrwxrwx 1 aravind aravind     9291 Oct 19  2019 main_project.zip
## drwxrwxrwx 1 aravind aravind     4096 Jun 27  2020 myfiles
## drwxrwxrwx 1 aravind aravind     4096 Oct 22  2019 mypackage
## drwxrwxrwx 1 aravind aravind     4096 Oct 22  2019 myproject
## -rwxrwxrwx 1 aravind aravind     5200 Jun 27  2020 myproject.zip
## drwxrwxrwx 1 aravind aravind     4096 Jun 27  2020 myproject1
## drwxrwxrwx 1 aravind aravind     4096 Jun 27  2020 myproject2
## drwxrwxrwx 1 aravind aravind     4096 Oct 22  2019 myproject3
## drwxrwxrwx 1 aravind aravind     4096 Oct 22  2019 myproject4
## -rwxrwxrwx 1 aravind aravind     1498 Oct 19  2019 package_names.txt
## -rwxrwxrwx 1 aravind aravind     3937 Jun 27  2020 packproj.zip
## -rwxrwxrwx 1 aravind aravind    10240 Jun 27  2020 pkg_names.tar
## -rwxrwxrwx 1 aravind aravind     1082 Oct 19  2019 pkg_names.txt
## drwxrwxrwx 1 aravind aravind     4096 Oct 22  2019 r
## drwxrwxrwx 1 aravind aravind     4096 Jun 20  2020 r2
## drwxrwxrwx 1 aravind aravind     4096 Jun 27  2020 r_releases
## -rwxrwxrwx 1 aravind aravind    10240 Oct 19  2019 release_names.tar
## -rwxrwxrwx 1 aravind aravind      632 Oct 19  2019 release_names.tar.gz
## -rwxrwxrwx 1 aravind aravind      546 Oct 19  2019 release_names.txt
## -rwxrwxrwx 1 aravind aravind       65 Oct 19  2019 release_names_18.txt
## -rwxrwxrwx 1 aravind aravind      118 Jun 27  2020 release_names_18_19.txt
## -rwxrwxrwx 1 aravind aravind       53 Oct 19  2019 release_names_19.txt
## -rwxrwxrwx 1 aravind aravind      383 Jun 27  2020 releases.txt.gz
## -rwxrwxrwx 1 aravind aravind 31754998 Oct 19  2019 sept_15.csv.gz
## -rwxrwxrwx 1 aravind aravind      157 Oct 19  2019 urls.txt
## -rwxrwxrwx 1 aravind aravind     4398 Oct 19  2019 zip_example.zip

2.3.4 Display size in human readable format

ls -lh
## total 31M
## -rwxrwxrwx 1 aravind aravind   12 Oct 19  2019 analysis.R
## drwxrwxrwx 1 aravind aravind 4.0K Jun 27  2020 bash-tutorial
## -rwxrwxrwx 1 aravind aravind  430 Oct 19  2019 bash.R
## -rwxrwxrwx 1 aravind aravind  145 Oct 19  2019 bash.Rmd
## -rwxrwxrwx 1 aravind aravind  16K Oct 22  2019 bash.sh
## -rwxrwxrwx 1 aravind aravind   35 Oct 16  2019 imports_blorr.txt
## -rwxrwxrwx 1 aravind aravind   34 Oct 16  2019 imports_olsrr.txt
## -rwxrwxrwx 1 aravind aravind  39K Oct 19  2019 lorem-ipsum.txt
## -rwxrwxrwx 1 aravind aravind 9.1K Oct 19  2019 main_project.zip
## drwxrwxrwx 1 aravind aravind 4.0K Jun 27  2020 myfiles
## drwxrwxrwx 1 aravind aravind 4.0K Oct 22  2019 mypackage
## drwxrwxrwx 1 aravind aravind 4.0K Oct 22  2019 myproject
## -rwxrwxrwx 1 aravind aravind 5.1K Jun 27  2020 myproject.zip
## drwxrwxrwx 1 aravind aravind 4.0K Jun 27  2020 myproject1
## drwxrwxrwx 1 aravind aravind 4.0K Jun 27  2020 myproject2
## drwxrwxrwx 1 aravind aravind 4.0K Oct 22  2019 myproject3
## drwxrwxrwx 1 aravind aravind 4.0K Oct 22  2019 myproject4
## -rwxrwxrwx 1 aravind aravind 1.5K Oct 19  2019 package_names.txt
## -rwxrwxrwx 1 aravind aravind 3.9K Jun 27  2020 packproj.zip
## -rwxrwxrwx 1 aravind aravind  10K Jun 27  2020 pkg_names.tar
## -rwxrwxrwx 1 aravind aravind 1.1K Oct 19  2019 pkg_names.txt
## drwxrwxrwx 1 aravind aravind 4.0K Oct 22  2019 r
## drwxrwxrwx 1 aravind aravind 4.0K Jun 20  2020 r2
## drwxrwxrwx 1 aravind aravind 4.0K Jun 27  2020 r_releases
## -rwxrwxrwx 1 aravind aravind  10K Oct 19  2019 release_names.tar
## -rwxrwxrwx 1 aravind aravind  632 Oct 19  2019 release_names.tar.gz
## -rwxrwxrwx 1 aravind aravind  546 Oct 19  2019 release_names.txt
## -rwxrwxrwx 1 aravind aravind   65 Oct 19  2019 release_names_18.txt
## -rwxrwxrwx 1 aravind aravind  118 Jun 27  2020 release_names_18_19.txt
## -rwxrwxrwx 1 aravind aravind   53 Oct 19  2019 release_names_19.txt
## -rwxrwxrwx 1 aravind aravind  383 Jun 27  2020 releases.txt.gz
## -rwxrwxrwx 1 aravind aravind  31M Oct 19  2019 sept_15.csv.gz
## -rwxrwxrwx 1 aravind aravind  157 Oct 19  2019 urls.txt
## -rwxrwxrwx 1 aravind aravind 4.3K Oct 19  2019 zip_example.zip

2.3.5 Sort list by size

ls -lS
## total 31132
## -rwxrwxrwx 1 aravind aravind 31754998 Oct 19  2019 sept_15.csv.gz
## -rwxrwxrwx 1 aravind aravind    39501 Oct 19  2019 lorem-ipsum.txt
## -rwxrwxrwx 1 aravind aravind    16242 Oct 22  2019 bash.sh
## -rwxrwxrwx 1 aravind aravind    10240 Jun 27  2020 pkg_names.tar
## -rwxrwxrwx 1 aravind aravind    10240 Oct 19  2019 release_names.tar
## -rwxrwxrwx 1 aravind aravind     9291 Oct 19  2019 main_project.zip
## -rwxrwxrwx 1 aravind aravind     5200 Jun 27  2020 myproject.zip
## -rwxrwxrwx 1 aravind aravind     4398 Oct 19  2019 zip_example.zip
## drwxrwxrwx 1 aravind aravind     4096 Jun 27  2020 bash-tutorial
## drwxrwxrwx 1 aravind aravind     4096 Jun 27  2020 myfiles
## drwxrwxrwx 1 aravind aravind     4096 Oct 22  2019 mypackage
## drwxrwxrwx 1 aravind aravind     4096 Oct 22  2019 myproject
## drwxrwxrwx 1 aravind aravind     4096 Jun 27  2020 myproject1
## drwxrwxrwx 1 aravind aravind     4096 Jun 27  2020 myproject2
## drwxrwxrwx 1 aravind aravind     4096 Oct 22  2019 myproject3
## drwxrwxrwx 1 aravind aravind     4096 Oct 22  2019 myproject4
## drwxrwxrwx 1 aravind aravind     4096 Oct 22  2019 r
## drwxrwxrwx 1 aravind aravind     4096 Jun 20  2020 r2
## drwxrwxrwx 1 aravind aravind     4096 Jun 27  2020 r_releases
## -rwxrwxrwx 1 aravind aravind     3937 Jun 27  2020 packproj.zip
## -rwxrwxrwx 1 aravind aravind     1498 Oct 19  2019 package_names.txt
## -rwxrwxrwx 1 aravind aravind     1082 Oct 19  2019 pkg_names.txt
## -rwxrwxrwx 1 aravind aravind      632 Oct 19  2019 release_names.tar.gz
## -rwxrwxrwx 1 aravind aravind      546 Oct 19  2019 release_names.txt
## -rwxrwxrwx 1 aravind aravind      430 Oct 19  2019 bash.R
## -rwxrwxrwx 1 aravind aravind      383 Jun 27  2020 releases.txt.gz
## -rwxrwxrwx 1 aravind aravind      157 Oct 19  2019 urls.txt
## -rwxrwxrwx 1 aravind aravind      145 Oct 19  2019 bash.Rmd
## -rwxrwxrwx 1 aravind aravind      118 Jun 27  2020 release_names_18_19.txt
## -rwxrwxrwx 1 aravind aravind       65 Oct 19  2019 release_names_18.txt
## -rwxrwxrwx 1 aravind aravind       53 Oct 19  2019 release_names_19.txt
## -rwxrwxrwx 1 aravind aravind       35 Oct 16  2019 imports_blorr.txt
## -rwxrwxrwx 1 aravind aravind       34 Oct 16  2019 imports_olsrr.txt
## -rwxrwxrwx 1 aravind aravind       12 Oct 19  2019 analysis.R

2.3.6 Sort list by modification date

ls -ltr
## total 31132
## -rwxrwxrwx 1 aravind aravind       35 Oct 16  2019 imports_blorr.txt
## -rwxrwxrwx 1 aravind aravind       34 Oct 16  2019 imports_olsrr.txt
## -rwxrwxrwx 1 aravind aravind      145 Oct 19  2019 bash.Rmd
## -rwxrwxrwx 1 aravind aravind       12 Oct 19  2019 analysis.R
## -rwxrwxrwx 1 aravind aravind    39501 Oct 19  2019 lorem-ipsum.txt
## -rwxrwxrwx 1 aravind aravind      430 Oct 19  2019 bash.R
## -rwxrwxrwx 1 aravind aravind      546 Oct 19  2019 release_names.txt
## -rwxrwxrwx 1 aravind aravind    10240 Oct 19  2019 release_names.tar
## -rwxrwxrwx 1 aravind aravind     4398 Oct 19  2019 zip_example.zip
## -rwxrwxrwx 1 aravind aravind     9291 Oct 19  2019 main_project.zip
## -rwxrwxrwx 1 aravind aravind      632 Oct 19  2019 release_names.tar.gz
## -rwxrwxrwx 1 aravind aravind      157 Oct 19  2019 urls.txt
## -rwxrwxrwx 1 aravind aravind       53 Oct 19  2019 release_names_19.txt
## -rwxrwxrwx 1 aravind aravind       65 Oct 19  2019 release_names_18.txt
## -rwxrwxrwx 1 aravind aravind     1498 Oct 19  2019 package_names.txt
## -rwxrwxrwx 1 aravind aravind     1082 Oct 19  2019 pkg_names.txt
## -rwxrwxrwx 1 aravind aravind 31754998 Oct 19  2019 sept_15.csv.gz
## -rwxrwxrwx 1 aravind aravind    16242 Oct 22  2019 bash.sh
## drwxrwxrwx 1 aravind aravind     4096 Oct 22  2019 r
## drwxrwxrwx 1 aravind aravind     4096 Oct 22  2019 myproject3
## drwxrwxrwx 1 aravind aravind     4096 Oct 22  2019 mypackage
## drwxrwxrwx 1 aravind aravind     4096 Oct 22  2019 myproject
## drwxrwxrwx 1 aravind aravind     4096 Oct 22  2019 myproject4
## drwxrwxrwx 1 aravind aravind     4096 Jun 20  2020 r2
## drwxrwxrwx 1 aravind aravind     4096 Jun 27  2020 r_releases
## -rwxrwxrwx 1 aravind aravind      118 Jun 27  2020 release_names_18_19.txt
## -rwxrwxrwx 1 aravind aravind    10240 Jun 27  2020 pkg_names.tar
## -rwxrwxrwx 1 aravind aravind      383 Jun 27  2020 releases.txt.gz
## -rwxrwxrwx 1 aravind aravind     3937 Jun 27  2020 packproj.zip
## -rwxrwxrwx 1 aravind aravind     5200 Jun 27  2020 myproject.zip
## drwxrwxrwx 1 aravind aravind     4096 Jun 27  2020 bash-tutorial
## drwxrwxrwx 1 aravind aravind     4096 Jun 27  2020 myfiles
## drwxrwxrwx 1 aravind aravind     4096 Jun 27  2020 myproject1
## drwxrwxrwx 1 aravind aravind     4096 Jun 27  2020 myproject2

2.4 R Functions

In R, getwd() will return the current working directory. You can use here() from the here package as well. To change the current working directory, use setwd(). The fs package provides useful functions for file operations.

Command R
pwd getwd() / here::here()
ls dir() / list.files() / list.dirs() / fs::dir_ls() / dir_info()
cd setwd()
mkdir dir.create() / fs::dir_create()
rmdir fs::dir_delete()