Handy Linux Terminal Commands

If there is one thing that I love about Linux, it's that I always find new ways to simplify complex tasks that would have otherwise taken me hours or days to do. In this article, I'll list some of the most useful terminal commands that I use to get things done.

At the time of writing article, I'm using Arch Linux (btw). However, if you don't have the commands listed below already installed, you should be able to find them with your distributions package manager.

Moving a lot of specific files to another folder

If you have a lot of files mixed with other file types in a folder, and want to move a specific bunch of files based on file extension to another folder (for example video files), you can do this using the fd and mv commands:

1# Moving a bunch of video files to the Vidoes folder
2cd Downloads/
3# Find all files ending in .mkv and move them to ~/Videos
4fd -g --extension 'mkv' -x mv '{}' ~/Videos/ \;

Setting HUGO markdown "front matter" values

When switching between HUGO themes, I often find that some of them are more suited to a Table of Contents (toc:) display than others. Using the following command, I can easily toggle all the toc: values in all the markdown files front matter to true or false using grep and sed from within the website/content folder.

1cd ~/my-hugo-website/content/
2grep -r --only-matching "toc: true" . | sed -i 's/toc: true/toc: false/g'

Remove spaces

Remove the spaces from filenames and replace with an underscore.

1for f in *; do mv "$f" `echo $f | tr ' ' '_'`; done

Quickly understand a command

Anyone who has ever typed man find will know what I mean here. You just want to remember how to quickly use a command - but don't want to read the whole man page on it.

Use tldr for a quick reference on a command:

1tldr find
1tldr awk

Free up disk space

Having been working with Large Language Models (LLM's) lately, I often find myself quickly running out of hard disk space because of how large these files are. To solve this issue, I use a tool called ncdu to check which files are taking up a lot of space.

1cd Projects/
2ncdu

I can then use the arrow or vim keys to navigate into folders and press the "d" key to delete any files I no longer use.

We can do the same for the $HOME folder, but this time ignore the timeshift backup folder to speed things up.

1ncdu --exclude timeshift ~/

Upgrade many package installations at once

You may have used you personal distros package manager many times before, but did you know that there is a program that can update nearly everything you have installed? From system packages, AUR, Flatpak, vim, conda, GE-Proton and more.

The program is called topgrade and I use it a lot.

Upgrade everything apart from git repos:

1topgrade --disable="git_repos"

See man topgrade for more info.

Conclusion

Linux provides users with many ways to do things, which can make your life easier and allow you to work smarter. The more I learn about Linux, and how to use the operating system more effectively, the more I realize why I could never use anything else.