Top 50 Essential Linux Commands

By Anurag Singh

Updated on Aug 29, 2024

Top 50 Essential Linux Commands

Linux is a powerful and flexible operating system, widely used for servers, desktops, and development environments. Whether you're a beginner or an experienced user, mastering key Linux commands can significantly enhance your productivity. This tutorial will guide you through the top 50+ Linux commands you must know, explaining their usage and options.

1. ls - List Directory Contents

The ls command is used to list files and directories within the current directory.

ls
ls -l: Lists in long format showing permissions, ownership, and size.
ls -a: Lists all files, including hidden files (those starting with .).

2. free - Display Memory Usage

The free command shows memory usage.

free -h

3. pwd - Print Working Directory

The pwd command displays the current directory's full path.

pwd

4. mkdir - Make Directory

The mkdir command creates a new directory.

mkdir new_directory
mkdir -p /path/to/directory: Creates nested directories.

5. rmdir - Remove Directory

The rmdir command removes an empty directory.

rmdir directory_name

6. rm - Remove Files or Directories

The rm command deletes files and directories.

rm file_name
rm -r directory_name: Recursively deletes a directory and its contents.
rm -f file_name: Forces deletion without confirmation.

7. cp - Copy Files or Directories

The cp command copies files or directories.

cp source_file destination
cp -r source_directory destination: Recursively copies a directory.

8. mv - Move or Rename Files or Directories

The mv command moves or renames files or directories.

mv old_name new_name
mv file_name /path/to/destination: Moves a file to a different directory.

9. touch - Create an Empty File

The touch command creates an empty file or updates the timestamp of an existing file.

touch new_file

10. cat - Concatenate and Display Files

The cat command displays the content of a file.

cat file_name
cat file1 file2: Concatenates multiple files and displays the output.

11. echo - Print Text to the Terminal

The echo command displays text or outputs data to a file.

echo "Hello, World!"
echo "text" > file_name: Writes text to a file, overwriting its content.

12. head - View the First Lines of a File

The head command displays the first 10 lines of a file by default.

head file_name
head -n 20 file_name: Displays the first 20 lines.

13. tail - View the Last Lines of a File

The tail command displays the last 10 lines of a file by default.

tail file_name
tail -n 20 file_name: Displays the last 20 lines.
tail -f file_name: Continuously displays new lines as they are added.

14. grep - Search Text in Files

The grep command searches for patterns within files.

grep "pattern" file_name
grep -r "pattern" directory_name: Recursively searches within a directory.

15. find - Search for Files and Directories

The find command searches for files and directories based on various criteria.

find /path -name "file_name"
find /path -type d -name "dir_name": Searches for directories.

16. locate - Find Files by Name

The locate command quickly finds files by name.

locate file_name
locate -i file_name: Case-insensitive search.

17. chmod - Change File Permissions

The chmod command modifies the permissions of a file or directory.

chmod 755 file_name
chmod +x file_name: Makes a file executable.

18. chown - Change File Ownership

The chown command changes the ownership of a file or directory.

chown user:group file_name
chown -R user:group directory_name: Recursively changes ownership.

19. df - Display Disk Space Usage

The df command shows the disk space usage of file systems.

df -h
df -h /path: Shows usage for a specific path.

20. du - Estimate File Space Usage

The du command estimates file space usage.

du -h
du -sh directory_name: Shows total usage of a directory.

21. ps - Display Running Processes

The ps command displays currently running processes.

ps aux
ps -ef: Another common format to view processes.

22. top - Real-Time Process Monitoring

The top command shows real-time system processes.

top
Press q to quit.

23. kill - Terminate Processes

The kill command sends signals to terminate processes.

kill process_id
kill -9 process_id: Forcefully kills a process.

24. pkill - Terminate Processes by Name

The pkill command terminates processes based on name.

pkill process_name
pkill -9 process_name: Forcefully kills processes.

25. killall - Terminate All Instances of a Process

The killall command kills all instances of a process.

killall process_name

26. ssh - Secure Shell for Remote Login

The ssh command connects to remote servers securely.

ssh user@remote_host
ssh -p port_number user@remote_host: Connects on a different port.

27. scp - Secure Copy for File Transfer

