Top 30 Linux Command
As a software engineer, navigating the Linux command line is an invaluable skill. Linux provides a powerful environment for development, system administration, and more. In this article, we'll explore 30 essential Linux commands that software engineers should be familiar with, complete with practical examples to illustrate their usage.
1. ls - List Files
List files and directories in the current directory.
Example:
ls [/directory/folder/path]
2. cd - Change Directory
Change the current working directory.
Example:
cd /path/to/directory
Here are some navigation shortcuts:
3. pwd - Print Working Directory
Display the current directory's full path.
Example:
pwd
4. mkdir - Make Directory
Create a new directory.
Example:
mkdir [option] new_directory
Here are several common mkdir command options:
5. touch - Create Empty File
Create a new empty file.
Example:
touch new_file.txt
6. cp - Copy Files and Directories
Copy files or directories from one location to another.
Example:
cp filename.txt /home/username/Documents
cp -R /home/username/Documents /home/username/Documents_backup
7. rm - Remove Files and Directories
Remove files or directories (use with caution).
Example:
rm [option] unwanted_file.txt
To modify the command, add the following options:
Note: Use the rm command with caution since deletion is irreversible. Avoid using the -r and -f options since they may wipe all your files. Always add the -i option to avoid accidental deletion.
8. rmdir - Remove Directories
Use the rmdir command to delete an empty directory in Linux.
rmdir [option] directory_name
If the folder contains a subdirectory, the command will return an error. To force delete a non-empty directory, use the -p option.
9. touch - Create Empty File
Create a new empty file.
Example:
touch new_file.txt
10. mv - Move or Rename Files
Move or rename files and directories.
Example (move):
mv filename.txt /home/username/Documents
Example (rename):
mv old_filename.txt new_filename.txt
11. cat - Concatenate and Display File Content
Display the contents of a file.
Example:
cat filename.txt
There are various ways to use the cat command:
12. grep - Search Text
The global regular expression or grep command lets you find a word by searching the content of a file.
Example:
grep blue notepad.txt
13. head and tail - Display Beginning/End of File
Display the first or last lines of a file.
Example (head):
head file.txt # Display first 5 lines
Example (tail):
tail file.txt # Display last 5 lines
14. chmod - Change File Permissions
Change file permissions (read, write, execute).
Example:
chmod 755 script.sh
Read(1), write(2), and execute(4) for owner (1+2+4=7); read(1) and execute(4) for group(1+4=5) and others(1+4=5)
15. chown - Change File Owner
Change the owner of a file.
Example:
chown new_owner:group file.txt
16. du - Disk Usage of Directories
Display disk usage of directories and files.
Example:
Recommended by LinkedIn
du -sh /path/to/directory
The du command has several options, such as:
17. zip, unzip - Compress and Decompress Files
The zip command lets you compress items into a ZIP file with the optimal compression ratio. Here’s the syntax:
zip [options] zipfile file1 file2….
For example, this command compresses note.txt into archive.zip in the current working directory:
zip archive.zip note.txt
Use the unzip command to extract the compressed file. Here’s the syntax:
unzip file_name.zip
18. ps - Process Status
List running processes.
Example:
ps [option]
The ps command accepts several options, including:
19. kill - Terminate Processes
Terminate processes by their process ID (PID).
Example:
kill [PID]
20. uname - Unix Name
The uname or unix name command prints information about your machine, including its hardware, system name, and Linux kernel.
Example:
uname [option]
While you can use it without an option, add the following to modify the command:
21. sudo - Run with special privilege
Superuser do or sudo is one of the most basic commands in Linux. It runs your command with administrative or root permissions.
Example:
sudo useradd username
You can also add an option, such as:
22. Useradd, Userdel commands
Use useradd to create a new Linux user account and change its password with the passwd command.
Example:
useradd [option] username
passwd username
Both the useradd and passwd commands require sudo privileges. To delete a user, use the userdel command:
userdel username
23. ping - Check Server Availability
It lets you check whether a network or server is reachable, which is useful for troubleshooting connectivity issues.
Example:
ping www.google.com
24. wget - Download Files
Use the wget command to download files from the internet using HTTP, HTTPS, or FTP protocols. Here’s the syntax:
wget [option] [url]
For example, enter the following to download the latest version of WordPress:
wget https://wordpress.org/latest.zip
25. curl - Retrieve Content
The curl command transfers data between servers. Its common usage is for retrieving a web page’s content to your system using its URL. Here’s the syntax:
curl [option] URL
However, you can add various options to modify the curl command behavior for other tasks:
26. scp - Copy Files on server
The scp command securely copies files or directories between systems over a network.
Example:
scp [option] [source username@IP]:/[directory and file name] [destination username@IP]:/[destination directory]
For a local machine, omit the hostname and IP address. Use the following options to modify the copying behavior:
27. rsync - Sync Files
The rsync command lets you sync files or folders between two destinations to ensure they have the same content. Here’s the syntax:
rsync [options] source destination
If your destination or source is a folder, enter the directory path like /home/directory/path. To sync a remote server, use its hostname and IP address, like host@185.185.185.185.
This command has various options:
28. ifconfig command
The ifconfig command lets you list and configure your system’s network interface. In newer Linux distros, it is equivalent to the ip command.
Example:
ifconfig [interface] [option]
Running it without arguments displays information about all network interfaces in your system. To check a specific interface, add its name as an argument without an option. For a more specific task, use the following options:
29. netstat command
The netstat command is used to display your system’s network information, like sockets and routing. Here’s the command syntax:
netstat [option]
Use various options to modify the displayed information. Some common ones are:
30. dig command
The dig or domain information groper command gathers DNS data from a domain. Unlike nslookup, it is more detailed and versatile. Here’s the syntax:
dig [option] target [query_type]
Replace target with a domain name. By default, this command only shows A record type. Change query_type to check a specific type or use ANY to query all of them. To run a reverse DNS lookup, add the -x option and use the IP address as the target.
Conclusion
These 30 Linux commands are just the tip of the iceberg in the Linux command-line world. Mastering these commands will empower software engineers to efficiently navigate, manage, and develop in a Linux environment. As you delve deeper into Linux, you'll discover many more commands and options to streamline your development workflow and system administration tasks. Happy coding!
Informative