15 More Advanced Linux Tricks to Ease Your Workflow

November 26, 2024

By: ATB Team


Warning: Undefined array key "uniqueId" in /home/u341988038/domains/aroundthebytes.com/public_html/wp-content/plugins/generateblocks/includes/blocks/class-container.php on line 997

Warning: Undefined array key "uniqueId" in /home/u341988038/domains/aroundthebytes.com/public_html/wp-content/plugins/generateblocks/includes/blocks/class-container.php on line 997

15 More Advanced Linux Tricks to Ease Your Workflow

Now that you’ve learned some basic Linux tricks, let’s check 15 more advanced tips and commands to further boost your productivity. These tricks are perfect for power users and system administrators who want to make the most of Linux’s capabilities.

1. Use rsync for Fast and Efficient File Transfers

rsync is one of the most efficient tools for copying files, especially over networks. It only transfers the parts of the files that have changed, making it incredibly fast.

Example: To sync a directory to a remote server:

rsync -avz /local/dir user@remote:/remote/dir

Here, -a stands for archive (preserving permissions, timestamps, etc.), -v is for verbose output, and -z compresses data during transfer.

2. Monitor File Changes with inotifywait

If you need to monitor when a file or directory is modified, inotifywait is a great tool.

Example: To monitor a directory for changes:

inotifywait -m /path/to/directory

This command will output a message every time a file is created, deleted, or modified in the directory.

3. Run Commands in Background with nohup

When running long-running commands, you may want to ensure that they keep running even after you close the terminal. Use nohup to detach a process from the terminal.

Example:

nohup long-running-command &

This will run the command in the background, and any output will be written to nohup.out by default.

4. Use dd for Disk Cloning and Backup

The dd command is powerful for creating disk images, backups, and cloning drives.

Example: To create an image of a disk:

dd if=/dev/sda of=/path/to/backup.img bs=64K conv=noerror,sync

This creates an exact byte-for-byte copy of the source disk (/dev/sda) to the destination image file (backup.img).

5. Create and Extract .tar Archives

The tar command is commonly used to create and extract compressed archives, making it easy to package multiple files.

Example: To create a .tar.gz archive:

tar -czvf archive.tar.gz /path/to/directory

To extract a .tar.gz archive:

tar -xzvf archive.tar.gz

6. Check Disk Usage with du and df

To check the disk usage of directories and partitions, du and df are invaluable tools.

  • Check directory size: du -sh /path/to/directory
  • Check disk space on all partitions: df -h

7. Use curl to Download Files from the Internet

curl is a command-line tool for transferring data with URLs. It supports multiple protocols like HTTP, FTP, and more.

Example: To download a file:

curl -O http://example.com/file.zip

You can also use curl to fetch the contents of a webpage:

curl http://example.com

8. Check System Uptime with uptime

The uptime command quickly shows the system’s uptime, load averages, and number of users currently logged in.

Example:

uptime

Output example:

 14:22:41 up 5 days,  3:10,  2 users,  load average: 0.13, 0.25, 0.21

9. Use wc to Count Words, Lines, and Characters

The wc command is handy when you need to count the number of lines, words, and characters in a file.

Example: To count the lines in a file:

wc -l filename

You can also use wc to get all counts:

wc filename

10. Automate Tasks with cron Jobs

cron is a powerful scheduling tool that allows you to run commands automatically at specified intervals.

To edit the cron jobs:

crontab -e

Example: Run a backup script every day at 3 AM:

0 3 * * * /path/to/backup.sh

11. Use chmod to Change File Permissions

File permissions are crucial in Linux, and chmod allows you to change them easily.

Example: To give read, write, and execute permissions to the owner and read and execute permissions to others:

chmod 755 file

12. Create and Manage Virtual Environments with virtualenv

For Python developers, virtualenv is a tool that helps isolate project dependencies.

Example: To create a new virtual environment:

virtualenv myenv

To activate it:

source myenv/bin/activate

To deactivate:

deactivate

13. Use awk for Text Processing

awk is a powerful text-processing tool for pattern scanning and processing.

Example: To print the first column from a file:

awk '{print $1}' filename

You can also use awk for complex operations such as calculations:

awk '{sum += $1} END {print sum}' filename

14. Use sed for Stream Editing

sed is a stream editor that can modify text in files or input streams.

Example: To replace all occurrences of “apple” with “orange” in a file:

sed -i 's/apple/orange/g' filename

Here, -i makes the changes in-place, and s/apple/orange/g is the substitution command.

15. Monitor Network Traffic with iftop

iftop is a real-time network bandwidth monitoring tool.

Example: To monitor real-time traffic:

sudo iftop

This will display a list of active connections, along with their data rates.

Conclusion

These 15 advanced Linux tricks will help you become a more efficient user, whether you are managing files, automating tasks, or monitoring system resources. By mastering these tools and commands, you’ll be able to tackle even the most complex tasks with ease.

Which of these tricks did you find most useful? Do you have any Linux tips of your own to share? Drop them in the comments below!

Leave a Comment

Table Of Content