Linux Commands Cheat Sheet: Your Complete Reference

Linux Commands Cheat Sheet

The Linux command line interface offers complete control over your Linux system. Although many Linux commands may seem scary or confusing initially, learning the most basic yet powerful and useful commands can make your server management significantly more manageable. This cheat sheet is designed to simplify your journey through Linux, providing a comprehensive reference to the most essential commands. Whether managing files, monitoring system performance, or configuring network settings, having these commands at your fingertips will enhance efficiency and productivity. We’ll share some of the most commonly used and valuable tips in our Linux commands cheat sheet. To begin with, we’ll break them down into easy-to-navigate sections. Let’s get into it.

1. Navigating the file system

pwd short for Print Working Directory, shows that current directory path you are currently in
cd /some/directory/path – change directory
ls – lists files and directories
ls -al – lists all files and directories in detailed format, including the hidden files or directories.
mkdir – create a new directory
touch filename – creates a new empty file
mv file /newpath/file – move file or directory to a new path
mv directory1 newdirectory – rename file or directory
rm somefile – remove file
rm -r newdir – remove directory and everything inside the directory recursively
cat filename – display the content of the file
grep file – search for pattern in the text file
w – show which users are online
adduser – create a new user account

2. Managing Linux users and permissions

userdel - delete a user account
usermod -aG - add a user to a group
groupadd – create a new group
passwd – change currents user password
passwd username - change the password for a specific user
chown username:username file – change the user and group ownership of the file
chown -R username:username file – change the user and group of the directory and every file and directory inside that directory recursively
chmod 755 file – set read, write and execute file permissions to file owner and set read and execute permissions for the group and others.
chmod -R 751 directory – set read, write and execute file permissions for the owner, read and execute for the group and only execute for everyone.

3. Processes

ps aux – shows all active processes in user-friendly format with detailed information such as CPU and memory usage, PID
top – display and manage all processes in real time
htop – same as the top command with more features for managing the processes
kill PID - kills the process by specifying the ID of the process
lsof -p PID – list all files opened by the process with specified PID

4. Disk Usage

df -h – show free and used space on all mounted filesystems
df -i – shows the number of free and used inodes on all mounted filesystems
du -chx – shows the size of the current directory.
fdisk -l – displays all partitions on the system

5. Networking

ip a – list IP addresses assigned to every interface
ifconfig – displays detailed information for each network interface
tcpdump -i any – capture network traffic on all network interfaces until stopped
iftop – real-time network bandwidth monitoring tool
nmap -p 1-2000 HOST - scan for open ports from 1 to 2000th port on the specified host

6. File transfer and compression

rsync -av /path/to/source/file.txt /path/to/destination/ - copy file from location to another
rsync -av -e ssh /path/to/source/dir/ user@remote_host:/path/to/destination/ - copy file to a remote location
rsync -avz /path/to/source/dir/ /path/to/destination/dir/ - compress data during transfer
tar -cvf archive.tar file1.txt dir1 – create an archive from the file1.txt and directory dir1
tar -czvf archive_name.tar.gz file1.txt dir1 directory_name – create a compresed archive from the file1.txt and directory dir1
tar -cvf archive.tar file1.txt dir1 – create an archive from the file1.txt and directory dir1
tar -czvf archive_name.tar.gz file1.txt dir1 directory_name – create a compresed archive from the file1.txt and directory dir1
tar -xvf archive.tar – extract archive.tar
tar -xzvf archive_name.tar.gz – extract compressed archive archive_name.tar.gz

Conclusion

These are the most commonly used Linux commands to help you manage your users and permissions and navigate through directories. Also, you can now check the disk usage and network interfaces and display and manage processes on your system. If you have an interesting Linux command that you frequently use and you want to share it with us, please write it in the comments below. Thanks for following up, and we hope you helped you learn more and made your life easier while managing your Linux systems. If you’re still uncomfortable with Linux operations or want a more practiced hand in fine-tuning your server, just let our Linx admins know. All of our staff are level 3 support Linux engineers, and so long as you get one of our Linux VPS hosting plans, they’re at your disposal 24/7.

Leave a Comment