0% found this document useful (0 votes)
9 views6 pages

Bash Cheatsheet

The document is a Bash cheat sheet that outlines the top 35 commands used in the Bash shell, which is the default command-line interface for most Linux distributions. It includes commands for file and directory manipulation, file content display, system information, process management, file searching, permissions, and other useful commands. Each command is accompanied by a brief description and common options, making it a handy reference for users looking to enhance their command-line skills.

Uploaded by

vb_pol@yahoo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views6 pages

Bash Cheatsheet

The document is a Bash cheat sheet that outlines the top 35 commands used in the Bash shell, which is the default command-line interface for most Linux distributions. It includes commands for file and directory manipulation, file content display, system information, process management, file searching, permissions, and other useful commands. Each command is accompanied by a brief description and common options, making it a handy reference for users looking to enhance their command-line skills.

Uploaded by

vb_pol@yahoo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Bash Cheat Sheet: Top 35 Commands

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.

The Top 35 Bash Commands


Note: Anything encased in [ ] means that it’s optional. Some commands can be used without options or specifying files.

File and Directory Manipulation


ls
The ls command allows you to view all files within the specified
$ ls
directory.
$ file.txt code.py folder_01
ls [option(s)] [file(s)]
Common options: -a, -l

touch
The touch command is used to create new files. $ touch new_file.txt

touch [option(s)] file_name(s) $ ls

Common options: -a, -m, -r, -d $ new_file.txt

mkdir
The mkdir command is used to create new directories. $ mkdir new_folder

mkdir [option(s)] directory_name(s) $ ls

Common options: -m, -p, -v $ 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

The mv command is used to move or rename directories. $ file.txt code.py

mv [option(s)] old_path new_path $ mv folder_01/code.py

Common options: -i, -b folder_02/code.py

$ ls folder_02

$ code.py

rm $ ls folder_01

The rm command is used to remove files or directories. $ file.txt code.py


rm [option(s)] file(s)/directory(ies) $ rm folder_01/code.py

Common options: -f, -i, -r $ 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

find [option(s)] path [expression] $ find folder_01 “*.py”

Common options: -name, -size, -mtime $ code.py

File Content Display and Manipulation


cat
The cat command is used to display files, combine copies of them, $ ls folder_01
and create new ones. $ file.txt code.py
cat [option(s)] [file_name(s)] [-] [file_name(s)] $ find folder_01 “*.py”
Common options: -n $ 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...

Common options: -e, -f, -n

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

System Information and Control


pwd
The pwd command displays the current directory you’re in. $ pwd

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)]

Common options: -a, -r, -m

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 ...

kill [signal] PID (s) 2411 ttys0 24:11:20


...
Common options: -p
$ kill 2411
$
Bash Cheat Sheet: Top 35 Commands
top
The top command lists active processes and their resource usage $ top
in real time. $ PID COMMAND %CPU ...
top [option(s)] 2411 vscode 24.0
...
Common options: -u, -p, -n

File Searching
locate
The locate command searches for files by name. $ locate “*.py”

locate [option(s)] pattern $ ~/user/Desktop/code.py


~/user/Documents/file.py
Common options: -q, -n, -i
...

Permissions
chmod
The chmod command changes the access flags for files and directories. $ chmod 777 code.py

chmod [option(s)] permissions file_name $

Common options: -f, -v

stat
The stat command shows detailed information about files, including $ stat code.py
ownership, permissions, and timestamps. $ ... -rwxrwxrwx ...
stat file_name

Common options: -f, -v

Other Useful Commands


echo
The echo command outputs text or variables. $ echo “www.educative.io”

chmod [option(s)] [string(s)] $ www.educative.io

Common options: -e, -n

$ 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

command1 | command2 [| ...] def (func):


...

alias
$ alias listfiles=”ls”
The alias command defines shortcuts for commands or groups of
commands. $ listfiles

alias name=”command” $ code.py file.txt folder_01

Operating System Courses


To learn more about Linux, you can take help from the following resources:

• Master the Bash Shell

• Operating Systems: Virtualization Concurrency & Persistence

• Bash for Programmers

You might also like