0% found this document useful (0 votes)
11 views

Linux Commands Cheat Sheet - Codelvily

The document is a comprehensive Linux Commands Cheat Sheet that provides a curated list of essential commands for various tasks including file management, searching, directory navigation, user management, package management, and more. It covers commands applicable to both RedHat-like and Debian-like distributions, along with descriptions for each command. Additionally, it includes sections on process management, system information, disk usage, SSH login, file permissions, networking, and keyboard shortcuts.

Uploaded by

syedbaran438
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Linux Commands Cheat Sheet - Codelvily

The document is a comprehensive Linux Commands Cheat Sheet that provides a curated list of essential commands for various tasks including file management, searching, directory navigation, user management, package management, and more. It covers commands applicable to both RedHat-like and Debian-like distributions, along with descriptions for each command. Additionally, it includes sections on process management, system information, disk usage, SSH login, file permissions, networking, and keyboard shortcuts.

Uploaded by

syedbaran438
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Linux Commands Cheat Sheet -

Codelvily

The command line terminal in Linux is the operating systemʼs most powerful
component. However, due to the sheer amount of commands available, it can be
intimidating for newcomers. Even longtime users may forget a command every once
in a while and that is why we have created this Linux cheat sheet commands guide.

In this page, weʼll present you with a curated list of the most handy Linux
commands.

Please note that those commands are for Linux in general, both RedHat-like and
Debian-like distributions. There are some commands in the Package management
session which may be specific for Redhat-based such as yum and rpm which do
not work in Ubuntu Debian-based).

Linux Commands Cheat Sheet  Codelvily 1


File Commands
Command Descr iption
ls List files in the directory

ls -a List all files (shows hidden files)

Find all files and directories related to a particular