The scp command securely copies files between hosts.

scp file_name user@remote_host:/path
scp -r directory_name user@remote_host:/path: Copies directories.

28. rsync - Remote Sync

The rsync command synchronizes files and directories between locations.

rsync -avz source destination
rsync -avz source user@remote_host:/path: Synchronizes with a remote host.

29. tar - Archive Files

The tar command creates and extracts archives.

tar -cvf archive_name.tar file_or_directory
tar -xvf archive_name.tar: Extracts an archive.

30. zip/unzip - Compress and Decompress Files

The zip command compresses files, and unzip decompresses them.

zip archive_name.zip file_or_directory
unzip archive_name.zip

31. wget - Download Files from the Internet

The wget command downloads files from the internet.

wget http://example.com/file
wget -c http://example.com/file: Resumes an incomplete download.

32. curl - Transfer Data from or to a Server

The curl command transfers data from or to a server.

curl http://example.com
curl -O http://example.com/file: Downloads a file.

33. hostname - Display or Set the System's Hostname

The hostname command shows or sets the system’s hostname.

hostname
hostnamectl set-hostname new_hostname: Sets a new hostname.

34. uname - Display System Information

The uname command shows system information.

uname -a
uname -r: Displays the kernel version.

35. whoami - Display Current User

The whoami command shows the current logged-in user.

whoami

36. sudo - Execute a Command as Superuser

The sudo command executes a command with superuser privileges.

sudo command
sudo -i: Opens a superuser shell.

37. apt-get - Package Management for Debian-based Distributions

The apt-get command installs, updates, and removes packages on Debian-based systems.

sudo apt-get update
sudo apt-get install package_name
sudo apt-get remove package_name: Removes a package.
38. yum - Package Management for RHEL-based Distributions

The yum command manages packages on RHEL-based systems.

sudo yum update
sudo yum install package_name
sudo yum remove package_name: Removes a package.

39. dnf - Updated Package Management for RHEL-based Distributions

The dnf command is a modern replacement for yum on RHEL-based systems.

sudo dnf update
sudo dnf install package_name

40. service - Control System Services

The service command starts, stops, and manages system services.

sudo service service_name start
sudo service service_name stop: Stops a service.

41. systemctl - Control the System and Service Manager

The systemctl command manages systemd services and configurations.

sudo systemctl start service_name
sudo systemctl enable service_name: Enables a service to start at boot.

42. passwd - Change User Password

The passwd command changes the password of a user.

passwd
sudo passwd user_name: Changes the password for another user.

43. useradd - Add a New User

The useradd command creates a new user.

sudo useradd new_user
sudo useradd -m new_user: Creates a new user with a home directory.

44. usermod - Modify a User Account

The usermod command modifies a user account.

sudo usermod -aG group_name user_name
sudo usermod -l new_name old_name: Changes a user's username.

45. userdel - Delete a User Account

The userdel command deletes a user account.

sudo userdel user_name
sudo userdel -r user_name: Deletes a user and their home directory.

46. groupadd - Add a New Group

The groupadd command creates a new group.

sudo groupadd new_group

47. groupdel - Delete a Group

The groupdel command deletes a group.

sudo groupdel group_name

48. crontab - Schedule Jobs

The crontab command schedules tasks to run at specific times.

crontab -e
crontab -l: Lists scheduled jobs.

49. alias - Create Shortcuts for Commands

The alias command creates shortcuts for commands.

alias ll='ls -l'
unalias ll: Removes an alias.

50. history - View Command History

The history command displays the list of previously executed commands.

history
!number: Re-executes a command from history by its number.

Conclusion

In this guide, we’ve covered some of the most essential Linux commands that every user should know. These commands are the building blocks for managing and interacting with your Linux system effectively. Whether you're a beginner or an experienced user, mastering these commands will greatly enhance your productivity and confidence when working in a Linux environment. Remember, the power of Linux lies in its versatility and control, and by familiarizing yourself with these tools, you’ll be well-equipped to harness the full potential of your system. Keep practicing, and don't hesitate to explore more advanced commands as you grow more comfortable with the basics. Happy Linuxing!

Checkout our dedicated servers and KVM VPS