Essential Linux Commands
Linux commands are a critical part of managing systems, debugging issues, and automating tasks in the IT field.
1. Navigation and File Management
cd: Change the current directory.
Example: cd /home/user/Documentscd ..: Move up one directory level.
pwd: Print the current directory path.
mkdir: Create a new directory.
Example: mkdir new_foldertouch: Create an empty file.
Example: touch example.txtrm -rf: Remove files and directories forcefully.
Example: rm -rf unwanted_foldercp -r: Copy a directory recursively.
Example: cp -r source_dir destination_dirmv: Move or rename files and directories.
Example: mv old_name.txt new_name.txt
2. File Viewing and Search
cat: View the contents of a file.
Example: cat file.txthead and tail: View the first or last lines of a file.
Example:head -n 10 file.txt (first 10 lines)
tail -n 10 file.txt (last 10 lines)
less: View files page by page interactively.
Example: less file.txtgrep: Search for a string in files.
Example: grep -rin "error" /var/logs/find: Locate files or directories.
Example: find / -name "example.txt"locate: Quickly search for files by name.
Example: locate example.txttac: View a file’s contents in reverse order.
Example: tac file.txtzgrep: Search within compressed files.
Example: zgrep "error" logs.gz
3. Networking Commands
ifconfig: Display or configure network interfaces.
Example: ifconfigcurl ifconfig.me: Fetch your public IP address.
ipconfig (Windows): Show IP configuration.
ip r: Show the routing table.
nslookup: Query DNS for domain information.
Example: nslookup google.comping: Check connectivity to an IP address or domain.
Example: ping 127.0.0.1telnet: Establish a telnet connection for testing ports.
Example: telnet example.com 80scp: Securely copy files between systems.
Example: scp localfile.txt user@remote:/path/to/destinationssh: Securely connect to a remote system.
Example: ssh user@remote_hostnetstat -ntpl: Display active TCP connections and listening ports.
4. Disk and System Management
lsblk: List information about block devices.
Example: lsblkdf -ht: Display disk space usage in human-readable format.
Example: df -ht ext4du -sh : Show the size of files and directories.
Example: du -sh /var/growpart /dev/xvda 1 : It is used to resize a partition.
5. Process and System Control
ps -ef: Display all running processes.
kill -9: Forcefully terminate a process.
Example: kill -9 PIDtop and htop: Monitor system performance interactively.
systemctl: Manage system services.
Examples:systemctl start apache2
systemctl restart nginx
systemctl enable docker
6. Log Management
crontab -l: List scheduled cron jobs.
crontab -e: Edit cron jobs.
tail -f: Follow log files in real-time.
Example: tail -f catalina.outgrep -A 100 -B 100: View 100 lines before and after a matching string.
Example: grep -a 100 -b 100 "error" catalina.outlogrotate: Manage log rotation and retention.
7. Redirection and Streams
stdin, stdout, stderr: Standard input, output, and error streams.
\> and >> : Redirect output to files.
Examples:echo "hello" > file.txt (overwrite)
echo "world" >> file.txt (append)
/dev/null: Discard output.
Example: command > /dev/null 2>&1
8. Miscellaneous
sed: Stream editor for parsing and transforming text.
Example: sed -n '5,10p' file.txt (lines 5-10)wc -w: Count words in a file.
Example: wc -w file.txttar: Archive files into tarballs.
Example: tar -cvf archive.tar file1 file2unzip: Extract files from a zip archive.
Example: unzip archive.zip
Conclusion
This blog highlights essential Linux commands that every IT professional should know. Whether you’re troubleshooting, managing systems, or automating tasks, mastering these commands will make you more efficient and boost your productivity.
Subscribe to my newsletter
Read articles from DEVESH NEMADE directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by