Americas

  • United States
sandra_henrystocker
Unix Dweeb

2021 New Year’s resolutions for Linux users

How-To
Jan 05, 20215 mins
Linux

Linux has a wealth a powerful tools to make working with it easier and more productive, and here are some tips for taking advantage of them.

It’s a good idea to start each year with some ideas about how to make the new year better–even when it comes to working with Linux. This post offers some suggestions on how you might get more value and enjoyment from Linux in 2021.

Commit favorite commands to aliases or scripts

Linux commands make it easy to manipulate files and command output, but the cleverest commands can be very difficult to remember and reuse. Commit them to a script or alias, on the other hand, and you can give them meaningful names that are easy to remember  and use them easily  any time you need. Here’s an example of a complicated Linux command turned into an alias:

alias oct2dec='f(){ echo "obase=10; ibase=8; $1" | bc; unset -f f; }; f'

To save an alias, add its definition (like the one shown above that converts octal numbers to decimal) to your .bashrc or other start-up file and give it a name that clearly describes what it does.

Read some man pages

Read a man page now and then. There are almost always some options that you won’t already know about. Even if you’ve been using a command for decades, it is likely to have some options that will surprise you.

Never be reluctant to ask for help

Don’t be shy about asking Linux to help with a command that you want to use. You can try the –help option that is available with most, if not all, Linux commands to display command syntax and options. Keep in mind that syntactical elements displayed inside square brackets are optional.

For example, the first section of help from the adduser command shows many options and indicates that the USER variable is the only argument that is required. The other options displayed are available to further customize how the command works for you. They allow you to do things such as specify the user’s group rather than using the default, assign the user to multiple groups, and select the user’s shell.

$ adduser --help
adduser [--home DIR] [--shell SHELL] [--no-create-home] [--uid ID]
[--firstuid ID] [--lastuid ID] [--gecos GECOS] [--ingroup GROUP | --gid ID]
[--disabled-password] [--disabled-login] [--add_extra_groups]
[--encrypt-home] USER
…

Be proactive in watching for problems

Linux provides some great commands for looking for potential problems. Make sure you take advantage of commands like df to look at available disk space and last to review recent logins. Remember that it’s easy to notice when something’s wrong when you know what’s normal for systems that you manage.

$ df -k | grep -v loop
Filesystem     1K-blocks     Used Available Use% Mounted on
udev             3014760        0   3014760   0% /dev
tmpfs             608712     2620    606092   1% /run
/dev/sda1      114854020 20054752  88921920  19% /
tmpfs            3043540        0   3043540   0% /dev/shm
tmpfs               5120        4      5116   1% /run/lock
tmpfs            3043540        0   3043540   0% /sys/fs/cgroup
/dev/sdb1      446885824 42031208 382084392  10% /home
tmpfs             608708       28    608680   1% /run/user/1000
$
$ last | head -11
shs      pts/0        192.168.0.23     Sat Jan  2 14:51   still logged in
shs      pts/0        192.168.0.23     Sat Jan  2 12:28 - 13:53  (01:25)
shs      pts/0        192.168.0.23     Thu Dec 31 15:18 - 19:31  (04:13)
shs      :0           :0               Thu Dec 31 15:11   still logged in
reboot   system boot  5.4.0-58-generic Thu Dec 31 15:10   still running
shs      :0           :0               Sat Dec 26 15:20 - crash (4+23:50)
nemo     pts/0        192.168.0.7      Fri Dec 18 17:34 - 18:01  (00:26)
shs      pts/0        192.168.0.7      Fri Dec 18 16:50 - 17:19  (00:28)
reboot   system boot  5.4.0-58-generic Fri Dec 18 15:52   still running
nemo     pts/0        192.168.0.7      Fri Dec 18 15:51 - 15:51  (00:00)
shs      pts/0        192.168.0.7      Fri Dec 18 09:51 - 14:04  (04:12)

Discover commands you’ve never used

One good way to unearth commands you may have never tried is to use the apropos command. To generate a list of commands that set up or work with user accounts, for example, you can run a command like this one:

$ apropos account
acct (2)             - switch process accounting on or off
acct (5)             - process accounting file
accton (8)           - turns process accounting on or off
atopacctd (8)        - process accounting daemon
goa-daemon (8)       - GNOME Online Accounts Daemon
npm-adduser (1)      - Add a registry user account
pam_lastlog (8)      - PAM module to display date of last login and perform inactive...
pam_succeed_if (8)   - test account characteristics
sa (8)               - summarizes accounting information
userdel (8)          - delete a user account and related files
usermod (8)          - modify a user account

Update your system regularly

You should be notified on login when system packages are upgradable, but you can ask using apt (Ubuntu and related systems) or yum commands to display upgrades that are currently available:

$ apt list --upgradable
Listing... Done

$ sudo yum check-update

Get Help

Don’t ever be reluctant to look up a problem that you are having by consulting an online search tool. Nearly every problem you run into will have been seen and resolved before and many Linux geeks are happy to post solutions that have worked for them.

Choose sudo

Use sudo whenever you need to run a command as root. Switch user to root only when you need to do something that takes a long series of commands or that are difficult to accomplish using sudo. This limits your use of root privilege and makes it less likely that you will run a command as root that has more serious consequences than you were expecting.

Learn a new scripting language

Spend some of the time that you’re not chasing down problems and installing software to learn a new scripting language. Having a handle on both bash and python, for example, will give you some options for choosing the best language for the problem at hand.

Be grateful if you’re able to work from home

If you’ve been able to work from home during the pandemic, pause every now and then and take a deep breath. Be grateful for all the geeks over the years that have made telecommuting possible and have provided tools to make it easy to manage and use systems remotely.

Remember that Linux is fun

Never lose track of the fact that Linux is fun to use. The more you learn about it, the more you will enjoy its clever commands and powerful tools. From helping you troubleshoot your problems to suggesting fixes for your typos, Linux can help you make 2021 a more fun and productive year.

sandra_henrystocker
Unix Dweeb

Sandra Henry-Stocker has been administering Unix systems for more than 30 years. She describes herself as "USL" (Unix as a second language) but remembers enough English to write books and buy groceries. She lives in the mountains in Virginia where, when not working with or writing about Unix, she's chasing the bears away from her bird feeders.

The opinions expressed in this blog are those of Sandra Henry-Stocker and do not necessarily represent those of IDG Communications, Inc., its parent, subsidiary or affiliated companies.