0% found this document useful (0 votes)
0 views17 pages

Linux Commands Cheat Sheet

The document is a comprehensive Linux Commands Cheat Sheet aimed at both beginners and experienced developers, covering basic to advanced commands for file operations, permissions, process management, system information, and networking. It includes examples and descriptions for each command, as well as shortcuts for various text editors. By using this cheat sheet, users can gain a solid understanding of Linux commands and their practical applications.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views17 pages

Linux Commands Cheat Sheet

The document is a comprehensive Linux Commands Cheat Sheet aimed at both beginners and experienced developers, covering basic to advanced commands for file operations, permissions, process management, system information, and networking. It includes examples and descriptions for each command, as well as shortcuts for various text editors. By using this cheat sheet, users can gain a solid understanding of Linux commands and their practical applications.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 17

Linux Commands Cheat Sheet

Last Updated : 02 Aug, 2024



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.

Linux Commands Cheat Sheet


What is Linux?
Linux is an open-source UNIX-like operating system (OS). An operating system is a software
that directly manages a system’s hardware and resources, like CPU, memory, and storage. OS
acts as a GUI through which user can communicate with the computer. The OS sits between
applications and hardware and makes the connections between all of your software and the
physical resources that do the work.
Linux Commands List - Table of Content
 File and Directory Operations Commands
 File Permission Commands
 File Compression and Archiving Commands
 Process Management Commands
 System Information Commands
 Networking Commands
 IO Redirection Commands
 Environment Variable Commands
 User Management Commands
 Shortcuts Commands List
o Bash Shortcuts Commands
o Nano Shortcuts Commands
o VI Shortcuts Commands
o Vim Shortcuts Commands
 FAQs on Linux Commands Cheat Sheet
Basic Linux Commands with Examples
In this Linux cheat sheet, we will cover all the most important Linux commands, from the
basics to the advanced. We will also provide some tips on how to practice and learn Linux
commands. This cheat sheet is useful for Beginners and Experience professionals.
1. File and Directory Operations Commands
File and directory operations are fundamental in working with the Linux operating system.
Here are some commonly used File and Directory Operations commands:
Command Description Options Examples

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

Create an empty  touch file.txt


file or update file creates an empty file
touch timestamps. named "file.txt".

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

2. File Permission Commands


File permissions on Linux and Unix systems control access to files and directories. There are
three basic permissions: read, write, and execute. Each permission can be granted or denied
to three different categories of users: the owner of the file, the members of the file's group,
and everyone else.
Here are some file permission commands:
Command Description Options Examples

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

 chown user file.txt


Change file
changes the owner of "file.txt"
ownership.
chown to the specified user.
Command Description Options Examples

 chgrp group file.txt


Change group changes the group ownership
ownership. of "file.txt" to the specified
chgrp group.

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

3. File Compression and Archiving Commands


Here are some file compression and archiving commands in Linux:
Commands Description Options Examples

 -c: Create a new


archive.
 -x: Extract files
from an archive.
 -f: Specify the
archive file  tar -czvf archive.tar.gz files/
Create or name. creates a compressed tar
extract archive  -v: Verbose archive named
files. mode. "archive.tar.gz" containing the
 -z: Compress files in the "files/" directory.
the archive with
gzip.
 -j: Compress the
archive with
tar bzip2.

 gzip file.txt
 -d: Decompress
Compress files. compresses the file "file.txt"
files.
gzip and renames it as "file.txt.gz".

 zip archive.zip file1.txt


Create  -r: Recursively file2.txt
compressed zip include creates a zip archive named
archives. directories. "archive.zip" containing
zip "file1.txt" and "file2.txt".

4. Process Management Commands


In Linux, process management commands allow you to monitor and control running
processes on the system. Here are some commonly used process management commands:
Commands Description Options Examples

 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

grep used to search for  -i: Ignore case  grep -i "hello"


specific patterns or distinctions while file.txt
regular expressions in searching.  grep -v "error"
text files or streams  -v: Invert the file.txt
and display matching match, displaying  grep -r "pattern"
lines. non-matching directory/
lines.  grep -l "keyword"
 -r or -R: file.txt
Recursively  grep -n "pattern"
search directories file.txt
for matching In these examples we
patterns. are extracting our
 -l: Print only the desirec output from
names of files filename (file.txt)
containing
matches.
 -n: Display line
Commands Description Options Examples

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.

5. System Information Commands


In Linux, there are several commands available to gather system information. Here are some
commonly used system information commands:
sudCommand Description Options Examples

 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

Display network  ifconfig


ifconfig interface information. shows the details of all network interfaces.

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

Download files from  wget http://example.com/file.txt


wget the web. downloads "file.txt" from the specified URL.

 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

cmd < file Input of cmd is taken from file.

cmd > file Standard output (stdout) of cmd is redirected to file.

cmd 2> file Error output (stderr) of cmd is redirected to file.

cmd 2>&1 stderr is redirected to the same place as stdout.

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

cmd &> file Every output of cmd is redirected to file.


Command Description

cmd 1>&2 stdout is redirected to the same place as stderr.

cmd >> file Appends the stdout of cmd to file.

8. Environment Variable Commands


In Linux, environment variables are used to store configuration settings, system information,
and other variables that can be accessed by processes and shell scripts. Here are some
commonly used environment variable commands:
Command Description

