0% found this document useful (0 votes)
129 views21 pages

Linux Commands Cheat Sheet - Beginner To Advanced

The document provides a comprehensive Linux commands cheat sheet covering basic and advanced commands for file operations, permissions, compression, processes, systems information, networking and more with examples. It explains what Linux is and provides a table of contents and explanations of common commands like ls, cd, mkdir, rm etc. with examples to help users understand Linux commands.
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)
129 views21 pages

Linux Commands Cheat Sheet - Beginner To Advanced

The document provides a comprehensive Linux commands cheat sheet covering basic and advanced commands for file operations, permissions, compression, processes, systems information, networking and more with examples. It explains what Linux is and provides a table of contents and explanations of common commands like ls, cd, mkdir, rm etc. with examples to help users understand Linux commands.
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/ 21

Linux Commands Cheat Sheet

Last Updated : 24 Aug, 2023


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
Bash Shortcuts Commands
Nano Shortcuts Commands
VI Shortcuts Commands
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 ls -l
displays files and directories
-l: Long format
with detailed information.
listing.
ls -a
List files and -a: Include hidden
shows all files and
directories. files hidden ones
directories, including
-h: Human-
ls -lh
readable file sizes.
displays file sizes in a
human-readable format.

cd cd /path/to/directory
Change directory. changes the current directory
to the specified path.

pwd pwd
Print current
displays the current working
working directory.
directory.

mkdir mkdir my_directory


Create a new
creates a new directory
directory.
named “my_directory”.

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

cp Copy files and -r: Copy cp -r directory destination


directories. directories copies the directory
recursively. “directory” and its contents
to the specified destination.
cp file.txt destination
copies the file “file.txt” to the
Command Description Options Examples

specified destination.

mv mv file.txt new_name.txt
renames the file “file.txt” to
Move/rename files “new_name.txt”.
and directories. mv file.txt directory
moves the file “file.txt” to the
specified directory.

touch Create an empty touch file.txt


file or update file creates an empty file named
timestamps. “file.txt”.

cat cat file.txt


View the contents
displays the contents of the
of a file.
file “file.txt”.

head head file.txt


shows the first 10 lines of
-n: Specify the
Display the first the file “file.txt”.
number of lines to
few lines of a file. head -n 5 file.txt
display.
displays the first 5 lines of
the file “file.txt”.

tail tail file.txt


shows the last 10 lines of the
-n: Specify the
Display the last few file “file.txt”.
number of lines to
lines of a file. tail -n 5 file.txt
display.
displays the last 5 lines of
the file “file.txt”.

ln ln -s source_file link_name
-s: Create
Create links creates a symbolic link
symbolic (soft)
between files. named “link_name” pointing
links.
to “source_file”.

find Search for files and -name: Search by find /path/to/search -name
directories. filename. “*.txt”
-type: Search by searches for all files with the
file type.
HTML Cheat Sheet CSS Cheat
Command Sheet JS Cheat Sheet
Description Bootstrap
Options Cheat Sheet jQuery Cheat Sheet Angular Cheat Sheet
Examples SD

extension “.txt” in the


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

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

chown chown user file.txt


Change file
changes the owner of “file.txt” to
ownership.
the specified user.

chgrp chgrp group file.txt


Change group
changes the group ownership of
ownership.
“file.txt” to the specified group.

umask Set default file umask 022


permissions. sets the default file permissions
to read and write for the owner,
Command Description Options Examples

and read-only for group and


others.

3. File Compression and Archiving Commands


Here are some file compression and archiving commands in Linux:

Commands Description Options Examples

tar -c: Create a new


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

gzip gzip file.txt


-d: Decompress
Compress files. compresses the file “file.txt” and
files.
renames it as “file.txt.gz”.

zip zip archive.zip file1.txt file2.txt


Create -r: Recursively
creates a zip archive named
compressed zip include
“archive.zip” containing
archives. directories.
“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 ps aux
shows all running
Display running -aux: Show all
processes with
processes. processes.
detailed information.

top top
displays a dynamic
Monitor system
view of system
processes in real-time.
processes and their
resource usage.

kill kill PID


-9: Forcefully kill terminates the process
Terminate a process.
a process. with the specified
process ID.

pkill pkill process_name


Terminate processes terminates all
based on their name. processes with the
specified name.

pgrep pgrep process_name


List processes based on lists all processes with
their name. the specified name.

grep used to search for -i: Ignore case grep -i “hello” file.txt
specific patterns or distinctions while grep -v “error” file.txt
regular expressions in searching. grep -r “pattern”
text files or streams and -v: Invert the directory/
display matching lines. match, displaying grep -l “keyword”
non-matching file.txt
lines. grep -n “pattern”
-r or -R: file.txt
Recursively In these examples we
search directories are extracting our
for matching desirec output from
patterns. filename (file.txt)
Commands Description Options Examples

