CLI Utilities

Table of Contents

1. File Manipulation

1.1. which

Probe what program or alias the following will execute.

1.2. whereis

Show the location of binary, source code (if available), and manpage.

1.3. whatis

Show the manpage entry.

1.4. apropos

Fuzzy-find through the manpages.

1.5. locate

It has been Unix tool for a while.

  • slocalte (secure locate), mlocate (merging locate), plocate (posting locate) are the implementations in order.
    • locate symlinks to the specific implementation.
  • updatedb command needs to run to build the databse at /var/lib/plocate/plocate.db.
  • plocate
    • It uses trigrams to index the database the index is inverted (from trigrams to files)

1.6. find

find [STARTING_POINTS...] EXPRESSION
  • STARTING POINT is any directory or file
    • Multiple of them can be given and each one of them is traversed left to right.
    • Current directory is assumed when not given.
  • EXPRESSION: any expression evaluates to either true or false.
    • Global: Always true
      • -maxdepth N: 0 means the starting point itself, and 1 means the child of it, and so on.
      • -mindepth N: does not evaluate the expression when depth is less than N
    • Test: true if matched
      • -name PATTERN: match the file name using the shell file name pattern (*, ?)
      • -iname PATTERN: case insensitive match
      • -path PATTERN: match the entire file path to the pattern.
      • -regex PATTERN: use regular expression to match the file name.
      • -type {b|c|f|s|...} match the file type
      • -size N[k|M|G] size of N kilo/mega/gigabytes.
      • -amin N, accessed N miniutes ago, -atime N accessed N days ago
        • +N or -N can be used to indicate "more than" and "less than".
        • -cmin N, -ctime N, -mmin N, -mtime N for changes and modified reprectively.
    • Action: true on seccess.
      • -delete
      • -exec COMMAND \;: run the command for the matched file. '{}' is replaced by the file name. Note that \ and ' are there to prevent the shell parsing it.
      • -print: print the full file name
      • -prune: stop descending further into this directory.
      • -quit: exit.
    • Operator
      • \( EXPR \): force precedence
      • \! EXPR, -not EXPR (not POSIX): true if EXPR is false.
      • EXPR1 EXPR2, EXPR1 -a EXPR2, EXPR1 -and EXPR2 (not POSIX)
      • EXPR1 -o EXPR2, EXPR1 -or EXPR2 (not POSIX): it has lower precedence than AND.
      • EXPR1 , EXPR2: EXPR1 is evaluated and discared. The value of EXPR2 is the value of the list.
  • -print is implicit after the whole expression, unless -delete, -exec, -print, … is used.

1.7. namei

Take a path pattern and return the information of directories along the path.

1.8. umask

Set the creation file mode for the current environment.

1.9. mknod

  • mknod [OPTION] NAME TYPE [MAJOR] [MINOR]
  • -m --mode=MODE permission mode
  • TYPE
    • b buffered block file
    • c u buffered/unbuffered character file
    • p FIFO
  • MAJOR MINOR
    • It must be specified for b c u
    • 0x 0X 0 == hexadecimal, octal, decimal

1.10. split

  • Divide a file into smaller ones.
  • -b: size, -n: division, -l line, --filter 'gzip > $FILE.gz': post-action hook.

The splitted files can be combined with cat on Linux, copy /b FILE1 + FILE2 OUTFILE on Windows.

7z -v SIZE also does the simple split on the compressed file.

1.11. link

  • Creates hard link by directly interacting with the system.

1.12. entr

1.13. mkfifo

  • Creates a named pipe, which can be accessed from multiple sessions.

1.14. tee

  • Pipe input to both standard output and a file.

1.15. sync

  • Flushes cached data.

1.16. od

  • Octal dump. POSIX. Can be used for other bases.

1.17. dd

  • The options are given as variables format
  • bs ibs obs byte size
  • if of input, output files
  • count skip
  • conv convert while copying, status progress

1.18. shred

Zeroes out the file and then unlink

1.19. stdbuf

Controls the buffer of standard input and output.

1.20. truncate

Modifies file size.

1.21. lsof

List open files

  • Note that everything is a file in UNIX-like systems.
  • -i list all open network connections?

1.22. tar

tape archive

  • -c create. should be used with -f to set the archive filename
  • -x extract. should be used with -f to select the archive
    • It detects the compression algorithm automatically, but it can be set manually also.
    • -a --auto-compress detect the compression algorithm based on the archive suffix.
  • -f select the file or filename.
  • -v verbose
  • filter through -z gzip , -Z compress, -j bzip2, -J xz, -I COMMAND use COMMAND.

1.23. zip

  • zip OPTIONS ARCHIVE FILES

1.24. cpio

copy in and out. It copies files between archives and directories.

  • -o --create
  • -i --extract
  • --file
  • --block-size=BLOCK-SIZE set the I/O block size
  • -D --directory=DIR
  • -c old portable archive format, -H --format=FORMAT use the FORMAT, the default format one is newc?
    • bin obsolete binary format
    • odc old POSIX.1 portable format
    • newc new SVR4 portable format
    • crc SVR4 format with checksum
    • tar
    • ustar
    • hpbin
    • hpodc

1.25. stow

1.26. cwebp and dwebp

  • Compress and decompress into and out of .webp
  • dwebp WEBP -o PNG/JPG
  • cwebp IMAGE -o WEBP -q [0-100]

1.27. qpdf

Transform PDF files. For example, encryption and decryption, or web optimization.

1.28. pandoc

1.28.1. Extensions

  • auto_identifiers: Add id field, even if it does not have the id field itself.

1.28.2. Filter

Define a function with a name of a element, that returns a new element.

  • pandoc.ELEMENT create a new element.

2. Text Manipulation

2.1. join

  • Relational SQL-like join on two text files.

2.2. fold

  • Wrap the text to a specified width.

2.3. pr

  • Paginate or columnate text for printing.

2.4. tac

  • Reverse strings.

2.5. shuf

  • Shuffle input.

2.6. sort

  • Sort input.

2.7. sed

  • See

2.8. uniq

  • Make each word from input unique.

2.9. tr

  • Translate(replace) single byte characters.

2.10. jp2a

  • Convert JPEG image to ASCII art.

2.11. comm

  • Perform set operations.
    • $ comm -12 A B
    • Flags
      • 1 : Remove elements only in the first set
      • 2 : Remove elements only in the second set
      • 3 : Remove elements in both the first and the second set

2.12. seq

  • seq <initial> <increment> <quantity>

2.13. jq

2.14. sed

  • Stream Editor
    • It processes text line by line.
  • The stream version of the ed, the original UNIX text file editor, which also used similar commands.
  • The structure is inherited by .

2.14.1. Options

  • -i
    • In-place editing. Directly changes the text file.
  • -z
    • Replace \n with NULL, then ^, $, \n matches with NULL. This enables multi-line editing.
  • -n --quiet --silent
    • Suppress the automatic printing of pattern space
  • -e SCRIPT
    • Each command in the script is separated by a newline.
    • \w \s. \d does not work. Use [0-9]
    • \0, & for the entire match
    • [abc] *
    • \U to upper, \L to lower, \E return to normal
  • -r -E --regexp-extended
    • (abc) \1 \N Grouping
    • {N} + ? repeat.
  • -f SCRIPTFILE

2.14.2. Commands

  • : LABEL
  • #COMMENT
  • ADDRESS { COMMANDS }
2.14.2.1. Addresses
  • NUMBER, FIRST~STEP match line numbers
  • $ last line
  • /REGEXT/ \<C><REGEXP><C> line that matches the
  • 0,ADDRESS until ADDRESS is found
  • ADDRESS,+N N lines follwing ADDRESS
  • ADDRESS,~N from ADDRESS to the line number N or its multiples.
2.14.2.2. Zero-, One-Address Commands
  • = print the line number
  • a TEXT append text into the next line. \<ret> is used to insert newlines.
  • i TEXT insert text into the previous line.
  • q quit
  • r FILENAME append text from the file. R append one line at a time from the file
2.14.2.3. Address Range Commands
  • c TEXT
  • d delete pattern space
  • h copy pattern space to hold space, H append to hold space
  • g copy hold space to pattern space, G append to pattern space
  • n read the next line into the pattern space, N append into the pattern space
  • p print the pattern space
  • s/REGEXP/REPLACEMENT/ replace the within pattern space.
    • \1 through \9 is available, with -r
      • \0 or & can be used without -r
    • s/^/REPLACEMENT/ appends in the beginning of a line.
    • \<PATTERN\> matches a word. same as \bPATTERN\b
    • \d does not match the number since they are strings.
  • w FILENAME write the pattern space to a file. W write one line at a time
  • y/SOURCE/DEST/ transliterate. See ((669f0999-d1e0-46f6-b0cf-0f57d2148067))
  • b LABEL branch to LABEL. If LABEL is omitted branch to the end of script.
  • t LABEL if substitution succeeds, branch to LABEL, T LABEL if no substitution succeeds.

