Linux tricks

Essential Command Line Tricks for Linux Users

β€”

by

in

Intoduction

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

CommandDescription
ls -lahList files in a directory with detailed information, including hidden files.
cd -Switch back to the previous directory you were in.
find / -type f -size +100MList 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_directoryCreate a new directory.
rm -rf directory_nameRemove a directory and all its contents.
touch newfile.txtCreate a new empty file.
mv oldname.txt newname.txtRename or move a file.
cp -r source_directory destination_directoryCopy directories and their contents recursively.
tar -cvf archive.tar directory/Create a .tar archive from a directory.
tar -xvf archive.tar.gzExtract the contents of a .tar.gz archive.

πŸ›  Process and System Monitoring

CommandDescription
topDisplay real-time CPU and memory usage.
htopAn enhanced version of top with a more user-friendly interface.
ps auxDisplay all running processes.
kill -9 <PID>Kill an unresponsive process by its Process ID (PID).
pkill process_nameKill a process by its name instead of PID.
uptimeShow how long the system has been running.
free -mCheck current memory usage in megabytes.
df -hCheck available disk space in a human-readable format.
journalctl -xeView system logs for debugging errors.
systemctl status service_nameCheck the status of a system service.
systemctl restart service_nameRestart a system service.

πŸ” User and Permission Management

CommandDescription
whoamiShow the current logged-in user.
passwdChange the user password.
chmod 755 script.shChange file permissions to make a script executable.
chown user:group filenameChange ownership of a file or directory.
adduser usernameAdd a new user to the system.
deluser usernameRemove a user from the system.

πŸ“‘ Networking and Connectivity

CommandDescription
ping google.comSend a test signal to Google to check if the internet connection is working.
traceroute google.comTrace the path packets take to reach Google.
netstat -tulnpShow active network connections and listening ports.
iptables -L -v -nList firewall rules.
hostname -IDisplay the IP address of the machine.
wget URLDownload a file from the internet.
curl -O URLDownload a file using curl.
scp file.txt user@remote:/destination/pathSecurely transfer files between computers using SSH.
rsync -avz source/ destination/Synchronize files and directories efficiently.

πŸ“ Text Processing and Search

CommandDescription
grep "word" filename.txtSearch for a specific word inside a text file.
awk '{print $1, $3}' filename.txtExtract specific columns from a text file.
sed 's/old-text/new-text/g' filename.txtReplace all occurrences of old-text with new-text.
cat filename.txtDisplay the contents of a file.
tail -f /var/log/syslogContinuously monitor system logs for updates.

⏳ Productivity Boosters

CommandDescription
ctrl + rSearch for a specific command in history.
alias ll='ls -lah'Create a shortcut for frequently used commands.
history | grep commandSearch command history for a specific command.
!!Re-run the last executed command.
python3 -m http.server 8000Start 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! πŸš€


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *