Top 50 Linux Commands With Examples
MontaF - Oct. 11, 2024
The Linux command line is a powerful tool for managing and interacting with the operating system. Whether you're a system administrator, developer, or casual user, knowing these commands will enhance your efficiency when using Linux.
1. pwd
(Print Working Directory)
Displays the current working directory.
pwd
2. cd
(Change Directory)
Changes the current directory.
cd /home/user/documents
3. ls
(List)
Lists files and directories in the current directory.
ls -l
4. mkdir
(Make Directory)
Creates a new directory.
mkdir new_folder
5. rmdir
(Remove Directory)
Removes an empty directory.
rmdir old_folder
6. rm
(Remove)
Removes files or directories.
rm file.txt # Remove file
rm -r folder_name # Remove directory with files
7. cp
(Copy)
Copies files or directories.
cp source.txt destination.txt
cp -r folder1/ folder2/
8. mv
(Move)
Moves or renames files and directories.
mv file.txt /new_directory/ # Move file
mv old_name.txt new_name.txt # Rename file
9. touch
Creates an empty file or updates the timestamp of a file.
touch newfile.txt
10. cat
(Concatenate)
Displays the content of a file.
cat file.txt
11. head
Displays the first lines of a file.
head -n 5 file.txt # Display the first 5 lines
12. tail
Displays the last lines of a file.
tail -n 10 file.txt # Display the last 10 lines
13. echo
Outputs text to the terminal or a file.
echo "Hello World"
echo "Hello World" > hello.txt # Write to file
14. nano
Opens the nano text editor.
nano file.txt
15. vi
/ vim
Opens a powerful text editor.
vi file.txt
16. find
Searches for files or directories in a directory hierarchy.
find / -name filename.txt # Find file by name
17. locate
Searches for files by name (uses a pre-built database).
locate file.txt
18. grep
Searches for a specific pattern in files.
grep "search_term" file.txt
19. chmod
(Change Mode)
Changes the file permissions.
chmod 755 script.sh # Give read, write, execute to owner, read-execute to others
20. chown
(Change Ownership)
Changes the file owner and group.
chown user:group file.txt
21. ps
(Process Status)
Displays information about running processes.
ps aux
22. top
Displays dynamic real-time information about running processes.
top
23. kill
Terminates a process by ID.
kill 1234 # Kill process with ID 1234
24. killall
Terminates all processes with a given name.
killall firefox
25. df
(Disk Free)
Shows the amount of free disk space.
df -h # Show human-readable disk usage
26. du
(Disk Usage)
Shows disk space used by files and directories.
du -sh folder_name # Show size of a folder
27. free
Displays memory usage.
free -h # Show human-readable memory usage
28. uname
Displays information about the system.
uname -a
29. ifconfig
Displays network interface information (replaced by ip
in newer distributions).
ifconfig
30. ip
Displays or manipulates network interface configurations.
ip addr
31. ping
Sends ICMP packets to test connectivity.
ping google.com
32. wget
Downloads files from the internet.
wget http://example.com/file.zip
33. curl
Transfers data from or to a server.
curl https://example.com
34. tar
Archives files or extracts files from archives.
tar -cvf archive.tar file1 file2 # Create an archive
tar -xvf archive.tar # Extract an archive
35. zip
Compresses files into a ZIP archive.
zip archive.zip file1 file2
36. unzip
Extracts files from a ZIP archive.
unzip archive.zip
37. ssh
Connects to a remote machine via SSH.
ssh user@remote_server
38. scp
Copies files securely between machines over SSH.
scp file.txt user@remote_server:/path/to/destination
39. rsync
Efficiently transfers files between machines.
rsync -avz source/ user@remote_server:/destination/
40. sudo
Runs a command with superuser (root) privileges.
sudo apt update
41. apt
Package manager for Debian-based distributions (like Ubuntu).
sudo apt install package_name
sudo apt update # Update package list
42. yum
Package manager for Red Hat-based distributions (like CentOS).
sudo yum install package_name
43. systemctl
Controls the systemd system and service manager.
sudo systemctl status apache2 # Check service status
sudo systemctl restart apache2 # Restart a service
44. journalctl
Views system logs managed by systemd.
sudo journalctl -u apache2 # View logs for apache2 service
45. history
Displays the command history.
history
46. alias
Creates shortcuts for commands.
alias ll="ls -la" # Create alias for 'ls -la'
47. unalias
Removes an alias.
unalias ll
48. whoami
Displays the current user.
whoami
49. hostname
Displays or sets the system's hostname.
hostname
50. reboot
Reboots the system.
sudo reboot
Conclusion
These are just some of the many commands you can use in Linux. Mastering these will help you navigate and control your Linux environment with ease. Whether you're a beginner or an advanced user, regularly using the Linux terminal will deepen your understanding of the system and increase your productivity.
Happy Linux-ing!