2.14.3. Examples

  • sed -z 's/\ntime: /T/g' -i **/*.md
  • sed 's/^/# /' # comment out

2.15. awk

  • Al *A*ho, Peter *W*einberger, Brian *K*ernighan
  • The text file manipulator, powered by yacc
    • with a Scripting Language
    • The program is reimplemented under GNU project as gawk, powered by the reimplementation of yacc, bison.

2.15.1. Syntax

  • pattern { action }
2.15.1.1. Patterns
  • BEGIN, END special pattern that matches the start and end of a program
    • BEGIN can be used for initialization of the environment variables.
  • /regex/
  • || && ! ? : ,
2.15.1.2. Actions
  • print, printf
    • "TEXT"
    • It can be redirected to a file with > and >>
    • It can be piped to external commands with |,
    • $0 is the entire record. $N is the =N=th field.
  • ** Special Variables
    • ARGC the number of arguments
    • ARGV array of arguments
    • FS field separator regular expression
    • NR the current line number
    • OFS output field separator
    • FILENAME the current input file path

3. Process Manipulation

3.1. pstree

  • Show the entire process tree.

3.2. top

  • Monitor the processes
    • Keybindings
      • h help
      • < > change the sorted column
      • f change the properties to display
      • Z change the color scheme
      • A toggle multi-window view
      • V toggle forest (process trees)
        • v fold a branch
      • W save this preset
      • i hide idle processes
      • c toggle full commands
      • u, o filter processes
      • Toggle: <C-p> namespaces (cgroup: , ipc: , …), <C-n> environment variables, <C-u> supplementary groups (plugdev, wheel, harry), <C-k> full commands, <C-g> control groups (0::/user.slice/…).
      • q exit

3.3. nproc

  • Show the number of processors.

3.4. nice

  • Set a nice value to a program so that smaller valued ones finish faster on average.

3.5. fuser

  • Show which process is using a file or a device. With -n tcp <port> flag, it shows which process is using a tcp port.

3.6. timeout

  • timeout 2h <command>
    • Terminate the command based on time.

3.7. env

  • Set environment variables for the process

3.8. parallel

  • GNU Parallel
    • Execute multiple jobs of the command given in a special format, each with given arguments.
    • {} argument, {.} argument without file extension, …
    • ::: arguments, < arguments file

3.9. yes

Print y repeatedly, so that it can be piped to another program.

3.10. printenv

Print the current environment variables.

3.11. setsid

Execute command in an existing process.

4. Machine Control

4.1. systemctl soft-reboot

Keep the kernel, reboot the user space.

5. Networking

5.1. tcpdump

Monitor packets

5.2. netstat

from core/net-tools

5.3. ss

dump socket statistics.

6. Programming

6.1. nm

list symbols from object files

6.2. Reverse Engineering

6.2.1. IDA

6.2.2. Ghidra

6.2.3. objdump

7. Audio Player

7.1. mpd

It is the media server that can host various musics. I feel like this is not a good option for personal music player.

7.2. mplayer

It is a CLI tool, that has separate frontend: smplayer, etc. These tools is not well-maintained.

7.3. mpv

Audio and video player based on MPlayer, mplayer2, and FFmpeg.

7.3.1. OSC Customization

8. Miscellaneous

8.1. neofetch

  • It is configurable

8.2. cowsay

  • Animals other than cow is also available.

8.3. fortune

  • Random quotes

8.4. figlet

  • ASCII text stylizer

8.5. lolcat

8.6. cava

  • Audio visualizer

8.7. pipes

  • Screensaver

8.9. minimodem

  • Generate modem signal based on input.

8.10. tldr

  • Short version of man page. It provides a quick snippets.

8.11. id

  • Show uid, gid and others of a given user (current user if unprovided).

8.12. fzf

  • Fuzzy find command.

8.13. btop

rocm-smi-lib is required to display GPU informations.

8.14. expr

Evaluate the expression. Each component of the expression must be separated by space, and the reserved characters must be escaped.

  • String manipulation with
    • STRING : REGEXP, match STRING REGEXP, length, index, substr STRING POS LEN
  • Arithmetic operation with
    • + - * / % > < = >=
    • n | m if n=0 return m; else return n, n & m if n=0 && m=0 return 0; else return n
    • Precedence is controlled by parenthesis. They need to be escaped in Bash.

8.15. date

  • Print datetime
    • -d STRING --date=STRING use this datetime.
    • +FMT format it
    • -u --utc --universal print or set UTC
    • --rfc-3339={date|hours|minutes|seconds|ns}
    • -I --iso-8601={date|hours|minutes|seconds|ns} use ISO format

8.16. bc

  • Arbitrary precision calculator

This program is too basic to be useful for complex calculation

The syntax is identical to plain C without semicolon and types. Note that semicolon is still used to separate statements in a statement list {...; ...}.

Every variable is assumed to be a number, string cannot be assigned to a variable. String must be surrounded by ".

The function is defined with the keyword define:

define [void] <name> ( <parameters> ) {
  <statements>
}

If void keyword is used the function returns nothing instead of zero (the value of print).

Some expressions are builtin.

  • return (EXPR).
  • length (EXPR) the number of digits before the decimal point, scale (EXPR) the number of digits after the decimal point.
  • read(), scale(EXPR) the precision, sqrt(EXPR)
  • print EXPR1, EXPR2, ...

With math library (-l or --mathlib), six functions are defined:

  • s (x) sine (in radian)
  • c (x) cosine
  • a (x) arc tangent
  • l (x) natural logarithm
  • e (x) exponential function
  • j (n,x) Bessel function

The exit keyword is quit

Author: Jeemin Kim

Created: 2026-07-12 Sun 14:28