Linux Commands Cheat Sheet

Suraj barikSuraj barik
4 min read

FILE AND DIRECTORY COMMANDS:

Commands

Description

ls -al

List all files in a long listing (detailed) format

pwd

Display the present working directory

rm -r directory

Remove the directory and its contents recursively

rm file

Remove (delete) file

mkdir directory

Create a directory

rm -rf directory

Forcefully remove the directory recursively

cp file1 file2

Copy file1 to file2

cp -r source_directory destination

Copy source_directory recursively to destination. If a destination exists, copy source_directory into a destination, otherwise create a destination with the contents of source_directory.

touch file

Create an empty file or update the access and modification times of file.

mv file1 file2

Rename or move file1 to file2. If file2 is an existing directory, move file1 into directory file2

Rename or move file1 to file2. If file2 is an existing directory, move file1 into directory file2

cat file

View the contents of file

head file

Display the first 10 lines of file .

tail file

Display the last 10 lines of file

tail -f file

Display the last 10 lines of file and "follow" the file as it grows.

File Permission commands:

SYSTEM INFORMATION:

uname -aDisplay Linux system information
uname -rDisplay kernel release information
cat /etc/os-releasehow operating system information such as distribution name and version
uptimeShow how long the system has been running + load
hostnameShow system host name
hostname -IDisplay all local IP addresses of the host.
dateShow the current date and tim
whoamiWho you are logged in as

DISK USAGE:

df -h

Show free and used space on mounted filesystems

df -i

Show free and used inodes on mounted filesystems

du -sh

Display the total disk usage of the current director

du -ah

Display disk usage for all files and directories in human-readable format

fdisk -l

Display disks partitions sizes and types

DIRECTORY NAVIGATION

cd ..To go up one level of the directory tree. (Change into the parent directory.)
cdGo to the $HOME directory
cd ../..go back two-step back

USER INFORMATION AND MANAGEMENT:

idDisplay the user and group ids of your current user.
lastDisplay the last users who have logged onto the system.
whoShow who is logged into the system.
wShow who is logged in and what they are doing.
groupadd testCreate a group named "test".
useradd -c "John Smith" -m johnCreate an account named john, with a comment of "John Smith" and create the user's home directory.
userdel johnDelete the john account.
usermod -aG sales johnAdd the john account to the sales group

Process command :

psDisplay your currently running processes
ps -efDisplay all the currently running processes on the system.
ps -efgrep processnameDisplay process information for process name
kill pidKill process with process ID of pid
killall processnameKill all processes named processname

NETWORKING:

ip aDisplay all network interfaces and IP address
ping hostSend ICMP echo request to host
whois domainDisplay whois information for domain
host domainDisplay DNS IP address for domain
hostname -IDisplay all local IP addresses of the host.
grep pattern fileSearch for pattern in file
grep -r pattern directorySearch recursively for pattern in directory
find /home/john -name 'prefix*'Find files in /home/john that start with "prefix".
locate nameFind files and directories by name

Thank you for reading! I hope you find this article helpful. Happy Learning :)

0
Subscribe to my newsletter

Read articles from Suraj barik directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Suraj barik
Suraj barik

I'm Suraj Barik Aspiring DevOps Engineer with Hands-on experience in Automating,Shell Scripting, Supporting in AWS, management, CI/CD, and DevOps processes.