-l: Print only the


names of files
containing
matches.
-n: Display line
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 uname -a
Print system -a: All system
displays all system
information. information.
information.

whoami whoami
Display current
shows the current
username.
username.

df df -h
Show disk space -h: Human- displays disk space usage
usage. readable sizes. in a human-readable
format.

du -h: Human-
du -sh directory/
Estimate file and readable sizes.
provides the total size of
directory sizes. -s: Display total
the specified directory.
size only.

free free -h
Display memory -h: Human-
displays memory usage in
usage information. readable sizes.
a human-readable format.

uptime uptime
Show system
shows the current system
uptime.
uptime.

lscpu lscpu
Display CPU provides detailed CPU
information. information.

lspci lspci
List PCI devices.
List PCI devices.

lsusb lsusb
lists all connected USB
List USB devices.
devices.
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

ifconfig Display network ifconfig


interface information. shows the details of all network interfaces.

ping ping google.com


Send ICMP echo
sends ICMP echo requests to “google.com” to
requests to a host.
check connectivity.

netstat Display network


netstat -tuln
connections and
shows all listening TCP and UDP connections.
statistics.

ss ss -tuln
Display network socket
shows all listening TCP and UDP connections.
information.

ssh ssh user@hostname


Securely connect to a
initiates an SSH connection to the specified
remote server.
hostname.

scp scp file.txt


Securely copy files user@hostname:/path/to/destination
between hosts. securely copies “file.txt” to the specified remote
host.

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


web. downloads “file.txt” from the specified URL.

curl curl http://example.com


Transfer data to or from
retrieves the content of a webpage from the
a server.
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 > /dev/null Discards the stdout of cmd by sending it to the null device.

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

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

echo $VARIABLE_NAME Displays the value of a specific environment variable.

env Lists all environment variables currently set in the system.

unset VARIABLE_NAME Unsets or removes an environment variable.


Command Description

Shows a list of all currently exported environment


export -p
variables.

Sets the value of an environment variable for a specific


env VAR1=value COMMAND
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 specified


sudo adduser username
username.

Display information about all the users currently logged into


finger
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 their


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

Delete the specified user account from the system, including


sudo userdel -r username 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, preventing the


sudo passwd -l username
user from logging in.
Command Description

su – username Switch to another user account with the user’s environment.

sudo usermod -a -G
Add an existing user to the specified group. The user is added
GROUPNAME
to the group without removing them from their current groups.
USERNAME

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 position command
Ctrl + A beginning of Ctrl + U Ctrl + R
to the beginning of history (reverse
the line.
the line. search).

Cut/delete from
Escape from
Move to the the cursor position
Ctrl + E Ctrl + K Ctrl + G history search
end of the line. to the end of the
mode.
line.

Go to the
Cut/delete the
Move back one Ctrl + previous
Ctrl + B word before the Ctrl + P
character. W command in
cursor.
history.

Go to the next
Move forward Paste the last cut
Ctrl + F Ctrl + Y Ctrl + N command in
one character. text.
history.

Terminate the
Move back one
Alt + B Ctrl + L Clear the screen. Ctrl + C current
word
command.
Navigation Description Editing Description History Description

Move forward
Alt + F
one word.

10.2: Nano Shortcuts Commands:

File Description Navigation Description Editing Description Sear


Operations and
Repla

Cut/delete
from the
Save the Scroll up one cursor
Ctrl + O Ctrl + Y Ctrl + K Ctrl +
file. page. position to
the end of
the line.

Exit Nano
Uncut/restore
(prompt to Scroll down
Ctrl + X Ctrl + V Ctrl + U the last cut Alt +
save if one page.
text.
modified).

Read a file Mark a block


Go to a
into the of text for
Ctrl + R Alt + \ specific line Ctrl + 6 Alt +
current copying or
number.
buffer. cutting.

Go to the
Justify the Cut/delete
beginning of
Ctrl + J current Alt + , Ctrl + K the marked
the current
paragraph. block of text.
line.

Go to the Copy the


Alt + . end of the Alt + 6 marked block
current line. of text.

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 until
R
you press the Escape key.

o Insert a new line below the current line and switch to insert mode.

u Undo the last change.

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.


Command Description

a Switch to insert mode after the cursor.

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

10.4: Vim Shortcuts Commands:

Normal Description Command Description Visual Description


Mode Mode Mode

Enter insert
Enter visual
mode at the
i :w Save the file. v mode to select
current cursor
text.
position.

Delete the
Copy the
x character under :q Quit Vim. y
selected text.
the cursor.

