5 surprisingly productive things you can do with the Linux terminal


Jack Wallen/ZDNET

As much as I tout that users don’t have to work with the Linux terminal, I have to admit there are certain things I do from the command line that are far more productive than their GUI counterparts.

It’s part of what makes Linux such a great operating system. If you want to do things simply, use the GUI. If you want to do things efficiently, use the command line. Although you can do almost anything you need with various GUI applications, the command line is often simpler (once you know the commands) and more effective.

Also: 5 Linux commands I use to keep my device running smoothly

Here are five things I do from the command line to help keep me more productive.

1. Task automation

Task automation is a big one. I might have bash scripts I’ve written for various purposes (such as backups) that must run at specific times. Or maybe I want to run the same command on multiple machines without manually iterating through those commands, one at a time. Either way, task automation is a big help on Linux — and doing it from the command line is effective.

The primary tool for this task is called cron, which makes it possible for you to create cron jobs that run at specific times or intervals. You can write simple or complex bash scripts and then call those scripts automatically with a cron job. Cron is powerful but surprisingly easy to use. The biggest challenge with cron is knowing how time works with the system. Every cron job is created as a line (using the crontab -e command) in a crontab file, and that line contains five sections that indicate time. Those sections are:

minute hour day_of_month month day_of_week

Then comes the command. Let’s say you want a command to run at 9:05 in the morning every day. That entry would look like this:

05 09 * * *

You would follow that by adding the path to your bash script like so:

05 09 * * * /path/to/script

If the script produces output, you must silence that output (otherwise it fails). To do that, you send the output to /dev/null like so:

> /dev/null 2>&1

The entire entry would look like this:

05 09 * * * /path/to/script > /dev/null 2>&1

2. Hide sensitive information

This trick is simple and effective. Let’s say you have a file with sensitive information, but the information isn’t so sensitive that it needs to be encrypted. You can hide that file from plain sight by adding a leading “.” to the file name. For example, you might have a file that contains your journal (named, aptly, journal). That file might be in ~/Documents, but you want to ensure no one can see it without using a special flag with the ls command (ls -a) or a GUI file manager. To hide that file, rename it like so:

mv ~/Documents/journal ~/Documents/.journal

When you need to edit the file, remember to add the “.” before the name, like so:

nano ~/Documents/.journal

Remember, the file’s contents are not encrypted or password protected, they’re just hiding in plain sight.

3. Search within files

Let’s say you have a text file with many names and addresses, and you’re looking for one particular name/address combo. You could open that file and scan through it to find the entry, or you could use grep to locate that single entry to make things much easier. For example, if the file name is contacts and the contact you’re looking for is Jit Su, you could use grep like so:

grep “Jit Su” contacts

The output of the command would list the entire entry that contains “Jit Su”.

Also: 4 free project management apps I recommend on Linux – and why you should use one

Let’s say you have multiple entries with the first name “Jit” and want to list them all in the output. For that, you would remove the last name like so:

grep “Jit” contacts

If you wanted to know the corresponding line number for each entry, the command would be:

grep -n “Jit” contacts

4. Back up your files

As I mentioned in the automation section, it’s easy to back up files and folders from the command line — and you can use rsync. You can back up files from one folder on your internal drive to an external drive and across your network. You can use rsync as a one-off command or with cron to create an automated backup that will run at specific intervals.

Also: The first 5 Linux commands every new user should learn

The most basic rsync backup script might look something like this:

rsync -r data/ backup

The -r option is for recursive, meaning it will also backup any sub-folders and files. Notice the trailing / after data. If you don’t use that slash, the data folder would be copied into backup, so you’d have backup/data instead of just the files and subfolders found in data.

5. Check system performance

When your computer seems to be running slow, you can check system performance with several commands. The command I generally turn to first is top, which displays all running commands/services and lists how much CPU, RAM, and other resources are in use. 

Also: The 6 Linux commands you need to know for user management

If I find one particular command or service is gobbling up too many resources, I’ll stop the command or service and restart it. A lot of times, this step will solve the issue. If not, there could be an issue with the command/service. Other commands you can use include htop, vmstat, iostat, free, df, du, netstat, mpstat, nmon, and glances.





Source link

Leave a Comment