Linux Commands Cheat Sheet
Linux Commands Cheat Sheet
Linux, often associated with being a complex operating system primarily used by developers,
may not necessarily fit that description entirely. While it can initially appear challenging for
beginners, once you immerse yourself in the Linux world, you may find it difficult to return
to your previous Windows systems. The power of Linux commands in controlling your PC,
coupled with their clean user interface, can make it hard to switch back to older operating
systems. If you're a developer, you can likely relate to the advantages and appeal of Linux.
To support developers and beginners alike, we have created a comprehensive Linux/Unix
command line cheat sheet. This cheat sheet covers all the basic and advanced commands,
including file and directory commands, file permission commands, file compression and
archiving, process management, system information, networking, and more with proper
examples and descriptions. In addition to that we provide all the most used Linux Shortcut
which includes Bash shortcuts, Nano shortcuts, VI & Vim Shortcuts Commands. It provides a
solid foundation on Linux OS commands, as well as insights into practical applications.
By the end of this cheat sheet, you will have a basic understanding of Linux/Unix Commands
and how it makes development easy for developers.
ls -l
-l: Long format displays files and
listing. directories with detailed
-a: Include information.
List files and hidden files ls -a
directories. hidden ones shows all files and
-h: Human- directories, including
readable file ls -lh
sizes. displays file sizes in a
ls human-readable format.
cd /path/to/directory
changes the current
Change directory.
directory to the specified
cd path.
pwd
Print current
displays the current
working directory.
pwd working directory.
mkdir my_directory
Create a new
creates a new directory
directory.
mkdir named "my_directory".
Command Description Options Examples
rm file.txt
deletes the file named
"file.txt".
-r: Remove
rm -r my_directory
directories
deletes the directory
Remove files and recursively.
"my_directory" and its
directories. -f: Force removal
contents.
without
rm -f file.txt
confirmation.
forcefully deletes the file
"file.txt" without
rm confirmation.
cp -r directory
destination
copies the directory
-r: Copy
Copy files and "directory" and its contents
directories
directories. to the specified destination.
recursively.
cp file.txt destination
copies the file "file.txt" to
cp the specified destination.
mv file.txt new_name.txt
renames the file "file.txt"
Move/rename files to "new_name.txt".
and directories. mv file.txt directory
moves the file "file.txt" to
mv the specified directory.
cat file.txt
View the contents
displays the contents of the
of a file.
cat file "file.txt".
head file.txt
shows the first 10 lines of
-n: Specify the
Display the first the file "file.txt".
number of lines
few lines of a file. head -n 5 file.txt
to display.
displays the first 5 lines of
head the file "file.txt".
Command Description Options Examples
tail file.txt
shows the last 10 lines of
-n: Specify the
Display the last the file "file.txt".
number of lines
few lines of a file. tail -n 5 file.txt
to display.
displays the last 5 lines of
tail the file "file.txt".
ln -s source_file
-s: Create link_name
Create links
symbolic (soft) creates a symbolic link
between files.
links. named "link_name"
ln pointing to "source_file".
find /path/to/search -
-name: Search by
name "*.txt"
Search for files filename.
searches for all files with
and directories. -type: Search by
the extension ".txt" in the
file type.
find specified directory.
u: User/owner
permissions.
g: Group
permissions.
o: Other
chmod u+rwx file.txt
permissions.
Change file grants read, write, and execute
+: Add
permissions. permissions to the owner of the
permissions.
file.
-: Remove
permissions.
=: Set
permissions
chmod explicitly.
umask 022
sets the default file permissions
Set default file
to read and write for the
permissions.
owner, and read-only for group
umask and others.
gzip file.txt
-d: Decompress
Compress files. compresses the file "file.txt"
files.
gzip and renames it as "file.txt.gz".
ps aux
shows all running
Display running -aux: Show all
processes with
processes. processes.
detailed information.
ps
top
displays a dynamic
Monitor system
view of system
processes in real-time.
processes and their
top resource usage.
kill PID
-9: Forcefully kill terminates the process
Terminate a process.
a process. with the specified
kill process ID.
pkill process_name
Terminate processes terminates all
based on their name. processes with the
pkill specified name.
pgrep process_name
List processes based lists all processes with
on their name. the specified name.
pgrep
numbers
alongside
matching lines.
-w: Match whole
words only,
rather than partial
matches.
-c: Count the
number of
matching lines
instead of
displaying them.
-e: Specify
multiple patterns
to search for.
-A: Display lines
after the
matching line.
-B: Display lines
before the
matching line.
-C: Display lines
both before and
after the
matching line.
uname -a
Print system -a: All system
displays all system
information. information.
uname information.
whoami
Display current
shows the current
username.
whoami username.
df -h
Show disk space -h: Human- displays disk space
usage. readable sizes. usage in a human-
df readable format.
sudCommand Description Options Examples
-h: Human-
du -sh directory/
Estimate file and readable sizes.
provides the total size of
directory sizes. -s: Display total
the specified directory.
du size only.
free -h
Display memory -h: Human- displays memory usage
usage information. readable sizes. in a human-readable
free format.
uptime
Show system
shows the current
uptime.
uptime system uptime.
lscpu
Display CPU provides detailed CPU
information. information.
lscpu
lspci
List PCI devices.
lspci List PCI devices.
lsusb
lists all connected USB
List USB devices.
devices.
lsusb
6. Networking Commands
In Linux, there are several networking commands available to manage and troubleshoot
network connections. Here are some commonly used networking commands:
Command Description Examples
ping google.com
Send ICMP echo
sends ICMP echo requests to "google.com" to
requests to a host.
ping check connectivity.
Display network
netstat -tuln
connections and
shows all listening TCP and UDP connections.
netstat statistics.
Command Description Examples
ss -tuln
Display network
shows all listening TCP and UDP connections.
socket information.
ss
ssh user@hostname
Securely connect to a
initiates an SSH connection to the specified
remote server.
ssh hostname.
scp file.txt
Securely copy files user@hostname:/path/to/destination
between hosts. securely copies "file.txt" to the specified remote
scp host.
curl http://example.com
Transfer data to or
retrieves the content of a webpage from the
from a server.
curl specified URL.
7. IO Redirection Commands
In Linux, IO (Input/Output) redirection commands are used to redirect the standard input,
output, and error streams of commands and processes. Here are some commonly used IO
redirection commands:
Command Description
cmd1 <(cmd2) Output of cmd2 is used as the input file for cmd1.
cmd >
Discards the stdout of cmd by sending it to the null device.
/dev/null
export
Sets the value of an environment variable.
VARIABLE_NAME=value
sudo usermod -a -G Add an existing user to the specified group. The user is
GROUPNAME added to the group without removing them from their
USERNAME current groups.
Cut/delete from
Search
Move to the the cursor
Ctrl + Ctrl + command
Ctrl + A beginning of position to the
U R history (reverse
the line. beginning of the
search).
line.
Go to the
Cut/delete the
Move back Ctrl + Ctrl + previous
Ctrl + B word before the
one character. W P command in
cursor.
history.
Go to the next
Move forward Ctrl + Paste the last cut Ctrl +
Ctrl + F command in
one character. Y text. N
history.
Terminate the
Move back Ctrl + Ctrl +
Alt + B Clear the screen. current
one word L C
command.
Move forward
Alt + F
one word.
Cut/delete
from the
Search
cursor
Ctrl + Save the Scroll up Ctrl Ctrl + for a
Ctrl + Y position
O file. one page. +K W string in
to the end
the text.
of the
line.
Exit
Search
Nano Uncut/
Scroll and
Ctrl + (prompt Ctrl restore the Alt +
Ctrl + V down replace a
X to save if +U last cut W
one page. string in
modified text.
the text.
).
buffer. or cutting.
Go to
Justify Cut/delete
the
the the
Ctrl + beginnin Ctrl
current Alt + , marked
J g of the +K
paragrap block of
current
h. text.
line.
Go to the
Copy the
end of
Alt + marked
Alt + . the
6 block of
current
text.
line.
Command Description
Change the current word. Deletes from the cursor position to the end of the
cw
current word and switches to insert mode.
Enter replace mode. Overwrites characters starting from the cursor position
R
until you press the Escape key.
o Insert a new line below the current line and switch to insert mode.
s Substitute the character under the cursor and switch to insert mode.
dw Delete from the cursor position to the beginning of the next word.
4dw Delete the next four words from the cursor position.
Replace the character under the cursor with a new character entered from the
r
keyboard.
3dd Delete the current line and the two lines below it.
ESC Exit from insert or command-line mode and return to command mode.
U Restore the current line to its original state before any changes were made.
Delete from the cursor position to the end of the line and switch to insert
C
mode.
Enter insert
Enter visual
mode at the
i :w Save the file. v mode to
current cursor
select text.
position.
Delete the
Copy the
x character under :q Quit Vim. y
selected text.
the cursor.
Quit Vim
Delete the Delete the
dd :q! without saving d
current line. selected text.
changes.
Replace all
Paste the copied
occurrences of
or deleted text
p :s/old/new/g "old" with
below the
"new" in the
current line.
file.
:set nu
Undo the last Display line
u or
change. numbers.
:set number
Conclusion
In conclusion, Linux is a widely used operating system for development, and as a developer,
you should have knowledge of Linux and its basic commands. In this Cheat Sheet, we
covered all commands like creating directories, file compression and archiving, process
management, system information, networking and more. In addition to that, this Linux Cheat
Sheet is organized and categorized, making it easy for developers to quickly find the
commands they need for specific use cases. By utilizing this resource, developers can
enhance their productivity and efficiency in working with Linux, leading to smoother and
more successful development projects.
PS. Don't miss our other Python cheat sheet for data science that covers Scikit-
Learn, Bokeh, Pandas and Python basics.
Comment
More info
Advertise with us
Next Article
Pandas Cheat Sheet for Data Science in Python
Similar Reads
Geeksforgeeks Cheatsheets - All Coding Cheat Sheets Collections
Cheatsheets are short documents that contain all the most essential information about a
specific technology in short, such as its syntax, commands, functions, or its features. Sheets
are designed to help users to learn quickly and these Sheets are given the basics Overview of
the technology without
4 min read
C++ Cheatsheet
This is a C++ programming cheat sheet. It is useful for beginners and intermediates looking
to learn or revise the concepts of C++ programming. While learning a new language, it feels
annoying to switch pages and find different websites for different concepts that are easily
understandable. You can
15 min read