locate [name]
name:
Show directory you are currently working in
pwd
Create a new directory
mkdir [directory]
Remove a file
rm [file_name]
Remove a directory recursively
rm -r [directory_name]
Recursively remove a directory without requiring
rm -rf [directory_name] confir mation
Copy the contents of one file to another file
cp [file_name1] [file_name2]
Recursively copy the contents of one file to a second
cp -r [directory_name1] file
[directory_name2]
Rename [file_name1 to [file_name2 with the command
mv [file_name1] [file_name2]
Create a symbolic link to a file
ln -s /path/to/[file_name]
[link_name]
Create a new file using touch
touch [file_name]
Show the contents of a file
more [file_name]
or use the cat command
cat [file_name]

cat [file_name1] >>


[file_name2]
Append file contents to another file

head [file_name] Display the first 10 lines of a file with head command

tail [file_name] Show the last 10 lines of a file

Show the number of words, lines, and bytes in a file


wc
using wc
List number of lines/words/characters in each file in a
ls \| xargs wc directory with the xargs command
Cut a section of a file and print the result to standard
cut -d[delimiter] [filename] output

Linux Commands Cheat Sheet  Codelvily 2


Cut a section of piped data and print the result to
[data] \| cut -d[delimiter]
standard output
awk '[pattern] {print $0}' Print all lines matching a pattern in a file
[filename]

diff [file1] [file2] Compare two files and display differences


source [filename] Read and execute the file content in the current shell

[command] \| tee [filename] Store the command output in a file and skip the
>/dev/null terminal output

Searching
Command Descr iption
grep [pattern]
Search for a specific pattern in a file with grep
[file_name]

grep -r [pattern]
[directory_name]
Recursively search for a pattern in a directory:

locate [name] Find all files and directories related to a particular name:

List names that begin with a specified character [a] in a


find [/folder/location] -
specified location [/folder/location] by using the find
name [a]
command:
find [/folder/location] -
size [+100M]
See files larger than a specified size 100M in a folder:

Directory Navigation
Command Descr iption
tar cf [compressed_file.tar] [file_name] Archive an existing file

tar xf [compressed_file.tar] Extract an archived file

tar czf [compressed_file.tar.gz] Create a gzip compressed tar file by running

gzip [file_name] Compress a file with the .gz extension

Linux Commands Cheat Sheet  Codelvily 3


File Transfer
Command Descr iption
scp [file_name.txt] Copy a file to a server directory securely using the Linux
[server/tmp] scp command

rsync -a [/your/directory] Synchronize the contents of a directory with a backup


[/backup/] directory using the rsync command

Users and Groups


Command Descr iption
id See details about the active users

last Show last system logins


Display who is currently logged into the
who
system with the who command
Show which users are logged in and their
w activit y
Add a new group by typing
groupadd [group_name]
Add a new user
adduser [user_name]
Add a user to a group
usermod -aG [group_name] [user_name]
Temporarily elevate user privileges to
sudo superuser or root using the sudo command
[command_to_be_executed_as_superuser]
Delete a user
userdel [user_name]
Modify user information with
usermod
Change directory group
chgrp [group-name] [directory-name]

Package management
Command Descr iption
List all installed packages with
yum list installed
yum
Find a package by a related
yum search [keyword]
keyword

Linux Commands Cheat Sheet  Codelvily 4


Show package information and
yum info [package_name]
summar y

Install a package using the YUM


yum install [package_name.rpm]
package manager
Install a package using the DNF
dnf install [package_name.rpm] package manager
Install a package using the APT
apt install [package_name] package manager
Install an .rpm package from a
local file
rpm -i [package_name.rpm]
Remove an .rpm package

rpm -e [package_name.rpm] Install an .deb package from a


local file
dpkg -i [package_name.deb] Remove an .deb package

dpkg -r [package_name.deb] Install software from source


code
tar zxvf [source_code.tar.gz] && cd [source_code] &&
./configure && make && make install

Process management
Command Descr iption
ps See a snapshot of active processes

pstree Show processes in a tree-like diagram

pmap Display a memory usage map of processes

top See all running processes

kill [process_id] Terminate a Linux process under a given ID

pkill [proc_name] Terminate a process under a specific name

killall [proc_name Terminate all processes labelled “procˮ

bg
List and resume stopped jobs in the background
Bring the most recently suspended job to the
fg foreground
Bring a particular job to the foreground
fg [job]
List files opened by running processes
lsof

Linux Commands Cheat Sheet  Codelvily 5


trap "[commands-to-execute-on-
Catch a system error signal in a shell script
trapping]" [signal]

Pause terminal or a Bash script until a running


wait
process is completed
nohup [command] & Run a Linux process in the background

System Management and Information


Command Descr iption
uname -r Show system information

uname -a See kernel release information


Display how long the system has been running, including load
uptime
average
See system hostname
hostname
Show the IP address of the system
hostname -i
List system reboot history
last reboot
See current time and date
date
Query and change the system clock with
timedatectl
Show current calendar (month and day)
cal
See which user you are using
whoami
Show information about a particular user
finger [username]

ulimit [flags] View or limit system resource amounts


[limit]
Schedule a system shutdown
shutdown [hh:mm]
Shut Down the system immediately
shutdown now

Disk Usage
Command Descr iption

df -h See free and used space on mounted systems

df -i Show free inodes on mounted filesystems

Linux Commands Cheat Sheet  Codelvily 6


Display disk partitions, sizes, and types with the
fdisk -l
command
du -ah See disk usage for all files and directory
du -sh Show disk usage of the directory you are currently in
findmnt Display target mount point for all filesystem
mount [device_path]
Mount a device
[mount_point]

SSH Login
Command Descr iption
ssh user@host Connect to host as user

ssh host Securely connect to host via SSH default port 22

ssh -p [port] user@host Connect to host using a particular port

File Permission
Command Descr iption
chmod 777 [file_name] Assign read, write, and execute permission to everyone
Give read, write, and execute permission to owner, and read
chmod 755 [file_name]
and execute permission to group and others
Assign full permission to owner, and read and write permission
chmod 766 [file_name] to group and others
Change the ownership of a file
chown [user]
[file_name]

chown [user]:[group]
[file_name]
Change the owner and group ownership of a file

Network
Command Descr iption
ip addr show List IP addresses and network interfaces

Linux Commands Cheat Sheet  Codelvily 7


ip address add
Assign an IP address to interface eth0
[IP_address]

ifconfig Display IP addresses of all network interfaces with


netstat -pnltu See active (listening) ports with the netstat command
netstat -nutlp Show tcp and udp ports and their programs
whois [domain] Display more information about a domain
dig [domain] Show DNS information about a domain using the dig command
dig -x host Do a reverse lookup on domain
dig -x [ip_address] Do reverse lookup of an IP address
host [domain] Perform an IP lookup for a domain
hostname -I Show the local IP address
wget [file_name] Download a file from a domain using the wget command
nslookup [domain- Receive information about an internet domain
name]
Save a remote file to your system using the filename that
curl -O [file-url] corresponds to the filename on the server

Variables
Command Descr iption

let "[variable]=[value]" Assign an integer value to a variable

export [variable-name] Export a Bash variable

declare [variable-name]= "


[value]"
Declare a Bash variable

List the names of all the shell variables and


set
functions
echo $[variable-name]
Display the value of a variable

Shell Command Management


Command Descr iption

Linux Commands Cheat Sheet  Codelvily 8


alias [alias-
Create an alias for a command
name]='[command]'

watch -n [interval-in-
seconds] [command]
Set a custom interval to run a user-defined command

sleep [time-interval] &&


[command]
Postpone the execution of a command

Create a job to be executed at a certain time Ctrl+D to


at [hh:mm]
exit prompt after you type in the command)
man [command]
Display a built-in manual for a command

Print the history of the commands you used in the


history terminal

Linux Keyboard Shortcuts


Command Descr iption
Ctrl + C Kill process running in the terminal
Stop current process  The process can be resumed in the foreground
Ctrl + Z
with fg or in the background with bg
Cut one word before the cursor and add it to clipboard
Ctrl + W
Cut part of the line before the cursor and add it to clipboard
Ctrl + U
Cut part of the line after the cursor and add it to clipboard
Ctrl + K
Paste from clipboard
Ctrl + Y
Recall last command that matches the provided characters
Ctrl + R
Run the previously recalled command
Ctrl + O
Exit command history without running a command
Ctrl + G
Run the last command again
!!
Log out of current session
`Ctrl  D

Hardware information
Command Descr iption
dmesg Show bootup messages

Linux Commands Cheat Sheet  Codelvily 9


cat /proc/cpuinfo See CPU information
free -h Display free and used memory

lshw List hardware configuration information

lsblk See information about block devices

lspci -tv Show PCI devices in a tree-like diagram

dmidecode Show hardware information from the BIOS

hdparm -i /dev/disk Display disk data information

hdparm -tT /dev/[device] Conduct a read-speed test on device/disk

fsck [disk-or-partition-location]
Run a disk check on an unmounted disk or partition

Linux Commands Cheat Sheet  Codelvily 10

You might also like