Bash Cheatsheet
Bash Cheatsheet
Introduction to Bash
Bourne Again SHell (Bash Shell) is a Unix shell and command language that is the default login
shell for the majority of Linux distributions.
The Bash Shell is the most widely used command-line interface (CLI) available.
touch
The touch command is used to create new files. $ touch new_file.txt
mkdir
The mkdir command is used to create new directories. $ mkdir new_folder
grep
The grep command is used to search text for patterns specified $ grep “educative” file.txt
by the user.
$ Educative is an e-learning
grep [option(s)] pattern [file(s)]
platform
Common options: -i, -c, -n
rmdir
$ ls
The rmdir command will remove empty directories.
$ folder_01 folder_02
rmdir [option(s)] directory_name (s)
$ rmdir folder_01
Common options: -p
$ ls
$ folder_02
cp
$ ls
The cp command is used to copy files and directories. $ file.txt
cp [option(s)] old_path new_path
$ cp file.txt copy_file.txt
Common options: -r, -i, -b
$ ls
$ file.txt copy_file.txt
Bash Cheat Sheet: Top 35 Commands
mv $ ls folder_01
$ ls folder_02
$ code.py
rm $ ls folder_01
$ file.txt
find
$ ls folder_01
The find command is used for locating files within a directory
hierarchy. $ file.txt code.py
less
The less command allows you to view files without opening an $ less file.txt
editor, one page at a time.
$ Educative is an e-learning
less [option(s)] file_name platform...
head
The head command displays the first 10 lines of a file. $ head file.txt
head [option(s)] file(s) $ Educative is an e-learning
platform
Common options: -n
It has courses for developers
created by industry experts.
...
Bash Cheat Sheet: Top 35 Commands
tail
$ tail file.txt
The tail command displays the last 10 lines of a file. $ They specialize in System
tail [option(s)] file(s) Design, GenAI, OOD, Coding
Interview prep, and Machine
Common options: -n Learning courses.
...
>
$ ls > new_file.txt
The > command takes the output from the preceding command
that you’d normally see in the terminal and sends it to a file that you $ cat new_file.txt
give it.
$ file.txt code.py
command > output
pwd $ ~/user/Desktop
cd $ pwd
The cd command moves between directories. $ ~/user/Desktop
cd [directory] $ cd folder_01
$ pwd
$ ~/user/Desktop/folder_01
compgen
$ compgen -c
The compgen command displays a list of all possible commands
$ ls
and functions.
echo
compgen [option(s)] clear
exit
Common options: -a, -c, -d ...
history
$ history
The history command displays previously used commands.
$ compgen -c
history [option(s)] pwd
cd folder_01
Common options: -c, -d pwd
...
clear
The clear command clears the terminal display for a fresh view. $ clear
clear $
exit
The exit command closes a terminal or ends an SSH session.
$ exit
exit
(closed)
Common options: None
Bash Cheat Sheet: Top 35 Commands
whoami
$ whoami
The whoami command shows the username of the current user.
$ educative_cheatsheets
whoami
date
$ date
The date command shows the system date and time.
$ thu Oct 31 16:49:29 US 2024
date [option(s)]
Common options: -d
uname
$ uname
The uname command provides details about the system, such as
kernel name and version. $ Drawin
uname [option(s)]
df
$ df
The df command shows available disk space on filesystems.
$ Filesystem Used Available...
df [option(s)]
/dev/disk 80% 20%
Common options: -h, -i, -T
...
Process Management
ps
$ ps
The ps command shows active processes.
$ PID TTY TIME ...
ps [option(s)]
2411 ttys0 24:11:20
Common options: -aux
sleep
$ sleep 1
The sleep command pauses execution for a specified time
(default is seconds). (delay for 1 second)
$
sleep duration
kill
$ ps
The kill command ends processes by ID. Use ps to find the PID first. $ PID TTY TIME ...
File Searching
locate
The locate command searches for files by name. $ locate “*.py”
Permissions
chmod
The chmod command changes the access flags for files and directories. $ chmod 777 code.py
stat
The stat command shows detailed information about files, including $ stat code.py
ownership, permissions, and timestamps. $ ... -rwxrwxrwx ...
stat file_name
$ man echo
$ ECHO (1) Generall Commands
man Manual Echo (1)
NAME
The man command provides detailed information on commands.
echo - write arguments to
man [command]
the standard output
Common options: -w, -f, -b
SYNOPSIS
echo [-] [string ...]
...
Bash Cheat Sheet: Top 35 Commands
| (Pipe symbol)
$ cat code.py | head
The pipe symbol (|) connects the output of one command to the
input of another. $ #import time
alias
$ alias listfiles=”ls”
The alias command defines shortcuts for commands or groups of
commands. $ listfiles