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

Linux Commands Cheat Sheet GitHack

Linux Commands Cheat Sheet GitHack

Uploaded by

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

Linux Commands Cheat Sheet GitHack

Linux Commands Cheat Sheet GitHack

Uploaded by

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

Linux Commands Cheat Sheet

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

File Commands
Command Description

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:
pwd Show directory you are currently working in
mkdir [directory] Create a new directory
rm [file_name] Remove a file
rm -r [directory_name] Remove a directory recursively
Recursively remove a directory without requiring
rm -rf [directory_name]
confirmation
cp [file_name1] [file_name2] Copy the contents of one file to another file
Recursively copy the contents of one file to a second
cp -r [directory_name1] [directory_name2]
file
Rename [file_name1] to [file_name2] with the
mv [file_name1] [file_name2]
command
ln -s /path/to/[file_name] [link_name] Create a symbolic link to a file
touch [file_name] Create a new file using touch
more [file_name] Show the contents of a file
cat [file_name] or use the cat command
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
Command Description

Cut a section of a file and print the result to standard


cut -d[delimiter] [filename]
output
Cut a section of piped data and print the result to
[data] \| cut -d[delimiter]
standard output
awk '[pattern] {print $0}' [filename] Print all lines matching a pattern in a file
diff [file1] [file2] Compare two files and display differences
source [filename] Read and execute the file content in the current shell
Store the command output in a file and skip the
[command] \| tee [filename] >/dev/null
terminal output

Searching
Command Description

grep [pattern] [file_name] Search for a specific pattern in a file with grep
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] -name [a] specified location [/folder/location] by using the find
command:
find [/folder/location] -size
[+100M] See files larger than a specified size [+100M] in a folder:

Directory Navigation
Command Description

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

File Transfer
Command Description

Copy a file to a server directory securely using the Linux scp


scp [file_name.txt] [server/tmp]
command
Synchronize the contents of a directory with a backup
rsync -a [/your/directory] [/backup/]
directory using the rsync command

Users and Groups


Command Description

id See details about the active users


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

Package management
Command Description

List all installed packages with


yum list installed
yum
Find a package by a related
yum search [keyword]
keyword
Show package information and
yum info [package_name]
summary
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
rpm -i [package_name.rpm]
local file
rpm -e [package_name.rpm] Remove an .rpm package
Install an .deb package from a
dpkg -i [package_name.deb]
local file
dpkg -r [package_name.deb] Remove an .deb package
tar zxvf [source_code.tar.gz] && cd [source_code] && Install software from source
./configure && make && make install code

Process management
Command Description

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
fg Bring the most recently suspended job to the foreground
fg [job] Bring a particular job to the foreground
lsof List files opened by running processes
trap "[commands-to-execute-on-trapping]"
[signal] Catch a system error signal in a shell script

Pause terminal or a Bash script until a running process


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

System Management and Information


Command Description

uname -r Show system information


uname -a See kernel release information
uptime Display how long the system has been running, including load average
hostname See system hostname
hostname -i Show the IP address of the system
last reboot List system reboot history
date See current time and date
timedatectl Query and change the system clock with
cal Show current calendar (month and day)
whoami See which user you are using
finger [username] Show information about a particular user
ulimit [flags] [limit] View or limit system resource amounts
shutdown [hh:mm] Schedule a system shutdown
shutdown now Shut Down the system immediately

Disk Usage
Command Description

df -h See free and used space on mounted systems


df -i Show free inodes on mounted filesystems
fdisk -l Display disk partitions, sizes, and types with the 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_point] Mount a device

SSH Login
Command Description

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 Description

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

Network
Command Description

ip addr show List IP addresses and network interfaces


ip address add [IP_address] Assign an IP address to interface eth0
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
Command Description

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-name] Receive information about an internet domain
Save a remote file to your system using the filename that corresponds to
curl -O [file-url]
the filename on the server

Variables
Command Description

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
set List the names of all the shell variables and functions
echo $[variable-name] Display the value of a variable

Shell Command Management


Command Description

alias [alias-name]='[command]' Create an alias for a 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 exit
at [hh:mm]
prompt after you type in the command)
man [command] Display a built-in manual for a command
history Print the history of the commands you used in the terminal

Linux Keyboard Shortcuts


Command Description

Ctrl + C Kill process running in the terminal


Stop current process - The process can be resumed in the foreground with fg or in the background
Ctrl + Z
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
Command Description

Ctrl + Y Paste from clipboard


Ctrl + R Recall last command that matches the provided characters
Ctrl + O Run the previously recalled command
Ctrl + G Exit command history without running a command
!! Run the last command again
`Ctrl + D Log out of current session

Hardware information
Command Description

dmesg Show bootup messages


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

You might also like