Bash & ZSH Shell Terminal Basics Cheat Sheet - DataCamp
Bash & ZSH Shell Terminal Basics Cheat Sheet - DataCamp
Sale ends in
�d ��h ��m ��s
EN
C H E AT S H E E T S Category
Richie Cotton
Webinar & podcast host, course and book author, spends all day chit-chatting about data
TO P I C S
Data Science
1 of 17 2/12/24, 2:38
Bash & zsh Shell Terminal Basics Cheat Sheet | DataCamp https://www.datacamp.com/cheat-sheet/bash-and-zsh-s...
Download PDF
Definitions
The working directory is the directory that commands are executed from. By default,
commands will read and write files to this directory.
The root directory is the top of the file system. All other directories are contained within
the hierarchy of this directory.
An absolute path starts from the root directory. Think of it like latitude and longitude -
the values to a location don't change wherever you are.
A relative path starts from the working directory. Think of it like directions from where
you are, like "20 kilometers West from here".
A regular expression is a more complex way of specifying text fragments. Learn more
in DataCamp's Regular Expressions Cheat Sheet.
Getting Help
Display the manual for a command with man
2 of 17 2/12/24, 2:38
Bash & zsh Shell Terminal Basics Cheat Sheet | DataCamp https://www.datacamp.com/cheat-sheet/bash-and-zsh-s...
man head
POWERED BY
pwd
POWERED BY
POWERED BY
cd /home
POWERED BY
cd ./images
POWERED BY
POWERED BY
3 of 17 2/12/24, 2:38
Bash & zsh Shell Terminal Basics Cheat Sheet | DataCamp https://www.datacamp.com/cheat-sheet/bash-and-zsh-s...
ls
POWERED BY
List all files and folders, including hidden ones (names starting .) with ls -a
ls -a
POWERED BY
ls -lh
POWERED BY
POWERED BY
Recursively list all files below the current working directory with ls -R
ls -R
POWERED BY
List estimated disk usage of files and folders in a human-readable format with du -ah
du -ah
POWERED BY
Find files by name in the current directory & its subdirectories with find . -type f -name
4 of 17 2/12/24, 2:38
Bash & zsh Shell Terminal Basics Cheat Sheet | DataCamp https://www.datacamp.com/cheat-sheet/bash-and-zsh-s...
pattern
POWERED BY
Displaying Files
Display the whole file with cat
cat README.txt
POWERED BY
less README.txt
POWERED BY
POWERED BY
POWERED BY
5 of 17 2/12/24, 2:38
Bash & zsh Shell Terminal Basics Cheat Sheet | DataCamp https://www.datacamp.com/cheat-sheet/bash-and-zsh-s...
POWERED BY
Display the lines of a file containing text matching a regular expression with grep
POWERED BY
Display the names of files with filenames containing text matching a regular expression
with grep -r
POWERED BY
wc README.txt
POWERED BY
POWERED BY
POWERED BY
6 of 17 2/12/24, 2:38
Bash & zsh Shell Terminal Basics Cheat Sheet | DataCamp https://www.datacamp.com/cheat-sheet/bash-and-zsh-s...
POWERED BY
mv sales.csv sales-2023.csv
POWERED BY
POWERED BY
POWERED BY
rm bad_data.json
POWERED BY
rmdir temp_results
POWERED BY
7 of 17 2/12/24, 2:38
Bash & zsh Shell Terminal Basics Cheat Sheet | DataCamp https://www.datacamp.com/cheat-sheet/bash-and-zsh-s...
Combining commands
Redirect the output from a command to a file with >
POWERED BY
POWERED BY
POWERED BY
Glob Patterns
Match one or more character with *
POWERED BY
POWERED BY
8 of 17 2/12/24, 2:38
Bash & zsh Shell Terminal Basics Cheat Sheet | DataCamp https://www.datacamp.com/cheat-sheet/bash-and-zsh-s...
POWERED BY
POWERED BY
sort random_order.txt
POWERED BY
sort -r random_order.txt
POWERED BY
Combine cut and sort using a pipe to sort a column of a CSV file
cut -d , -f 2 | sort
POWERED BY
uniq sales.csv
POWERED BY
9 of 17 2/12/24, 2:38
Bash & zsh Shell Terminal Basics Cheat Sheet | DataCamp https://www.datacamp.com/cheat-sheet/bash-and-zsh-s...
uniq -c sales.csv
POWERED BY
POWERED BY
Variables
List all environment variables with set
set
POWERED BY
mydata=sales.csv
POWERED BY
pyfiles=$(ls *.py)
POWERED BY
10 of 17 2/12/24, 2:38
Bash & zsh Shell Terminal Basics Cheat Sheet | DataCamp https://www.datacamp.com/cheat-sheet/bash-and-zsh-s...
echo $HOME
POWERED BY
export mydata
POWERED BY
datafiles=*.csv
for file in datafiles; do echo $file; done
POWERED BY
datafiles=*.csv
for file in datafiles
do
echo $file
done
POWERED BY
11 of 17 2/12/24, 2:38
Bash & zsh Shell Terminal Basics Cheat Sheet | DataCamp https://www.datacamp.com/cheat-sheet/bash-and-zsh-s...
x=99;
if [ $x > 50 ] ; then
echo "too high";
elif [ $x < 50 ] ; then
echo "too low";
else
echo "spot on";
fi
POWERED BY
Reusing Commands
See your previous commands with history
history
POWERED BY
Save commands in a shell file (extension .sh) and run them with bash or zsh
bash mycommands.sh
zsh mycommands.sh
POWERED BY
AUTHOR
Richie Cotton
Richie helps individuals and organizations get better at using data and AI. He's been a
data scientist since before it was called data science, and has written two books and
created many DataCamp courses on the subject. He is a host of the DataFramed
podcast, and runs DataCamp's webinar program.
TO P I C S
Data Science
12 of 17 2/12/24, 2:38
Bash & zsh Shell Terminal Basics Cheat Sheet | DataCamp https://www.datacamp.com/cheat-sheet/bash-and-zsh-s...
Related
C H E AT- S H E E T
C H E AT- S H E E T
C H E AT- S H E E T
See More
LEARN
Learn Python
Learn R
Learn AI
Learn SQL
Learn Power BI
13 of 17 2/12/24, 2:38
Bash & zsh Shell Terminal Basics Cheat Sheet | DataCamp https://www.datacamp.com/cheat-sheet/bash-and-zsh-s...
Learn Tableau
Assessments
Career Tracks
Skill Tracks
Courses
DATA C O U R S E S
Python Courses
R Courses
SQL Courses
Power BI Courses
Tableau Courses
Alteryx Courses
Azure Courses
AI Courses
DATA L A B
14 of 17 2/12/24, 2:38
Bash & zsh Shell Terminal Basics Cheat Sheet | DataCamp https://www.datacamp.com/cheat-sheet/bash-and-zsh-s...
Get Started
Pricing
Security
Documentation
C E R T I F I C AT I O N
Certifications
Data Scientist
Data Analyst
Data Engineer
SQL Associate
Azure Fundamentals
AI Fundamentals
RESOURCES
Resource Center
Upcoming Events
Blog
Code-Alongs
Tutorials
Docs
Open Source
RDocumentation
15 of 17 2/12/24, 2:38
Bash & zsh Shell Terminal Basics Cheat Sheet | DataCamp https://www.datacamp.com/cheat-sheet/bash-and-zsh-s...
Course Editor
Data Portfolio
Portfolio Leaderboard
PLANS
Pricing
For Business
For Universities
DataCamp Donates
FO R B U S I N E S S
Business Pricing
Teams Plan
Customer Stories
Partner Program
ABOUT
About Us
Learner Stories
Careers
Become an Instructor
Press
Leadership
16 of 17 2/12/24, 2:38
Bash & zsh Shell Terminal Basics Cheat Sheet | DataCamp https://www.datacamp.com/cheat-sheet/bash-and-zsh-s...
Contact Us
DataCamp Español
DataCamp Português
DataCamp Deutsch
DataCamp Français
S U P PO R T
Help Center
Become an Affiliate
Privacy Policy Cookie Notice Do Not Sell My Personal Information Accessibility Security
Terms of Use
17 of 17 2/12/24, 2:38