Useful Utils

Utility is when you have one telephone, luxury is when you have two, opulence is when you have three - and paradise is when you have none - Doug Larson

This page is a collection of tools that I have found useful over the years. I anticipate that it will grow as I remember tools or new tools come up.

Trash-cli

This Linux utility has prevented me from using the dreaded ‘rm -rf’ command in my root directory. Trash-cli is an alternative for the “remove” or rm command.

On Ubuntu or Red Hat the package name is the same: trash-cli. On Red Hat simply enter:

sudo dnf install trash-cli

Running the “trash” command after installing the package sends the files to the "trash" -- rather than the operating system completely removing them. — see Trash (computing) - Wikipedia. Trash works for files and directories, making it a drop-in replacement for rm.

Example usage:

Let’s see this in action. Open a terminal in Linux and enter:

touch test.txt
trash test.txt

Confirm the file is gone using ls. Fear not though, it is only in the trash! Enter trash-restore at the terminal and you should see it somewhere in the list. My terminal yields:

[mday@localhost ~]$ trash-restore

   0 2023-04-14 15:03:10 /home/mday/…/devel-rpms.tar.gz

   1 2023-04-18 08:50:32 /home/mday/test.txt

What file to restore [0..1]:

This says there are 2 entries in my trash and I want the second one so I enter ‘1’

A simple ls command should reveal that the file has been restored!

df -h

To visualize disk usage on Linux in a human-readable format enter:

df -h

There are many other options for the df command as well. When I enter it I in my Red Hat Enterprise Linux Virtual Machine I get:

[mday@localhost ~]$ df -h

Filesystem             Size  Used Avail Use% Mounted on

devtmpfs               3.9G     0  3.9G   0% /dev

tmpfs                  3.9G     0  3.9G   0% /dev/shm

tmpfs                  3.9G  9.3M  3.9G   1% /run

tmpfs                  3.9G     0  3.9G   0% /sys/fs/cgroup

/dev/mapper/rhel-root   14G  9.6G  3.8G  72% /

/dev/sda1             1014M  356M  659M  36% /boot

C_DRIVE                944G  335G  610G  36% /media/sf_C_DRIVE

tmpfs                  796M   24K  796M   1% /run/user/1000

ps -aux

My favorite way to see what processes are running on Linux is:

ps -aux

There are many other options for the ps command as well.

Example usage:

To list all of the processes currently running enter the command:

ps -aux

This results in something like the following:

mday        2422  0.3  0.5 695896 42468 tty2     Sl+  08:14   0:00 /usr/libexec/platform-python

mday        2430  1.1  1.0 1267372 81508 tty2    Sl+  08:14   0:00 /usr/bin/gnome-software --ga

mday        2432  0.2  0.3 748656 31564 ?        Ssl  08:14   0:00 /usr/libexec/tracker-store

mday        2435  0.0  0.0 214924  7660 ?        Sl   08:14   0:00 /usr/libexec/dconf-service

mday        2437  0.2  0.6 1310288 49928 ?       Ssl  08:14   0:00 /usr/libexec/evolution-addre

mday        2442  0.3  0.7 1375692 64580 tty2    Sl+  08:14   0:00 /usr/libexec/evolution/evolu

mday        2458  0.0  0.1 301372  8888 tty2     Sl+  08:14   0:00 /usr/libexec/gsd-disk-utilit

mday        2472  0.2  0.3 906572 26116 tty2     SNl+ 08:14   0:00 /usr/libexec/tracker-miner-a

mday        2476  0.2  0.3 850544 28016 tty2     SNl+ 08:14   0:00 /usr/libexec/tracker-miner-f

mday        2496  0.0  0.0 253248   308 ?        S    08:14   0:00 /usr/bin/VBoxClient --clipbo

mday        2497  0.0  0.0 453476  2124 ?        Sl   08:14   0:00 /usr/bin/VBoxClient --clipbo

mday        2518  0.0  0.0 253248   308 ?        S    08:14   0:00 /usr/bin/VBoxClient --seamle

mday        2519  0.0  0.0 451536  2752 ?        Sl   08:14   0:00 /usr/bin/VBoxClient --seamle

mday        2530  0.2  0.6 1588300 51144 ?       Sl   08:14   0:00 /usr/libexec/evolution-addre

mday        2536  0.0  0.0 253248   308 ?        S    08:14   0:00 /usr/bin/VBoxClient --dragan

mday        2538  0.3  0.0 517588  2804 ?        Sl   08:14   0:00 /usr/bin/VBoxClient --dragan

mday        2539  0.0  0.0 253248   308 ?        S    08:14   0:00 /usr/bin/VBoxClient --vmsvga

mday        2540  0.0  0.0 385352  2440 ?        Sl   08:14   0:00 /usr/bin/VBoxClient --vmsvga

root        2686  0.2  0.3 846952 25828 ?        Ssl  08:14   0:00 /usr/libexec/fwupd/fwupd

mday        2719  1.3  0.4 730096 39452 ?        Ssl  08:15   0:00 /usr/libexec/gnome-terminal-

mday        2724  0.0  0.0 226364  5468 pts/0    Ss   08:15   0:00 bash

root        2841  0.0  0.0 217084   912 ?        S    08:15   0:00 sleep 60

mday        2877  0.0  0.0 271488  4184 pts/0    R+   08:16   0:00 ps -aux

Let’s see how to use ps in conjunction with kill!

kill & kill -9

Speaking of processes: want to kill a process in Linux? Just use:

kill <process-id>

In the example above, to kill the bash process running under my user id enter:

kill 2724

at the terminal.

If you want to try this at home it is nearly certain you want a different number than 2724! See process identifier.

But that didn’t work! The reason is because I am currently logged in to the bash shell session in question and the system is trying to prevent me from doing something it thinks is dumb. The answer: kill -9. Let’s try it now!

kill -9 2724

Again, you will need to enter a different process identifier if you want to try this on your machine.

That worked! My bash session abruptly terminated! To understand what happened see this stackoverflow thread. In a nutshell what happens when you enter kill is that the operating system asks nicely to end the process. The -9 does away with the asking nicely part.

More utilities to come (probably)…

Previous
Previous

Demystifying Regular Expressions

Next
Next

VirtualBox Red Hat Guest on Windows Host