Shell Commands and Utilities

Updated 28-Jun-2024

This is a terse collection of commands and utilities I find useful for shells. There is little distinction between programs and commands as commands are programs (and are installed or come pre-installed) and programs have commands. Also included is a shell (Fish Shell) and some other shell applications/utilities (Mosh, Nano).

bc - basic calculator

cat - display contents of files and concatenate files

cd - display contents of files and concatenate files

cp - copy files/directories

ctrl-z, jobs, fg - suspend, resume current processes

dpkg-query - Determine Installed Packages (apt)

dpkg-query -l

fd - fd-find

  • Description: fd / fdfind finds files using sensible defaults (not necessarily replacing the find command)
  • Syntax:
    • fd filename finds a filename or partial, recursively, case-insensitively
    • see this article for more syntax examples
  • Install: sudo yum install -y fd-find
  • Note: add the alias fd to the .bashrc file

fuser - file user

  • Description: fuser lists process IDs of all processes that have one or more file open.
  • Syntax:
    • fuser -k filename kills all processes using or having filename
    • fuser -k -n tcp 80 kills all processes using tcp port 80
  • Install: yum install -y psmisc
  • Note: Since everything is a file (even udp and tcp ports) then those namespaces can be queried and killed. See also fuser and lsof

grep - find text in files

  • Description: Searches within files for given text
  • Syntax: grep -Ril "text-to-find-here" /
  • Install: Should be present in any distribution
  • Note: the final / is the directory to start in, -R means recursive, -i means case insensitive, and -l means provide filenames (with path0, and not in-file context of the match.

htop - top process utilization

  • Description: Live display of processes and resource utilization
  • Syntax: htop
  • Install: yum install -y htop
  • Note: ctrl-z to suspend (jobs/ctrl-c to resume), q to quit

iotop - i/o disk utilization

  • Description: Realtime i/o use by process
  • Syntax:
    • iotop all processes with i/o locks (regardless of activity
    • iotop --only will provide only active i/o
  • Install: yum install -y iotop
  • Note: Requires python

locate - find files/directories by name (fragment)

Not sure if fd is the same or better than locate

  • Description: Quick way to find files/directories
  • Syntax: locate [file/directory (partial) name]
  • Install: yum install -y mlocate
  • Note: Remember to refresh the database with: sudo updatedb

ls - infamous list command

  • Description: List files/directories in a given path
  • Syntax:
    • ls -la long format, including hidden files
    • ls -lS long format, sort by size
    • ls -R recursive subdirectory tree list
    • ls -d */ directories only
    • ls -laRS > out.txt long format, hidden files, recursive directories, sort by file size, and output to the file out.txt
  • Install: Preinstalled in nearly all distributions
  • Note: Information about ls including an ls syntax generator

lsof - list open files

  • Description: Just as with fuser, open files include disk files, named pipes, network sockets, and devices opened by all processes.
  • Syntax: lsof /var determining which files are opened by which processes on a given volume
  • Install: yum install -y lsof
  • Note: See also fuser and lsof

mv - move files/directories

ncdu - disk space utilization

  • Description: Easy to use interface to see where disk space is being used
  • Syntax: ncdu
  • Install: yum -y install ncdu
  • Note: abbreviation stands for NCurses Disk Usage

rsync - remote sync

  • Description: Used for backup, and also can be faster than scp at copying over a network
  • Syntax: ``
  • Install: ``
  • Note: See Full system backup with rsync

scp - Secure Copy

systemctl status - Status of Systemd

This is great and helps show status, but sometimes the journal gets packed with crap. Clear up to last 2 days with:

journalctl --vacuum-time=2d

tail -f - track changes to log files in realtime

tail -f FILENAME | grep "TEXT"

This will show the last 10 lines and filter based on TEXT

pkill - kill processes

  • Description: Quick way to kill all processes with a given name
  • Syntax: pkill [process (partial) name]
  • Install: Comes with kill usually pre-installed in Linux
  • Note: will kill all instances of matching processes

Remove files with find

Better than rm, use find, e.g.,

find . -name \*.tmp -type f -delete

tar

  • Description: basically a zipping/archiving utility
  • Syntax: c for create, x for expand: tar -zcvf directory.tar.gz directory, tar -zxvf directory.tar.gz directory
  • Install: comes with most linux

s3cmd

  • Description: S3 command line tool
  • Syntax: s3cmd put file.tar.gz s3://backup/file.tar.gz
  • Install: yum install -y s3cmd
  • Note:

lftp

  • lftp a beefy ftp/ssh tool with a lot of flexibility

Shells and Shell Applications

  • Fish Shell, friendly interactive shell
  • Mosh, replacement for ssh
  • Nano, command line text editor

wrk

  • Description: web performance tool
  • Syntax: wrk -t12 -c400 -d30s https://host.domain.tld
  • Install: sudo apt-get install -y wrk
  • Note: Pay attention to configuration to get useful data

Flush dns cache

sudo /etc/init.d/networking restart

Note: if there is no dns caching configured, then the main problem is dns caching in the Chrome browser. In this case, open a new tab with the following address:

chrome://net-internals/#dns

Then click the clear host cache button.

Template

  • Description:
  • Syntax: ``
  • Install: ``
  • Note: