Top 100 Linux commands.
Top 100 Linux Commands
1. **pwd**
Explanation: Displays the current working directory.
Example: Running `pwd` in the terminal would show the absolute path of the current directory, such as `/home/user/documents`.
2. **cd**
Explanation: Changes the current working directory.
Example: Running `cd /home/user/documents` would change the directory to `/home/user/documents`.
3. **cd ..**
Explanation: Moves up one level in the directory hierarchy.
Example: Running `cd ..` in `/home/user/documents` would move to the `/home/user` directory.
4. **ls**
Explanation: Lists the files and directories in the current directory.
Example: Running `ls` would display the files and directories in the current directory.
5. **ls -la**
Explanation: Lists detailed information about files and directories, including hidden files.
Example: Running `ls -la` would display a detailed list of files and directories, including hidden files, in the current directory.
6. **mkdir**
Explanation: Creates a new directory.
Example: Running `mkdir new_folder` would create a new directory named `new_folder` in the current directory.
7. **rmdir**
Explanation: Removes an empty directory.
Example: Running `rmdir empty_folder` would remove the directory named `empty_folder` if it is empty.
8. **man**
Explanation: Displays the manual pages for a specified command.
Example: Running `man ls` would show the manual pages with detailed information about the `ls` command.
9. **echo**
Explanation: Displays text or variables as output.
Example: Running `echo "Hello, world!"` would output `Hello, world!` in the terminal.
10. **>**
Explanation: Redirects the output of a command to a file and overwrites the file if it already exists.
Example: Running `echo "Hello" > greeting.txt` would write the text `Hello` to a file named `greeting.txt` or overwrite the file if it exists.
11. **>>**
Explanation: Redirects the output of a command and appends it to a file.
Example: Running `echo "World!" >> greeting.txt` would append the text `World!` to the end of the `greeting.txt` file.
12. **rm**
Explanation: Deletes files or directories.
Example: Running `rm file.txt` would delete the file named `file.txt` from the current directory.
13. **mv**
Explanation: Moves or renames files and directories.
Example: Running `mv file.txt new_directory/file_renamed.txt` would move the file `file.txt` to the `new_directory` and rename it as `file_renamed.txt`.
14. **cp**
Explanation: Copies files and directories.
Example: Running `cp file.txt backup/file_copy.txt` would create a copy of `file.txt` named `file_copy.txt` in the `backup` directory.
15. **locate**
Explanation: Searches for files and directories in a prebuilt database.
Example: Running `locate myfile.txt` would search for the file named `myfile.txt` in the prebuilt database and display its path if found.
16. **updatedb**
Explanation: Updates the database used by the locate command to reflect recent changes in the file system.
Example: Running `updatedb` would update the database, allowing the locate command to provide up-to-date search results.
17. **passwd**
Explanation: Allows a user to change their password.
Example: Running `passwd` would prompt the user to enter their current password and then set a new password.
18. **cat**
Explanation: Displays the contents of a file.
Example: Running `cat file.txt` shows the contents of `file.txt`.
19. **touch**
Explanation: Creates a new empty file.
Example: Running `touch newfile.txt` creates an empty file named `newfile.txt`.
20. **chmod**
Explanation: Changes file permissions.
Example: Running `chmod 755 script.sh` sets read, write, and execute permissions for the owner and read and execute for group and others.
21. **chown**
Explanation: Changes the owner and group of a file.
Example: Running `chown alice:users file.txt` changes the ownership of `file.txt` to user `alice` and group `users`.
22. **tar -cvf**
Explanation: Creates a tar archive of a directory.
Example: Running `tar -cvf archive.tar directory/` creates an archive named `archive.tar` containing the contents of `directory`.
23. **tar -xvf**
Explanation: Extracts a tar archive.
Example: Running `tar -xvf archive.tar` extracts the contents of `archive.tar`.
24. **gzip**
Explanation: Compresses a file using gzip.
Example: Running `gzip file.txt` creates `file.txt.gz` and deletes the original file.
25. **gunzip**
Explanation: Decompresses a gzip-compressed file.
Example: Running `gunzip file.txt.gz` restores `file.txt` from the compressed file.
26. **df -h**
Explanation: Displays disk space usage in a human-readable format.
Example: Running `df -h` shows available and used space for mounted filesystems.
27. **free -m**
Explanation: Displays memory usage.
Example: Running `free -m` shows memory usage in megabytes.
28. **top**
Explanation: Displays real-time system processes and resource usage.
Example: Running `top` opens an interactive display of system processes.
29. **htop**
Explanation: An enhanced version of top with a more user-friendly interface.
Example: Running `htop` displays processes and allows easy navigation.
30. **ps aux**
Explanation: Displays a snapshot of all running processes.
Example: Running `ps aux` shows detailed information about all active processes.
31. **kill**
Explanation: Terminates a process using its Process ID (PID).
Example: Running `kill 1234` sends a termination signal to the process with PID 1234.
32. **killall**
Explanation: Terminates all processes with the specified name.
Example: Running `killall firefox` closes all instances of Firefox.
33. **df -T**
Explanation: Displays filesystem types along with disk usage.
Example: Running `df -T` provides information about the type of each filesystem.
34. **uptime**
Explanation: Shows how long the system has been running.
Example: Running `uptime` displays the system uptime, number of users, and load averages.
35. **whoami**
Explanation: Displays the current user’s username.
Example: Running `whoami` shows the username of the current logged-in user.
36. **hostnamectl**
Explanation: Displays and modifies the system hostname.
Example: Running `hostnamectl` shows the current hostname and other related settings.
37. **nslookup**
Explanation: Queries DNS to obtain domain name or IP address mapping.
Example: Running `nslookup google.com` retrieves the IP addresses for Google.
38. **ifconfig**
Explanation: Displays network interface configuration.
Example: Running `ifconfig` shows details about all network interfaces.
39. **ip addr**
Explanation: Displays IP addresses and network interfaces.
Example: Running `ip addr` provides detailed information about IP addresses associated with network interfaces.
40. **route -n**
Explanation: Displays the routing table.
Example: Running `route -n` shows the current routing table without resolving hostnames.
41. **iptables -L**
Explanation: Lists current iptables rules.
Example: Running `sudo iptables -L` displays active firewall rules.
42. **wget**
Explanation: Downloads files from the web.
Example: Running `wget http://example.com/file.zip` downloads the specified file.
43. **curl -I**
Explanation: Fetches HTTP headers from a URL.
Example: Running `curl -I http://example.com` retrieves and displays the HTTP headers.
44. **ln -s**
Explanation: Creates a symbolic link.
Example: Running `ln -s /path/to/file link_name` creates a symlink to the specified file.
45. **diff -u**
Explanation: Compares files with unified output.
Example: Running `diff -u file1.txt file2.txt` shows differences between the two files in a unified format.
46. **history**
Explanation: Displays the command history.
Example: Running `history` shows a list of previously executed commands.
47. **alias**
Explanation: Creates a shortcut for a command.
Example: Running `alias ll='ls -la'` creates an alias `ll` for `ls -la`.
48. **unalias**
Explanation: Removes an alias.
Example: Running `unalias ll` removes the alias `ll`.
49. **locate filename**
Explanation: Quickly finds the location of files.
Example: Running `locate file.txt` searches for `file.txt` in the file database.
50. **grep**
Explanation: Searches for patterns in files.
Example: Running `grep 'text' file.txt` searches for the word `text` in `file.txt`.
51. **find**
Explanation: Searches for files and directories.
Example: Running `find /home/user -name '*.txt'` finds all `.txt` files in the specified directory.
52. **wc -l**
Explanation: Counts lines in a file.
Example: Running `wc -l file.txt` returns the number of lines in `file.txt`.
53. **cut -d**
Explanation: Removes sections from each line of files.
Example: Running `cut -d':' -f1 /etc/passwd` retrieves the first field from each line in the `passwd` file.
54. **sort**
Explanation: Sorts lines of text files.
Example: Running `sort file.txt` sorts the contents of `file.txt` alphabetically.
55. **uniq**
Explanation: Filters out repeated lines in a file.
Example: Running `uniq file.txt` removes duplicate lines from `file.txt`.
56. **tr**
Explanation: Translates or deletes characters.
Example: Running `tr 'a' 'b' < input.txt` replaces all occurrences of `a` with `b` in `input.txt`.
57. **basename**
Explanation: Strips the directory and suffix from filenames.
Example: Running `basename /home/user/file.txt` returns `file.txt`.
58. **dirname**
Explanation: Extracts the directory path from a filename.
Example: Running `dirname /home/user/file.txt` returns `/home/user`.
59. **touch**
Explanation: Updates the access and modification times of a file.
Example: Running `touch file.txt` updates the timestamp of `file.txt` to the current time.
60. **split**
Explanation: Splits a file into pieces.
Example: Running `split -l 100 file.txt` splits `file.txt` into files with 100 lines each.
61. **tee**
Explanation: Reads from standard input and writes to standard output and files.
Example: Running `echo "Hello" | tee file.txt` outputs `Hello` to the terminal and writes it to `file.txt`.
62. **history -c**
Explanation: Clears the command history.
Example: Running `history -c` removes all entries from the history list.
63. **df -h**
Explanation: Displays disk usage in a human-readable format.
Example: Running `df -h` provides an overview of disk space for all filesystems.
64. **du -sh**
Explanation: Displays the disk usage of a directory in a human-readable format.
Example: Running `du -sh /path/to/directory` shows the total size of the specified directory.
65. **tar -czvf**
Explanation: Creates a compressed tarball (gzip).
Example: Running `tar -czvf archive.tar.gz directory/` creates a compressed archive of `directory`.
66. **tar -xzvf**
Explanation: Extracts a compressed tarball (gzip).
Example: Running `tar -xzvf archive.tar.gz` extracts the contents of the compressed archive.
67. **service**
Explanation: Controls system services.
Example: Running `service apache2 restart` restarts the Apache web server.
68. **systemctl**
Explanation: Manages system services and units.
Example: Running `systemctl status apache2` shows the status of the Apache web service.
69. **crontab -e**
Explanation: Edits the cron jobs for the current user.
Example: Running `crontab -e` opens the current user's cron jobs for editing.
70. **ssh**
Explanation: Connects to a remote machine securely.
Example: Running `ssh user@remote_host` establishes an SSH connection to `remote_host`.
71. **scp**
Explanation: Securely copies files between hosts.
Example: Running `scp file.txt user@remote_host:/path/to/destination` copies `file.txt` to the specified destination.
72. **rsync**
Explanation: Syncs files and directories between locations.
Example: Running `rsync -av source/ destination/` synchronizes files from `source` to `destination`.
73. **ping**
Explanation: Tests connectivity to a host.
Example: Running `ping google.com` checks if the host is reachable.
74. **traceroute**
Explanation: Traces the route packets take to a network host.
Example: Running `traceroute google.com` displays the path taken to reach Google.
75. **netstat**
Explanation: Displays network connections, routing tables, and interface statistics.
Example: Running `netstat -tuln` shows active listening ports and their associated protocols.
76. **curl -O**
Explanation: Downloads a file and saves it with the same name.
Example: Running `curl -O http://example.com/file.txt` downloads `file.txt` from the specified URL.
77. **wget -r**
Explanation: Recursively downloads files from a website.
Example: Running `wget -r http://example.com` downloads the entire site.
78. **chmod +x**
Explanation: Grants execute permissions to a file.
Example: Running `chmod +x script.sh` makes `script.sh` executable.
79. **alias ll='ls -l'**
Explanation: Creates an alias `ll` for listing files in long format.
Example: Running `ll` would execute `ls -l`.
80. **lsblk**
Explanation: Lists block devices in the system.
Example: Running `lsblk` shows all attached storage devices and their partitions.
81. **mount**
Explanation: Mounts a filesystem or storage device.
Example: Running `mount /dev/sdb1 /mnt` mounts the device `/dev/sdb1` to the `/mnt` directory.
82. **umount**
Explanation: Unmounts a filesystem or storage device.
Example: Running `umount /mnt` unmounts the device mounted at `/mnt`.
83. **chattr**
Explanation: Changes file attributes on a Linux file system.
Example: Running `chattr +i file.txt` makes `file.txt` immutable (not deletable).
84. **dd**
Explanation: Converts and copies files, often used for disk imaging.
Example: Running `dd if=/dev/sda of=/path/to/image.img` creates an image of the `/dev/sda` disk.
85. **echo $PATH**
Explanation: Displays the current user's PATH variable.
Example: Running `echo $PATH` shows the directories where the shell looks for executables.
86. **source**
Explanation: Executes commands from a file in the current shell.
Example: Running `source ~/.bashrc` applies changes made to the `.bashrc` file.
87. **env**
Explanation: Displays the current environment variables.
Example: Running `env` shows all environment variables and their values.
88. **set**
Explanation: Sets shell options and variables.
Example: Running `set -o noclobber` prevents overwriting files with redirection.
89. **export**
Explanation: Sets environment variables for child processes.
Example: Running `export VAR=value` creates an environment variable `VAR`.
90. **echo $USER**
Explanation: Displays the current username.
Example: Running `echo $USER` shows the logged-in user's name.
91. **basename filename**
Explanation: Displays the base name of a file.
Example: Running `basename /home/user/file.txt` outputs `file.txt`.
92. **dirname filename**
Explanation: Displays the directory name of a file.
Example: Running `dirname /home/user/file.txt` outputs `/home/user`.
93. **ping -c**
Explanation: Sends a specified number of packets to a host.
Example: Running `ping -c 4 google.com` sends 4 packets to Google.
94. **scp -r**
Explanation: Securely copies directories recursively.
Example: Running `scp -r folder user@remote_host:/path` copies `folder` to the remote host.
95. **find / -name**
Explanation: Searches for files by name throughout the entire filesystem.
Example: Running `find / -name '*.txt'` finds all `.txt` files starting from the root directory.
96. **less**
Explanation: Views file contents page by page.
Example: Running `less file.txt` allows you to scroll through `file.txt`.
97. **more**
Explanation: Views file contents, similar to less but with limited scrolling.
Example: Running `more file.txt` displays `file.txt` one page at a time.
98. **tar -cvzf**
Explanation: Creates a compressed tarball (gzip) of a directory.
Example: Running `tar -cvzf archive.tar.gz directory/` creates a compressed archive.
99. **history | grep**
Explanation: Searches the command history for specific commands.
Example: Running `history | grep 'git'` finds all git commands in the history.
100. **free -h**
Explanation: Displays memory usage in a human-readable format.
Example: Running
`free -h` shows the total, used, and free memory in the system.
Comments