You are on page 1of 1

Linux Commands Cheat Sheet

Keyboard Shortcuts Users and Groups Files System Management Processes

Ctrl + C Kill process running in the id See details about the mkdir [directory_name] Create a new directory. uname -r Show system information ps List active processes.
terminal. active users. via uname command.
rm [file_name] Remove a file. pstree Show processes in a tree-
Ctrl + Z Stop the current process. last Show the last system uname -a See kernel release like diagram.
The process can be logins. rm -r [directory_name] Remove a directory information.
resumed in the foreground recursively. pmap Display a memory usage
with fg or in the who Display who is currently uptime Display how long the map of processes.
background with bg. logged into the system. rm -rf [directory_name] Recursively remove a system has been running,
directory without requiring including the load average. top See all running processes.
Ctrl + W Cut one word before the w Show which users confirmation.
cursor and add it to the are logged in and their hostname View system hostname. htop Interactive and colorful
clipboard. activity. cp [source_file] Copy the contents of one process viewer.
[destination_file] file to another file. hostname -i Show the IP address of the
Ctrl + U Cut part of the line before finger [user_name] Show user information. system. kill [process_id] Terminate a Linux
the cursor and add it to the cp -r [source_directory] Recursively copy a process under a given ID.
clipboard. sudo useradd Create a new user account. [destination_directory] directory to a second last reboot List system reboot history.
[user_name] directory. pkill [process_name] Terminate a process under
Ctrl + K Cut part of the line after the date See current time and date. a specific name.
cursor and add it to the sudo adduser Create a new user account mv [source_file] Move or rename files or
clipboard. [user_name] through the adduser [destination_file] directories. timedatectl Query and change killall [label] Terminate all processes with
command interface. the system clock. a given label.
Ctrl + Y Paste from clipboard. ln -s [path]/[file_name] Create a symbolic link to a
sudo userdel [user_name] Delete a user account. [link_name] file. cal Show current calendar prgrep [keyword] List processes based on the
Ctrl + R Recall the last command (month and day). provided keyword.
that matches the provided sudo usermod -aG Modify user touch [file_name] Create a new file.
characters. [group_name] information (add a user to w List logged-in users. pidof [process_name] Show the PID of a process.
[user_name] a group). cat [file_name] Show the contents of a file.
Ctrl + O Run the previously recalled whoami See which user you are bg List and resume stopped
command. passwd Change the current user's cat [source_file] >> Append file contents to using. jobs in the background.
sudo passwd [user_name] or another user's [destination_file] another file.
Ctrl + G Exit command history password. finger [user_name] Show information about a Bring the most recently
without running a head [file_name] Show the first ten lines of a particular user. fg suspended job to the
command. sudo groupadd Add a new group. file. foreground.
[group_name] ulimit [flags] [limit] View or limit system
clear Clear the terminal screen. tail [file_name] Show the last ten lines of a resource amounts. fg [job] Bring a particular job to the
sudo groupdel Delete a group. file. foreground.
!! Run the last command [group_name] shutdown [hh:mm] Schedule a system
again. more [file_name] Display contents of a file shutdown. lsof List files opened by running
sudo groupmod -n Modify a user group page by page. processes.
exit Log out of the current [new_name] [old_name] (change group name). shutdown now Shut down the system
session. less [file_name] Show the contents of a file immediately. trap "[commands]" Catch a system error
sudo [command] Temporarily elevate user with navigation. [signal] signal in a shell script.
privileges to superuser or modprobe Add a new kernel module. Executes provided
Searching root. nano [file_name] Open or create a file using [module_name] commands when the signal
the nano text editor. is caught.
find [path] -name Find files and su - [user_name] Switch the user account or dmesg Show bootup messages.
[search_pattern] directories that match the become a superuser. vi [file_name] Open or create a file using wait Pause the terminal or a
specified pattern in a vim [file_name] the Vi/Vim text editor. Bash script until a running
specified location. chgrp [group_name] [file/ Change file or directory Network process is completed.
directory] group. gpg -c [file_name] Encrypt a file.
find [path] -size [+100M] See files and directories ip addr show List IP addresses and nohup [command] & Run a Linux process in the
larger than a specified size gpg [file_name].gpg Decrypt an network interfaces. background.
in a directory. SSH Login encrypted .gpg file.
ip address add Assign an IP address to
grep [search_pattern] Search for a specific ssh [user_name]@[host] Connect to a remote wc -w [file_name] Show the number of [IP_address] interface eth0.
Hardware Information
[file_name] pattern in a file with grep. host as a user via SSH. words, lines, and bytes in a
file. ifconfig Display IP addresses of all lscpu See CPU information.
grep -r [search_pattern] Recursively search for a ssh [host] Securely connect to a network interfaces.
[directory_name] pattern in a directory. host via SSH default ls | xargs wc List the number of lines/ lsblk See information about
port 22. words/characters in each ping [remote_host] Ping remote host. block devices.
locate [name] Locate all files and file in a directory.
directories related to a ssh -p [port] Connect to the host netstat -pnltu See active (listening) ports lspci -tv Show PCI devices in a tree-
particular name. [user_name]@[host] using a particular port. cut -d [delimiter] Cut a section of a file and with the netstat command. like diagram.
[file_name] print the result to standard
which [command] Search the command ssh-keygen Generate SSH key pairs. output. netstat -tuln Show TCP and UDP ports lsusb -tv Display USB devices in a
path in and their programs. tree-like diagram.
the $PATH environment sudo service sshd start Start SSH [data] | cut -d [delimiter] Cut a section of piped data
variable. server daemon. and print the result to whois [domain_name] Display more information lshw List hardware configuration
standard output. about a domain. information.
whereis [command] Find the source, binary, scp [file_name] Securely copy
and manual page for a [user_name]@[host]:[rem files between local and shred -u [file_name] Overwrite a file to prevent dig [domain_name] Show DNS information cat /proc/cpuinfo Show detailed CPU
command. ote_path] remote systems via SSH. its recovery, then delete it. about a domain using information.
the dig command.
awk '[search_pattern] Print all lines matching a sftp [user_name]@[host] Interactive file transfer diff [first_file] Compare two files and cat /proc/meminfo View detailed system
{print $0}' [file_name] pattern in a file. See also over encrypted SSH [second_file] display differences. dig -x [domain_name] Do a reverse DNS lookup memory information.
the gawk command, the session on the domain.
GNU version of awk. using SFTP protocol. source [file_name] Read and execute the file cat /proc/mounts See mounted file systems.
content in the current shell. dig -x [IP_address] Do a reverse DNS lookup of
sed 's/[old_text]/ Find and replace text in a telnet [host] Connect to the host an IP address. free -h Display free and used
[new_text]/' [file_name] specified file. via Telnet default port [command] | tee Store the command output memory.
23. [file_name] >/dev/null in a file and skip the host [domain_name] Perform an IP lookup for a
terminal output. domain. sudo dmidecode Show hardware information
Directory Navigation from the BIOS.
File Permissions Disk Usage hostname -I Show the local IP address
ls List files and directories in hdparm -i /dev/ Display disk data
the current directory. nslookup Receive information about [device_name] information.
chmod 777 [file_name] Assign read, write, and df -h Check free and used
space on mounted [domain_name] an internet domain.
execute file permission to hdparm -tT /dev/ Conduct a read speed test
ls -a List all files and directories everyone (rwxrwxrwx). systems.
in the current directory . [device_name] on the device/disk.
(shows hidden files).
File Compression
chmod 755 [file_name] Give read, write, and df -i Show free inodes on
badblocks -s /dev/ Test for unreadable blocks
execute permission to mounted file systems.
ls -l List files and directories in tar cf [archive.tar] [file/ Archive an existing file or [device_name] on the device/disk.
owner, and read and
long format. fdisk -l Display disk partitions, directory] directory.
execute permission to fsck /dev/[device_name] Run a disk check on an
group and others sizes, and types with the
pwd Show the directory you tar xf [archive.tar] Extract an archived file. unmounted disk or
(rwxr-xr-x). command.
are currently working in. partition.
du -ah See disk usage for all files tar czf [archive.tar.gz] Create a .gz compressed
chmod 766 [file_name] Assign full permission to
cd Change and directories. tar archive.
the owner, and read and Shell Commands
cd ~ directory to $HOME. write permission to the
du -sh Show disk usage of the gzip [file_name] Compress or
group and others
cd .. Move up one directory current directory. gunzip [file_name.gz] decompress .gz files. alias [alias- Create an alias for a
(rwxrw-rw-).
level. name]='[command]' command.
mount Show currently mounted bzip2 [file_name] Compress or decompress
chown [user_name] Change the ownership of
cd - Change to the previous file systems. bunzip2 [file_name.bz2] .bz2 files. watch -n [interval-in- Set a custom interval to
[file_name] a file with chown
directory. command. seconds] [command] run a user-defined
findmnt Display target mount command.
cd [directory_path] Change location to a
File Transfer
chown Change the owner and point for all file systems.
specified directory. [user_name]:[group_nam group ownership of a file. sleep [time-interval] && Postpone the
scp [source_file] Copy a file to a server [command] execution of a command.
e] [file_name] mount [device_path] Mount a device.
dirs Show current directory [user]@[remote_host]:[de directory securely.
[mount_point]
stack. stination_path] at [hh:mm] Create a job to be
Packages (Red Hat, CentOS, Fedora) executed at a certain time
Packages (Universal) rsync -a Synchronize the contents (Ctrl+D to exit prompt
Packages (Debian/Ubuntu) [source_directory] of a directory with a after command).
sudo yum install Install a package using [user]@[remote_host]:[de backup directory.
[package_name] the YUM package tar zxvf [file_name.tar.gz] Install software
sudo apt-get install Install an APT package stination_directory] man [command] Display a built-in
manager. cd [extracted_directory] from source code.
[package_name] using the apt-get manual for a command.
./configure make
package utility. wget [link] Download files from FTP
yum search [keyword] Find a package in the make install
or web servers. history Print the command
YUM repositories based
sudo apt install Install an APT package history used in the
on the provided keyword. sudo snap install Install a Snap package.
[package_name] using a newer APT curl -O [link] Transfer data to or from a terminal.
[package_name]
package manager. server with various
yum list installed List all packages installed protocols.
with YUM. sudo snap find [keyword] Search for a package in Variables
apt search [keyword] Search for a package in
the Snap store.
the APT repositories. ftp [remote_host] Transfer files between
yum info [package_name] Show package local and remote systems
sudo snap list List installed Snap let Assign an integer value to
information for a interactively using FTP.
apt list List packages installed "[variable_name]=[value]" a variable.
package. packages.
with APT.
sftp Securely transfer between export [variable_name] Export a Bash variable.
sudo dnf install Install a package using flatpak install Install a Flatpak package.
apt show Show information about a [user]@[remote_host] local and remote hosts
[package_name] the DNF package [package_name]
[package_name] package. using SFTP. declare [variable-name]= Declare a Bash variable.
manager.
flatpak search [keyword] Search for a Flatpak "[value]"
sudo dpkg -i Install a .deb package with
sudo rpm -i Install a .rpm package application in repositories.
[package_name.deb] the Debian package set List the names of all the
[package_name.rpm] from a local file.
manager. shell variables and
flatpak list List installed Flatpack
packages. functions.
sudo dpkg -l List packages installed
with dpkg. unset [variable_name] Remove an environment
variable.

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


variable.

You might also like