export
Sets the value of an environment variable.
VARIABLE_NAME=value

Displays the value of a specific environment


echo $VARIABLE_NAME
variable.

Lists all environment variables currently set in the


env
system.

unset VARIABLE_NAME Unsets or removes an environment variable.

Shows a list of all currently exported environment


export -p
variables.

Sets the value of an environment variable for a


env VAR1=value COMMAND
specific command.

printenv Displays the values of all environment variables.

9. User Management Commands


In Linux, user management commands allow you to create, modify, and manage user
accounts on the system. Here are some commonly used user management commands:
Command Description

who Show who is currently logged in.

Create a new user account on the system with the


sudo adduser username
specified username.

finger Display information about all the users currently logged


Command Description

into the system, including their usernames, login time, and


terminal.

sudo deluser USER


Remove the specified user from the specified group.
GROUPNAME

last Show the recent login history of users.

Provide information about the specified user, including


finger username their username, real name, terminal, idle time, and login
time.

Delete the specified user account from the system,


sudo userdel -r username including their home directory and associated files. The -r
option ensures the removal of the user's files.

Lock the password of the specified user account,


sudo passwd -l username
preventing the user from logging in.

Switch to another user account with the user's


su - username
environment.

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.

10. Shortcuts Commands


There are many shortcuts commands in Linux that can help you be more productive. Here are
a few of the most common ones:
10.1: Bash Shortcuts Commands:
Navigation Description Editing Description History Description

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.

Ctrl + E Move to the Ctrl + Cut/delete from Ctrl + Escape from


end of the K the cursor G history search
line. position to the mode.
Navigation Description Editing Description History Description

end of the 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.

10.2: Nano Shortcuts Commands:


Searc
File h and
Operatio Descript Navigati Descript Editi Descripti Repla Descript
ns ion on ion ng on ce ion

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

Ctrl + Read a Alt + \ Go to a Ctrl Mark a Alt + Repeat


R file into specific +6 block of R the last
the line text for search.
current number. copying
Searc
File h and
Operatio Descript Navigati Descript Editi Descripti Repla Descript
ns ion on ion ng on ce ion

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.

10.3: VI Shortcuts Commands:

Command Description

Change the current word. Deletes from the cursor position to the end of the
cw
current word and switches to insert mode.

dd Delete the current line.

x Delete the character under the cursor.

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.

u Undo the last change.


Command Description

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.

D Delete from the cursor position to the end of the line.

4dw Delete the next four words from the cursor position.

A Switch to insert mode at the end of the current line.

S Delete the current line and switch to insert mode.

Replace the character under the cursor with a new character entered from the
r
keyboard.

i Switch to insert mode before the cursor.

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.

~ Switch the case of the character under the cursor.

a Switch to insert mode after the cursor.

Delete from the cursor position to the end of the line and switch to insert
C
mode.

10.4: Vim Shortcuts Commands:


Normal Command Visual
Mode Description Mode Description Mode Description

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.

:wq Paste the


Copy the Save and quit
yy or p copied or
current line. Vim.
:x:x deleted text.

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

Ctrl + Redo the last


R undo.

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

Subnet Mask Cheat Sheet


A Subnet Mask is a numerical value that describes a computer or device's how to divide an IP
address into two parts: the network portion and the host portion. The network element
identifies the network to which the computer belongs and the host part identifies the unique
computer on that network. An
9 min read

Git Cheat Sheet


Git Cheat Sheet is a comprehensive quick guide for learning Git concepts, from very basic to
advanced levels. By this Git Cheat Sheet, our aim is to provide a handy reference tool for
both beginners and experienced developers/DevOps engineers. This Git Cheat Sheet not only
makes it easier for newcom
10 min read

NumPy Cheat Sheet: Beginner to Advanced (PDF)


NumPy stands for Numerical Python. It is one of the most important foundational packages
for numerical computing & data analysis in Python. Most computational packages providing
scientific functionality use NumPy’s array objects as the lingua franca for data exchange.
In this Numpy Cheat sheet f
15+ min read

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 W
13 min read

Pandas Cheat Sheet for Data Science in Python


Pandas is a powerful and versatile library that allows you to work with data in Python. It
offers a range of features and functions that make data analysis fast, easy, and efficient.
Whether you are a data scientist, analyst, or engineer, Pandas can help you handle large
datasets, perform complex op
15+ min read

Java Cheat Sheet


Java is a programming language and platform that has been widely used since its
development by James Gosling in 1991. It follows the Object-oriented Programming concept
and can run programs written on any OS platform. Java is a high-level, object-oriented,
secure, robust, platform-independent, multi
15+ min read

C++ STL Cheat Sheet


The C++ STL Cheat Sheet provides short and concise notes on Standard Template Library
(STL) in C++. Designed for programmers that want to quickly go through key STL concepts,
the STL cheatsheet covers the concepts such as vectors and other containers, iterators,
functors, etc., with their syntax and
15+ min read

Docker Cheat Sheet : Complete Guide (2024)


Docker is a very popular tool introduced to make it easier for developers to create, deploy,
and run applications using containers. A container is a utility provided by Docker to package
and run an application in a loosely isolated environment. Containers are lightweight and
contain everything neede
10 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

You might also like