50+ Essential Linux Commands Every User Should Know
Want to master the command line? This guide covers 50+ essential Linux commands, perfect for beginners and experienced users alike. Quickly navigate, manage files, and control your system with these powerful tools.
Why Learn Linux Commands?
- Efficiency: Execute tasks faster than with a graphical interface.
- Automation: Script repetitive tasks for increased productivity.
- Control: Fine-tune your system settings and software.
- Versatility: Manage servers, develop software, and troubleshoot problems.
Let's dive into the must-know Linux commands that will transform your command-line experience.
Core File and Directory Management Commands
These are the workhorses of the Linux command line. Learn these to navigate and manipulate your files and directories effortlessly.
1. ls
: List Files and Directories
See what's inside a directory with ls
.
ls
: Lists files and directories in the current directory.ls -l
: Provides detailed information, including permissions and sizes.ls -a
: Shows hidden files and directories (those starting with a dot).
2. pwd
: Print Working Directory
Not sure where you are in the file system? pwd
shows your current location.
- Simply type
pwd
to display the full path of your current directory.
3. cd
: Change Directory
Move between directories with cd
.
cd directory_name
: Navigates to the specified directory.cd ..
: Moves up one level to the parent directory.cd
: Returns to your home directory.
4. mkdir
: Make Directory
Create new directories with mkdir
.
mkdir directory_name
: Creates a new directory with the given name.mkdir -p path/to/new/directory
: Creates a nested directory structure.
5. cp
: Copy Files
Duplicate files with cp
.
cp source_file destination_file
: Copies a file to a new location.cp -r source_directory destination_directory
: Recursively copies an entire directory.
6. mv
: Move or Rename Files
Relocate or rename files with mv
.
mv source_file destination_file
: Moves a file to a new location.mv old_name new_name
: Renames a file.
7. rm
: Remove Files and Directories
Delete files and directories with rm
. Be careful – this is permanent!
rm file_name
: Deletes a file.rm -r directory_name
: Recursively deletes a directory and its contents.rm -i file_name
: Prompts for confirmation before deleting.
8. touch
: Create Empty Files
Create new, empty files with touch
.
touch file_name
: Creates an empty file.- Also updates the timestamp of existing files if they exist.
Viewing and Manipulating File Content: Essential Linux Commands
These commands allow you to peek inside files and manipulate their contents from the command line.
9. cat
: Concatenate and Print Files
Display the entire content of a file.
cat file_name
: Shows the file's content on the terminal.
10. echo
: Print Text
Display text on the terminal.
echo "Hello, world!"
: Prints the message "Hello, world!".echo $VARIABLE
: Displays the value of an environment variable.
11. less
: View Files Page by Page
Open files in a scrollable, page-by-page format.
less file_name
: Opens the file for viewing.- Use the spacebar to scroll down,
b
to scroll back, andq
to quit.
12. head
: View the Beginning of a File
Display the first few lines of a file.
head file_name
: Shows the first 10 lines.head -n 20 file_name
: Shows the first 20 lines.
13. tail
: View the End of a File
Display the last few lines of a file (useful for logs).
tail file_name
: Shows the last 10 lines.tail -f file_name
: Continuously displays new lines as they are added to the file.
14. grep
: Search for Text
Search for specific patterns within files. This is one of the most powerful Linux commands for filtering data.
grep "pattern" file_name
: Finds lines containing the specified pattern.grep -i "pattern" file_name
: Performs a case-insensitive search.grep -r "pattern" directory_name
: Recursively searches for the pattern within a directory.
15. sort
: Sort File Content
Arrange lines of text in a specific order.
sort file_name
: Sorts the lines alphabetically.sort -n file_name
: Sorts numerically if the lines contain numbers.
System Information and Management: Know Your Linux System
Get insights into your system's configuration and manage running processes.
16. uname
: System Information
Display basic information about your operating system.
uname -a
: Shows all system information.uname -r
: Displays the kernel release.
17. whoami
: Current User
Print the username of the currently logged-in user.
- Simply type
whoami
to see your username.
18. ps
: Process Status
View a snapshot of currently running processes.
ps aux
: Shows all processes running on the system.ps -ef
: Comprehensive process list.
19. top
: Real-Time Process Monitoring
Display a dynamic, real-time view of running processes and system resource usage.
- Type
top
to start the monitoring tool. - Press
q
to quit.
20. kill
and killall
: Terminate Processes
Terminate running processes.
kill process_id
: Sends a signal to terminate the process with the given ID (found usingps
ortop
).killall process_name
: Kills all processes with the specified name.
21. df
: Disk Space Information
Display disk space usage.
df -h
: Shows disk space usage in a human-readable format (e.g., GB, MB).
22. du
: Directory Space Usage
Estimate file space usage.
du -sh directory_name
: Shows the total size of a directory in a human-readable format.
23. free
: Memory Usage
Display the amount of free and used memory in the system.
free -m
: Shows memory usage in megabytes.
24. ifconfig
or ip addr
: Network Interface Configuration
Display network interface information. ip addr
is the modern replacement for ifconfig
.
ifconfig
: (May require installation)ip addr
: Lists network interfaces and their IP addresses.
25. ping
: Test Network Connectivity
Check if a network host is reachable.
ping google.com
: Sends packets to Google's server and measures the response time.
26. netstat
: Network Statistics
Display network connections, routing tables, interface statistics, and more.
netstat -tulnp
: Shows listening ports.
27. ss
: Socket Statistics
Another tool to investigate sockets. ss
is intended to be the replacement for netstat
.
ss -tulnp
: Displays listening ports via sockets.
Permissions and Ownership: Secure Your Files
Control who can access and modify your files.
28. chmod
: Change File Permissions
Modify file permissions (read, write, execute) for the owner, group, and others.
chmod 755 file_name
: Sets read, write, and execute permissions for the owner, and read and execute for the group and others.
29. chown
: Change File Ownership
Change the owner and group associated with a file.
chown user:group file_name
: Changes the owner touser
and the group togroup
.
Archiving and Compression: Managing Large Files
Reduce file sizes and create archives for easy storage and transfer.
30. tar
: Tape Archive
Create and extract archive files.
tar -cvf archive.tar files
: Creates an archive namedarchive.tar
containing the specified files.tar -xvf archive.tar
: Extracts the contents ofarchive.tar
.tar -czvf archive.tar.gz files
: Creates a compressed archive (gzip).tar -xzvf archive.tar.gz
: Extracts a compressed archive.
31. gzip
and gunzip
: Compress and Decompress Files
Compress individual files.
gzip file_name
: Compresses the file tofile_name.gz
.gunzip file_name.gz
: Decompresses the file.
32. zip
and unzip
: Create and Extract Zip Archives
Work with ZIP archives.
zip archive_name.zip files
: Creates a ZIP archive containing the specified files.unzip archive_name.zip
: Extracts the contents of the ZIP archive.
Package Management: Install and Update Software
Install, update, and remove software packages (commands vary depending on the Linux distribution).
33. apt
(Debian/Ubuntu): Advanced Package Tool
sudo apt update
: Updates the package lists.sudo apt upgrade
: Upgrades installed packages.sudo apt install package_name
: Installs a new package.sudo apt remove package_name
: Removes a package.
34. yum
(Red Hat/CentOS): Yellowdog Updater, Modified
sudo yum update
: Updates the system.sudo yum install package_name
: Installs a package.sudo yum remove package_name
: Removes a package.
35. dnf
(Fedora): Dandified Yum
sudo dnf update
: Updates the system.sudo dnf install package_name
: Installs a package.sudo dnf remove package_name
: Removes a package.
36. pacman
(Arch Linux): Package Manager
sudo pacman -Syu
: Synchronizes package databases and updates the system.sudo pacman -S package_name
: Installs a package.sudo pacman -R package_name
: Removes a package.
Networking and Remote Access
Connect to remote servers and manage network configurations.
37. ssh
: Secure Shell
Connect to a remote server securely.
ssh user@remote_host
: Connects to the specified host as the specified user.
38. scp
: Secure Copy
Securely copy files between your local machine and a remote server.
scp file user@remote_host:/path/to/destination
: Copies a file to the remote server.
39. wget
: Web Get
Download files from the internet.
wget URL
: Downloads the file from the specified URL.
System Administration and Control
These commands provide administrative control over your Linux system.
40. sudo
: Super User Do
Execute commands with elevated privileges.
sudo command
: Runs the specified command as the superuser (root).
41. service
: Manage Services
Start, stop, restart, and manage 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.
42. systemctl
: Control the Systemd System and Service Manager
Control the systemd system and service manager, used on many modern Linux distributions.
sudo systemctl start service_name
: Starts a service.sudo systemctl stop service_name
: Stops a service.sudo systemctl restart service_name
: Restarts a service.sudo systemctl status service_name
: Shows the status of a service.
43. firewall-cmd
: Dynamic Firewall Manager
Control the systemd system and service manager, used on many modern Linux distributions.
- Before usage please check the status
sudo firewall-cmd --state
- List all open ports
sudo firewall-cmd --list-all
- To open a port
sudo firewall-cmd --add-port=8080/tcp --permanent
- To reload the firewalld
sudo firewall-cmd --reload
- To remove a port
sudo firewall-cmd --remove-port=8080/tcp --permanent
Other Useful Linux Commands
These commands don't fit neatly into the above categories but are still valuable to know.
44. alias
: Create Command Shortcuts
Create custom shortcuts for frequently used commands.
alias la='ls -la'
: Creates an aliasla
for the commandls -la
. Typela
to executels -la
.
45. history
: Command History
View a list of previously executed commands.
- Type
history
to see your command history. - Use
!number
to re-execute a command from the history list.
46. man
: Manual Pages
Access the online manual pages for commands.
man command_name
: Displays the manual page for the specified command.
47. cal
: Calendar
View a calendar in the terminal.
- Type
cal
to see the current month's calendar.
48. find
: Find Files
Search for files based on various criteria.
find . -name "file_name"
: Finds files with the specified name in the current directory and its subdirectories.
49. locate
: Locate Files
Quickly find files by name (requires a pre-built database – run sudo updatedb
to update it).
locate file_name
: Finds files with the specified name.
50. diff
: Compare Files
Show the differences between two files.
diff file1 file2
: Displays the differences between the two files.
51. wc
: Word Count
Count the number of lines, words, and characters in a file.
wc file_name
: Displays the counts for the file.wc -l file_name
: Displays only the line count.
Mastering Linux Commands: Next Steps
This list provides a solid foundation for using the Linux command line. To further enhance your skills:
- Practice Regularly: The more you use these commands, the more comfortable you'll become.
- Experiment: Try different options and combinations of commands.
- Read Manual Pages: Use
man command_name
to learn about advanced features and options. - Explore Online Resources: Numerous websites and tutorials offer in-depth explanations and examples.
By mastering these essential Linux commands, you'll unlock a new level of control and efficiency in your computing experience.