Settings

Theme

Ask HN: What are your favorite UNIX tools?

11 points by aadhavans 10 months ago · 14 comments · 1 min read


Either built-in tools, or those that follow the UNIX philosophy.

My favorite hidden gems in a base UNIX install are `tac` (print lines in reverse order) and `tr` (character substitutions).

wruza 10 months ago

Most: grep, find, cat, sort, tail, wc, ls, sudo, pgrep.

Interesting: comm: https://linux.die.net/man/1/comm

Compare sorted files FILE1 and FILE2 line by line.

With no options, produce three-column output. Column one contains lines unique to FILE1, column two contains lines unique to FILE2, and column three contains lines common to both files.

-1 suppress column 1 (lines unique to FILE1)

-2 suppress column 2 (lines unique to FILE2)

-3 suppress column 3 (lines that appear in both files)

Weak: adduser/useradd (hard to non-interactive), chmod (could use file/dir filter with -R).

Least: systemctl, journalctl.

  • commandersaki 9 months ago

    One trick I learned from a UNIX greybeard in my junior days before pgrep was widely avaialble is: ps auxw | grep [p]rocessname and it will eschew the grep process in the list.

PaulHoule 10 months ago

awk

(It's a guilty pleasure to write shell pipelines that use awk to write a shell script and then pipe that script in sh, I find it easier than looking up the bizzaro syntax for loops in bash in the info pages.)

  • aadhavansOP 10 months ago

    > use awk to write a shell script

    Do you have any examples of this?

    • PaulHoule 10 months ago

      How about

          ls -l *.txt | awk '{if ($5<2000) print "cat " $9}' | sh
      
      to cat text files that are less than 2000 bytes long
kasperset 10 months ago

find

My command to backup selected file using Tarsnap. find /Users/xyz/Analysis -type f \( -name '.pdf' -o -name '.docx' \) -print0 | tarsnap --dry-run --no-default-config --print-stats --humanize-numbers -c --null -T-

This command file files ending with docx and pdf to back with tarsnap. The "-" following the "-T" option allows to pass the name using std-in via find command

vermasque 10 months ago

pbpaste and pbcopy to read and write to the clipboard and then combine with your favorite grep, sed, tr, cut, etc.

t-3 10 months ago

perl-rename - rename is also good, but much more annoying to use for me as it doesn't use standard regex notation like perl-rename.

printf - shell is natively great at interpolation already, but having C-style printf formatting is often useful and echo has a lot of footguns

bediger4000 10 months ago

tr is surprisingly useful. If you're clever, the -c and -d flags can do good things.

wc is also useful, mostly as "wc -l". If you keep data in line oriented, human readable form, "wc -l" counts data items.

caprock 10 months ago

ctrl-r in bash tops my list, even if it's not quite what you are thinking of as a unix tool.

Probably the pipe itself would be my favorite next.

Then in no particular order: tail, cut, xargs, wc, tr, grep, sort, uniq.

manbart 10 months ago

xclock with the cat theme

commandersaki 9 months ago

comm & awk

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection