50+ Essential Linux Commands: Your Ultimate Cheat Sheet
Are you ready to navigate the Linux command line like a pro? This guide covers 50+ essential Linux commands you need to know, whether you're a beginner or an experienced user. Master these basic Linux commands and boost your productivity.
Why Learn Linux Commands?
- Efficiency: Quickly manage files, directories, and system processes.
- Control: Precise control over your Linux environment.
- Automation: Script repetitive tasks for increased efficiency.
Prerequisites
This guide assumes you have access to a Linux system. An Ubuntu server is ideal, but any modern distribution will work.
Top Linux Commands You Must Know
1. ls
- List Directory Contents
See what's inside your current directory with the ls
command. It's one of the most frequently used Linux commands.
ls
: Lists all files and directories.ls -l
: Displays detailed information (permissions, size, etc.).ls -a
: Shows hidden files.
2. pwd
- Print Working Directory
Never get lost again! pwd
instantly shows your current location in the file system. This is one of the must-know Linux commands for navigation.
3. cd
- Change Directory
Navigate through directories with ease using cd
.
cd directory_name
: Move into a specific directory.cd ..
: Go up one level.cd
: Return to your home directory.
4. mkdir
- Make Directory
Create new directories effortlessly. This is a crucial basic Linux command for organizing your files.
mkdir directory_name
: Creates a new directory.mkdir -p path/to/new/directory
: Creates nested directories.
5. cp
- Copy Files and Directories
Duplicate files and folders quickly.
cp source_file destination_file
: Copies a file.cp -r source_directory destination_directory
: Copies a whole directory recursively.
6. mv
- Move or Rename Files
Relocate files or give them a new name.
mv old_name new_name
: Renames the file.mv file_name destination_directory
: Moves to new directory.
7. rm
- Remove Files and Directories
Carefully delete files and directories, this essential Linux command is irreversible.
rm file_name
: Deletes a file.rm -r directory_name
: Deletes a directory and its contents. (Use with caution!)rm -i file_name
: Asks for confirmation before deleting.
8. touch
- Create Empty Files
Quickly create zero-byte files, often used for logs or as placeholders.
touch file_name
: Creates a new empty file.
9. ln
- Create Links/Shortcuts
Create symbolic or hard links to files.
ln -s original_file link_name
: Creates a symbolic link (shortcut). This is an important Linux command.
10. clear
- Clear the Terminal Screen
Clean up your terminal for better visibility. Just type clear
and press Enter.
1**. cat
- Concatenate and Display Files
Display the contents of one or more files on the terminal.
cat file_name
: Displays the content of the file.
12. echo
- Display a Line of Text
Print text or variables to the terminal.
echo "Hello, world!"
: Prints "Hello, world!" to the terminal.
13. less
- View File Contents One Page at a Time
View long files comfortably with page-by-page navigation.
less file_name
: Opens the file inless
.- Use the arrow keys to scroll.
- Press
q
to exit.
14. man
- Access Manual Pages
Get detailed help on any command. For example, man ls
opens the manual page for the ls
command. Mastering the man pages is important for all the basic Linux commands.
15. uname
- Print System Information
Get basic information about your operating system.
uname -a
: Displays all system information.
16. whoami
- Print Current User
Find out which user you are currently logged in as.
17. tar
- Archive Files
Compress and extract files and directories.
tar -czvf archive_name.tar.gz directory_name
: Creates a compressed archive.tar -xzvf archive_name.tar.gz
: Extracts an archive.
18. grep
- Search Text
Find specific strings within files or command outputs.
grep "search_term" file_name
: Searches for "search_term" in the file.
19. head
- Display the Beginning of a File
Show the first few lines of a file (default: 10 lines).
head file_name
: Displays the first 10 lines.head -n 20 file_name
: Displays the first 20 lines.
20. tail
- Display the End of a File
Show the last few lines of a file (default: 10 lines). Useful for monitoring log files.
tail file_name
: Displays the last 10 lines.tail -f file_name
: Continuously monitors the file for updates.
21. diff
- Find the Difference Between Two Files
Compares all the differences of two files, line by line.
diff file1.txt file2.txt
: Shows differences between the two files.
22. cmp
- Compare Two Files
Check if two files are identical. The cmp
command shows the first byte where the files differ.
cmp file1.txt file2.txt
23. comm
- Compare Two Sorted Files
Combines the functionality of the diff
and cmp
commands requiring both files to be pre-sorted.
comm file1.txt file2.txt
24. sort
- Sort Lines of Text
Sort lines in a file or command output.
sort file_name
: Sorts the lines in the file.
25. export
- Set Environment Variables
Set environment variables for the current session.
export VARIABLE_NAME="value"
: Set and expose the variable.
26. zip
- Compress Files into a ZIP Archive
Compress one or more files into a zip archive named with a .zip
extension.
zip file.zip file1.txt file2.txt
: Compresses specified files into file.zip archive
27. unzip
- Extract ZIP Archives
Extract the content of a .zip
archive.
unzip file.zip
28. ssh
- Secure Shell
Connect to a remote server securely.
ssh username@server_address
: Connects to the server.
29. service
- Manage System Services
Start, stop, or restart system services.
sudo service service_name start
: Starts a service.sudo service service_name stop
: Stops a service.sudo service service_name restart
: Restarts a service.
30. ps
- Display Processes
View currently running processes.
31. kill
and killall
- Terminate Processes
Terminate processes by PID (kill
) or name (killall
).
kill PID
: Kills the process with the specified PID.killall process_name
: Kills all processes with the given name.
32. df
- Disk Free Space
Show disk space usage.
df -h
: Displays disk space in human-readable format.
33. mount
- Mount File Systems
Mount file systems, such as USB drives or network shares.
34. chmod
- Change File Permissions
Modify file permissions to control access.
chmod 755 file_name
: Sets read, write, and execute permissions for the owner, read and execute for the group and others.
35. chown
- Change File Owner
Change the owner and group of a file.
sudo chown user:group file_name
: Changes the owner and group.
36. ifconfig
- Configure a Network Interface
Display network interfaces and IP addresses configuration.
ifconfig
: Displays a list of network interfaces and configurations.
37. traceroute
- Trace Route to Host
Shows the route packets take to a network host to detect network delay issues.
traceroute host_address
38. wget
- Download Files
Download files from the internet.
wget URL
: Downloads the file from the specified URL.
39. ufw
- Uncomplicated Firewall
A frontend for managing iptables
rules, making firewall configuration easier.
40. iptables
- Firewall Configuration
Configure the Linux firewall. iptables
is the base that other firewalls (like ufw
) interface with.
41. apt
, pacman
, yum
, rpm
- Package Managers
Manage software packages. The specific command depends on your Linux distribution.
sudo apt update && sudo apt upgrade
(Debian/Ubuntu)sudo pacman -Syu
(Arch Linux)sudo yum update
(CentOS/RHEL)
42. sudo
- Execute Commands as Superuser
Run commands with administrative privileges.
43. cal
- Display Calendar
View a calendar in the terminal. Just type cal
and press Enter.
44. alias
- Create Command Aliases
Create shortcuts for frequently used commands.
alias la='ls -la'
set up an alias forls -la
command.
45. dd
- Data Duplicator
Copy and convert data. Commonly used for creating bootable USB drives.
46. whereis
- Locate a Command
Find the binary, source, and manual pages for a command.
47. whatis
- Describe a Command
Get a brief description of what a command does.
48. top
- Display Linux Processes
View active processes in real-time, along with their CPU and memory usage.
49. useradd
and usermod
- Manage User Accounts
Add new user accounts or modify existing accounts. An indispensable part of Linux commands.
sudo useradd username
: Adds a new user.sudo usermod -aG groupname username
: Add a user to a group.
50. passwd
- Change Password
Create or update passwords for user accounts.
Next Steps
Congratulations! You've now got a solid foundation in essential Linux commands and basic Linux commands. Continue exploring, practice regularly, and dive deeper into specific commands as needed.