0% found this document useful (0 votes)
261 views8 pages

Linux Commands Cheat Sheet

This document provides a cheat sheet of common Linux commands organized into categories such as hardware information, file compression, package installation, SSH login, searching, file transfer, process related commands, disk usage, file commands, directory navigation, system information, users, network, file permission, and keyboard. It lists over 50 commands and provides brief descriptions of their functions.
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)
261 views8 pages

Linux Commands Cheat Sheet

This document provides a cheat sheet of common Linux commands organized into categories such as hardware information, file compression, package installation, SSH login, searching, file transfer, process related commands, disk usage, file commands, directory navigation, system information, users, network, file permission, and keyboard. It lists over 50 commands and provides brief descriptions of their functions.
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/ 8

Linux

Commands
Cheat
Sheet

Hardware
Information
dmesg show bootup messages

cat /proc/cpuinfo show CPU information

free -h show free and used memory (-m


flag indicates memory in MB)

lshw list information about hardware


configuration

lsblk list information about block


devices

lspci-tv show PCI devices in a tree-like


diagram

lsusb-tv show USB devices in a tree-like


diagram

dmidecode show hardware information from


the BIOS

dmidecode show hardware information from


the BIOS

hdparm -i /dev/[disk] show information about disk


data

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


disk

badblocks -s /dev/[disk] test for unreadable blocks on


disk

1 8
File
Compression
tar cf create an archived file from a
[compressed_file.tar] file
[file_name]
tar xf extract archived file
[compressed_file.tar]
tar czf create a gzip compressed tar
[compressed_file.tar.gz] file
gzip [file_name] compress a file with the .gz
extension

Package
Installation
yum search [keyword] find a package by a related
keyword
yum info show package information and
[package_name] summary
yum install install a package using the YUM
[package_name.rpm] package manager
dnf install install a package using the DNF
[package_name.rpm] package manager
rpm -i install an rpm package from a
[package_name.rpm] local file
rpm -e remove an rpm package
[package_name.rpm]
tar zxvf
install software from source
[source_code.tar.gz]
code
cd [source_code]

./configure

make

make install

2 8
SSH Login
ssh user@host connect to host as user
ssh host securely connect to host via
SSH default port 22
ssg -p [port] user@host connect to host using a
particular port
telnet host connect to host via telnet
default port 23

Searching
grep [pattern] search for a specific pattern in a
[file_name] file
grep -r [pattern] search recursively for a specific
[directory_name] pattern in a directory
locate [name] find all files and directories by a
specific name
find [/folder/location] list names that begin with [a] in
-name [a] [/folder/location]
find [/folder/location] list files larger than 100M in a
-size [+100M] particular folder

File Transfer
scp [file_name.txt] securely copy a specific file to a
[server/tmp] server directory
rsync -a synchronize the contents of a
[/your/directory] specific directory with a backup
[/backup/] directory

3 8
Process
Related
ps show a snapshot of active
processes
ps tree show processes as a tree
pmap shows a memory usage map of
processes
top show all running processes
kill [process_id] kill a process under a given ID
pkill [proc_name] kill a process under the
specified name
killall [proc_name] kill all processed labelled proc
bg list and resume stopped jobs in
the background
fg bring the most recent
suspended job to the
foreground
fg [job] bring a particular job to the
foreground
lsof list files opened by processes

Disk Usage
df -h show free and used space on
mounted systems
df -i show free inodes on mounted
filesystems
fdisk -l show disk partitions, sizes, and
types
du -ah show disk usage for all files and
directory
du -sh show disk usage of current
directory
findmnt show target mount point for all
filesystems
mount [device_path] mount a device
[mount_point]

4 8
File
Commands
ls list files in directory
ls -a list all files, including hidden
pwd show the directory currently
working in
mkdir [directory] create a new directory
rm [file_name] remove a file
rm -r [directory_name] remove a directory recursively
rm -rf [directory_name] remove a directory recursively
without requiring confirmation
cp [file_name1] copy the contents of the first
[file_name2] file to the second file
cp -r [directory_name1] recursively copy the contents of
[director_name2] the first directory into the
second directory
mv [file_name1] rename file_ name1 to
[file_name2] file_ name2
ln -s create a symbolic link to a file
/path/to/[file_name]
[link_name]
touch [file_name] create a new file
more [file_name] show the contents of a file
head [file_name] show the first 10 lines of a file
tail [file_name] show the last 10 lines of a file
gpg -c [file_name] encrypt a file
gpg [file_name.gpg] decrypt a file
wc print the number of words, lines,
and bytes in a file

Directory
Navigation
cd .. move up one level in the
directory tree structure
cd change directory to $HOME
cd /chosen /directory change to specified directory

5 8
System

Information
uname -r show system information
unname -a show kernel release information
uptime show how long the system has
been running, including, load
average
hostname show system hostname
hostname -i show the ip address of the
system
last reboot show system reboot history
date show current time and date
timedatectl query and change the system
clock
cal show current calendar month
and day
w show logged in users in the
system
whoami show user you are using
finger [username] show information about a user

Users
id show details of the active user
last show the last logins onto the
system
who show who is logged into the
system
w show who is logged in and their
activity
groupadd
add a new group
[group_name]
adduser [user_name] add new user
usermod -aG add a user to a group
[group_name]
[user_name]
userdel [user_name] delete a user
usermod use for changing/modifying user
information

6 8
Users
id show details of the active user
last show the last logins onto the
system
who show who is logged into the
system
w show who is logged in and their
activity
groupadd
add a new group
[group_name]
adduser [user_name] add new user
usermod -aG add a user to a group
[group_name]
[user_name]
userdel [user_name] delete a user
usermod use for changing/modifying user
information

Network
ip addr show show IP addresses and network
interfaces
ip address add assign an IP address to
[IP_address] interface eth0
ifconfig show IP addresses of all
network interfaces
netstat -pnltu show active (listening) ports
netstat -nutlp show tcp and udp ports and
their programs
whois [domain] show more information about a
domain
dig [domain] show DNS information about a
domain
dig -x host reverse lookup on domain
dig -x [ip_address] reverse lookup of an IP address
host [domain] do an IP lookup for a domain
hostname -l show the local IP address
wget [file_name] download a file from a domain

7 8
File Permission
chmod 777 [file_name] give read, write, and execute
permission to everyone
chmod 755 [file_name] give full permission to owner,
and read and execute
permission to group and others
chmod 766 [file_name] give full permission to owner,
and read and write permission
to group and others
chown [user] change the file ownership
[file_name]
chown [user]: [group] change the owner and group
[file_name] ownership of a file

Keyboard
Shortcuts
Ctrl + C kill current process running in
the terminal
Ctrl + Z stop current process (can be
resumed in the foreground with
fg or in the background with bg)
Ctrl + W cut one word before the cursor
and add it to clipboard
Ctrl + U cut part of the line before the
cursor and add it to clipboard
Ctrl + K cut part of the line after the
cursor and add it to clipboard
Ctrl + Y paste from clipboard

Ctrl + R recall last command that


matches the provided
characters
Ctrl + O run the previous recalled
command
Ctrl + G exit command history without
running a command
!! repeat the last command

exit log out of current session

8 8

You might also like