Gregg's MOTD

Tips & Tricks that I've Encountered Over the Years...

Sorting Stuff in the VIM Buffer

August 07, 2023 — Gregg Szumowski

Suppose I have a file that I am editing in vim with the following contents:

$ cat file.txt
Red 4
Blue 3
Green 1
Orange 7
Black 8
Yellow 6
Purple 2
White 5

If I want to sort this data in vim, the first thing to do is to format it into columns using the column command:

:%!column -t

Which will put the data in the following format:

Red 4
Blue 3
Green 1
Orange 7
Black 8
Yellow 6
Purple 2
White 5

Then we can sort on the 2nd column using the sort command:

:%!sort -k2nr

Which will update the buffer like this:

Black 8
Orange 7
Yellow 6
White 5
Red 4
Blue 3
Purple 2
Green 1

Tags: cli, vim, sort, motd

How to recursively find the latest modified file in a directory

July 11, 2023 — Gregg Szumowski

find . -type f -printf '%T@ %p\n' | sort -n | tail -1 | cut -f2- -d" "

Tags: cli, find, sort, tail, cut, motd

How To Count All The Files Extension Recursively In Linux

May 09, 2023 — Gregg Szumowski

To count all the files by file extension recursively on the command line

$ find . -type f | sed -n 's/..*.//p' | sort | uniq -c
40 3g2
5 AVI
13 DS_Store
28 JPG
30 MOV
133 MP4
64 THM
1 docx
18 jpg
1 json
4 m3u
89 m4a
2 m4r
156 m4v
41 mkv
112 mov
38 mp3
587 mp4
1 nfo
2 osp
30 png
1 sh
4 srt
6 svg
10 torrent
6 txt
5 webm
10 zip

Tags: cli, motd, find, sed, sort, uniq