The command line is an incredibly powerful tool for Linux users, offering a fast and efficient way to perform tasks, automate processes, and manage the system. Here are some essential Linux command line tricks categorized to enhance your productivity.
File and Directory Management
Command
Description
ls -lah
List files in a directory with detailed information, including hidden files.
cd -
Switch back to the previous directory you were in.
find / -type f -size +100M
List files larger than 100MB to help free up disk space.
du -sh *
Show the size of all files and folders in the current directory.
mkdir new_directory
Create a new directory.
rm -rf directory_name
Remove a directory and all its contents.
touch newfile.txt
Create a new empty file.
mv oldname.txt newname.txt
Rename or move a file.
cp -r source_directory destination_directory
Copy directories and their contents recursively.
tar -cvf archive.tar directory/
Create a .tar archive from a directory.
tar -xvf archive.tar.gz
Extract the contents of a .tar.gz archive.
Process and System Monitoring
Command
Description
top
Display real-time CPU and memory usage.
htop
An enhanced version of top with a more user-friendly interface.
ps aux
Display all running processes.
kill -9 <PID>
Kill an unresponsive process by its Process ID (PID).
pkill process_name
Kill a process by its name instead of PID.
uptime
Show how long the system has been running.
free -m
Check current memory usage in megabytes.
df -h
Check available disk space in a human-readable format.
journalctl -xe
View system logs for debugging errors.
systemctl status service_name
Check the status of a system service.
systemctl restart service_name
Restart a system service.
User and Permission Management
Command
Description
whoami
Show the current logged-in user.
passwd
Change the user password.
chmod 755 script.sh
Change file permissions to make a script executable.
chown user:group filename
Change ownership of a file or directory.
adduser username
Add a new user to the system.
deluser username
Remove a user from the system.
Networking and Connectivity
Command
Description
ping google.com
Send a test signal to Google to check if the internet connection is working.
traceroute google.com
Trace the path packets take to reach Google.
netstat -tulnp
Show active network connections and listening ports.
iptables -L -v -n
List firewall rules.
hostname -I
Display the IP address of the machine.
wget URL
Download a file from the internet.
curl -O URL
Download a file using curl.
scp file.txt user@remote:/destination/path
Securely transfer files between computers using SSH.
rsync -avz source/ destination/
Synchronize files and directories efficiently.
Text Processing and Search
Command
Description
grep "word" filename.txt
Search for a specific word inside a text file.
awk '{print $1, $3}' filename.txt
Extract specific columns from a text file.
sed 's/old-text/new-text/g' filename.txt
Replace all occurrences of old-text with new-text.
cat filename.txt
Display the contents of a file.
tail -f /var/log/syslog
Continuously monitor system logs for updates.
Productivity Boosters
Command
Description
ctrl + r
Search for a specific command in history.
alias ll='ls -lah'
Create a shortcut for frequently used commands.
history | grep command
Search command history for a specific command.
!!
Re-run the last executed command.
python3 -m http.server 8000
Start a temporary web server in the current directory on port 8000.
Conclusion
Mastering these Linux command-line tricks can greatly enhance your efficiency and control over your system. Whether you’re a beginner or an advanced user, these categorized commands will help streamline your workflow. Try them out and take your Linux skills to the next level!
Leave a Reply