Command Line Basics for R Users

A gentle introduction to the command line.
Author

Aravind Hebbali

Published

September 29, 2026

Welcome

Figure 1: Cover image: Command Line Basics for R Users

This is the website for Command Line Basics for R Users. Visit the GitHub repository for this site.

Creative Commons License
This work by Aravind Hebbali is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Preface

In this book, you will be introduced to shell commands. We have selected a set of commands we think will be useful in general to a wide range of audience. We have created a Posit Cloud project to ensure that all readers are using the same environment while using code examples. Our goal is to ensure that after reading this book, you should be able to use the shell for version control, managing cloud services (like deploying your own shiny server etc.), execute commands in R & RMarkdown and execute R scripts in the shell. Apart from learning shell commands, the book will also focus on

  • exploring R release names
  • mapping shell commands to R functions
  • RStudio Terminal
  • executing shell commands from R using system2() or processx::run()
  • execute shell commands in RMarkdown
  • execute R scripts in the shell

If you want a deeper understanding of using command line for data science, we suggest you read Data Science at the Command Line. Software Carpentry too has a lesson on shell. We have listed more references at the end of the book for the benefit of the readers.

Outline

We start by introducing what the shell is, how to launch it in different operating system and explore commands for navigating file system and file management.

  • Introduction introduces the shell. It shows how to launch it in different operating systems. Apart from introducing the RStudio terminal, it will explore basic commands and different ways to view the documentation.

  • Navigating File System explores how to navigate between different directories, list contents of a directory and create & delete files & directories.

  • File Management describes how to create, copy, move, delete and compare files and directories.

  • Input/Output demonstrates how to print text on the terminal and read content from files. It will cover sorting/viewing/searching file contents.

  • Search & Regular Expression shows how to search text in file(s) using pattern matching and find files and folders using names and extensions.

  • sudo describes how to install, update and remove packages using sudo.

  • Data Transfer explores how to download files from the internet using wget and curl.

  • File Compression demonstrates how to list, extract, create and add files to archives using tar, zip and unzip.

  • System Info explains how to view system information using uname, free, df etc.

  • R & the Shell demonstrates how to execute shell commands in R using system2(). It will also look at using shell commands in RMarkdown documents and how to execute R commands and scripts from the command line.

  • Pipes & Redirection chains commands with |, streams data without loading it into R, and maps the shell pipe to R’s |>.

Topics this book does not cover

While the book explores several shell commands and demonstrates how to execute them in R, it does not cover the following topics:

  • shell scripting
  • editing files
  • file permissions
  • user information
  • awk
  • sed

About this book

This book is focused on practical exploration of shell commands. We focus on a select set of commands we hope will be useful to beginners and motivate them to explore the command line further.

We do not assume any previous knowledge of command line. We have used the RStudio terminal and RStudio Cloud to remove any hurdles for beginners and to ensure all learners have access to the same environment to explore the commands.

We do assume the reader is familiar with R and RStudio.

Using code examples

All the codes used in this book are available in our GitHub repository. We encourage you to use Posit Cloud (it is free), especially Windows users as you will get access to Linux Bash and all the code and files/directories used in the examples.

Software information

The R session information when compiling this book is shown below:

sessionInfo()
R version 4.4.2 (2024-10-31)
Platform: x86_64-pc-linux-gnu
Running under: Ubuntu 24.04.5 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3 
LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.26.so;  LAPACK version 3.12.0

locale:
 [1] LC_CTYPE=C.UTF-8       LC_NUMERIC=C           LC_TIME=C.UTF-8       
 [4] LC_COLLATE=C.UTF-8     LC_MONETARY=C.UTF-8    LC_MESSAGES=C.UTF-8   
 [7] LC_PAPER=C.UTF-8       LC_NAME=C              LC_ADDRESS=C          
[10] LC_TELEPHONE=C         LC_MEASUREMENT=C.UTF-8 LC_IDENTIFICATION=C   

time zone: UTC
tzcode source: system (glibc)

attached base packages:
[1] stats     graphics  grDevices datasets  utils     methods   base     

loaded via a namespace (and not attached):
 [1] compiler_4.4.2  fastmap_1.2.0   cli_3.6.6       htmltools_0.5.9
 [5] tools_4.4.2     yaml_2.3.12     rmarkdown_2.32  knitr_1.52     
 [9] jsonlite_2.0.0  xfun_0.61       digest_0.6.39   rlang_1.3.0    
[13] renv_1.2.4      evaluate_1.0.5