Small Utilities I Like

Standard Linux

stat

Show file info.

1stat little_programs.md
1  File: little_programs.md
2  Size: 5277            Blocks: 16         IO Block: 4096   regular file
3Device: 805h/2053d      Inode: 6554954     Links: 1
4Access: (0644/-rw-r--r--)  Uid: ( 1000/   ghost)   Gid: ( 1000/   ghost)
5Access: 2022-02-21 20:48:37.840867061 +0100
6Modify: 2022-02-21 20:41:44.774001797 +0100
7Change: 2022-02-21 20:41:44.778001768 +0100
8 Birth: 2022-02-21 20:41:44.774001797 +0100

file

Show what type of file something is.

1type /tmp/\*
1amfora_temp:           directory
2dbus-U00gxuKxNT:       socket
3scoped_dirNCvmsA:      directory
4serverauth.ELLhbMvz60: X11 Xauthority data

watch

Watch a command for changes in the output.

1watch cat /proc/net/arp

Or watch how much of the filesystem is free.

1watch df -h

Timeout

Let a command run for a limited amount of time:

1timeout 3 htop

Useful if you want a process to automatically run, but it's in danger of stopped, and asking you some questions. For example, if you want to 'apt update', then that might work, but it might stall until you answer a question. You can't really answer that question if the thing is running as part of a script, so to avoid having it hang, just cancel it after 10 minutes (or some time longer than an upgrade might take).

NB: When using sudo, the timeout command will apply to sudo itself, so best to run after the sudo, e.g.

1sudo timeout 10m apt upgrade -y

This may still lock the database, but at least you won't have a bunch of useless scripts building up.

New Utilities

cloc

Count the lines of code in a repository.

1cloc *project*
 1      59 text files.
 2      48 unique files.
 3      18 files ignored.
 4
 5github.com/AlDanial/cloc v 1.92  T=0.05 s (879.2 files/s, 181191.9 lines/s)
 6-------------------------------------------------------------------------------
 7Language                     files          blank        comment           code
 8-------------------------------------------------------------------------------
 9C++                              7            934            255           4916
10C/C++ Header                     8            103            106            724
11TeX                              7            113             16            660
12CSV                              8              0              0            654
13Python                           4             59             49            652
14Markdown                         3            187              0            220
15Bourne Shell                     4             34             14            121
16make                             5              0              0             49
17YAML                             1              0              0             15
18CMake                            1              3              5              3
19-------------------------------------------------------------------------------
20SUM:                            48           1433            445           8014
21-------------------------------------------------------------------------------

This can be useful for an overview of a project. The program is also great at counting actual lines of code, rather than just lines. The following contains 6 lines:

1ls -t | \
2sort -r > list
3
4
5cat < list

cloc will recognize blank lines are not lines of code, and recognize joined lines of code as separate.

duf

This outputs disk usage with a nice display.

1duf -only local
1╭────────────────────────────────────────────────────────────────────╮
2│ 2 local devices                                                    │
3├────────────┬────────┬────────┬────────┬────────┬──────┬────────────┤
4│ MOUNTED ON │   SIZE │   USED │  AVAIL │  USE%  │ TYPE │ FILESYSTEM │
5├────────────┼────────┼────────┼────────┼────────┼──────┼────────────┤
6│ /          │ 117.6G │  63.7G │  47.8G │  54.2% │ ext4 │ /dev/sda5  │
7│ /boot/efi  │ 602.1M │ 152.0K │ 602.0M │   0.0% │ vfat │ /dev/sda6  │
8╰────────────┴────────┴────────┴────────┴────────┴──────┴────────────╯

notify-send

Output a message to your desktop.

1sleep 8m && notify-send Tea 'water boiling' & disown

This will output a notification to finish making tea in 8 minutes. The 'disown' statement tells the terminal to leave the process running, even without the terminal.

fzy

This gives you the ability to type through a list to select an item.

Try this for a start:

1ls | fzy
 1ghost [ ~ ]
 2└─►─ ls | fzy
 3> 
 4Distros
 5LK
 6Mail
 7Projects
 8VMs
 9arc
10dl
11gollum
12img
13kn

Okay - not terribly impressive so far. But we can do things with the output.

1cd $(find ~/\* -type d | fzy)

Now we can find anywhere in the home directory and change directory there instantly. Or open any nearby file in vim:

1alias vf='vim "$(find -type f | fzy)"'
1vf

Now you can just type in vf and type the name of a file you want to edit, and fzy will find it for you.

onefetch

Output a summary of a Git.

 1$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$   Malin Freeborn ~ git version 2.35.1
 2$$$            $$$$$$$      $$$$$     $$   -----------------------------------
 3$$  $$$$  $$$$  $$$$$$$$$  $$$$$$$ $$$$$   Project: core (3 branches, 6 tags)
 4$$ $$$$$  $$$$$ $$$$$$$$$$  $$$$$ $$$$$$   HEAD: 115ba07 (dev, origin/dev)
 5$$ $$$$$  $$$          $$$$  $$$ $$$$$$$   Pending: 20+-
 6$$ $$$$$  $$$$$  $$$$$  $$$$  $ $$$$$$$$   Version: 0.6
 7$$$$$$$$  $$$$$  $$$$$$ $$$$$  $$$$$$$$$   Created: 2 years ago
 8$$$$$$$$  $$$$$  $$$$$$ $$$$$  $$$$$$$$$   Language: TeX (100.0 %)
 9$$$$$$$$  $$$$$  $$$$$$$$$$$$   $$$$$$$$   Authors: 100% Malin Freeborn 2188
10$$$$$$$$  $$$$$  $$$ $$$$$$$ $$  $$$$$$$            0% Vladar4 1
11$$$$$$$$  $$$$$      $$$$$$ $$$$  $$$$$$   Last change: a week ago
12$$$$$$$$  $$$$$  $$$ $$$$$ $$$$$$  $$$$$   Repo: https://gitlab.com/bindrpg/core
13$$$$$$$$  $$$$$  $$$$$$$$ $$$$$$$$  $$$$   Commits: 2189
14$$$$$        $$  $$$$$     $$$$$$     $$   Lines of code: 8416
15$$$$$$$$$$$$$$$  $$$$$$$ $$$$$$$$$$$$$$$   Size: 11.22 MiB (78 files)
16$$$$$$$$$$$$$$$  $$$$$$ $$$$$$$$$$$$$$$$   License: GPL-3.0-only
17$$$$$$$$$$$$$           $$$$$$$$$$$$$$$$
18$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$