Delete the Quit Vim without Delete the


dd :q! d
current line. saving changes. selected text.

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

Paste the copied Replace all


or deleted text occurrences of
p :s/old/new/g
below the “old” with “new”
current line. in the file.

:set nu
Undo the last or Display line
u
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.

FAQs on Linux Commands Cheat Sheet

1. What is Linux Cheat Sheet?

When your memory fails or you prefer not to rely on “linux –help?” in the Terminal,
this linux cheat sheet comes to the rescue. It is hard to memorize all the important
linux Commandsby heart, so print this out or save it to your desktop to resort to
when you get stuck.

2.What are the basics of Linux?

Kernel. The base component of the OS. Without it, the OS doesn’t work. …
System user space. The administrative layer for system-level tasks like
configuration and software install. …
Applications. A type of software that lets you perform a task.

3. What is 777 in Linux command?

You might have heard of chmod 777. This command will give read, write and
execute permission to the owner, group and public.

4. How do I see what users are doing in Linux?

Using the w Command, w command in Linux shows logged-in users and their
activities.

Here's a complete roadmap for you to become a developer: Learn DSA -> Master
Frontend/Backend/Full Stack -> Build Projects -> Keep Applying to Jobs

And why go anywhere else when our DSA to Development: Coding Guide helps you do
this in a single program! Apply now to our DSA to Development Program and our
counsellors will connect with you for further guidance & support.

15 Suggest improvement

Previous Next

NumPy Cheat Sheet: Beginner to Advanced Pandas Cheat Sheet for Data Science in Python
(PDF)

Share your thoughts in the comments Add Your Comment

Similar Reads
jQuery Cheat Sheet – A Basic Guide to jQuery Tkinter Cheat Sheet

CSS Cheat Sheet - A Basic Guide to CSS Git Cheat Sheet

ggplot2 Cheat Sheet Subnet Mask Cheat Sheet


C++ STL Cheat Sheet Python OpenCV Cheat Sheet

C Cheat Sheet React Cheat Sheet

J jayes5h62

Article Tags : Cheat Sheet , GFG Sheets , linux-command , Linux-Unix

A-143, 9th Floor, Sovereign Corporate


Tower, Sector-136, Noida, Uttar Pradesh -
201305

Company Explore
About Us Hack-A-Thons
Legal GfG Weekly Contest
Careers DSA in JAVA/C++
In Media Master System Design
Contact Us Master CP
Advertise with us GeeksforGeeks Videos
GFG Corporate Solution Geeks Community
Placement Training Program

Languages DSA
Python Data Structures
Java Algorithms
C++ DSA for Beginners
PHP Basic DSA Problems
GoLang DSA Roadmap
SQL Top 100 DSA Interview Problems
R Language DSA Roadmap by Sandeep Jain
Android Tutorial All Cheat Sheets
Tutorials Archive

Data Science & ML HTML & CSS


Data Science With Python HTML
Data Science For Beginner CSS
Machine Learning Tutorial Web Templates
ML Maths CSS Frameworks
Data Visualisation Tutorial Bootstrap
Pandas Tutorial Tailwind CSS
NumPy Tutorial SASS
NLP Tutorial LESS
Deep Learning Tutorial Web Design
Django Tutorial

Python Tutorial Computer Science


Python Programming Examples Operating Systems
Python Projects Computer Network
Python Tkinter Database Management System
Web Scraping Software Engineering
OpenCV Tutorial Digital Logic Design
Python Interview Question Engineering Maths

DevOps Competitive Programming


Git Top DS or Algo for CP
AWS Top 50 Tree
Docker Top 50 Graph
Kubernetes Top 50 Array
Azure Top 50 String
GCP Top 50 DP
DevOps Roadmap Top 15 Websites for CP

System Design JavaScript


High Level Design JavaScript Examples
Low Level Design TypeScript
UML Diagrams ReactJS
Interview Guide NextJS
Design Patterns AngularJS
OOAD NodeJS
System Design Bootcamp Lodash
Interview Questions Web Browser

Preparation Corner School Subjects


Company-Wise Recruitment Process Mathematics
Resume Templates Physics
Aptitude Preparation Chemistry
Puzzles Biology
Company-Wise Preparation Social Science
English Grammar
World GK

Management & Finance Free Online Tools


Management Typing Test
HR Management Image Editor
Finance Code Formatters
Income Tax Code Converters
Organisational Behaviour Currency Converter
Marketing Random Number Generator
Random Password Generator

More Tutorials GeeksforGeeks Videos


Software Development DSA
Software Testing Python
Product Management Java
SAP C++
SEO - Search Engine Optimization Data Science
Linux CS Subjects
Excel

@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved

You might also like