Shell Commands and Utilities

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).

Shell Commands

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

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)

  • Description: Quick way to find files/directories
  • Syntax: locate [file/directory (partial) name]
  • Install: yum install -y locate
  • 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

nmon - Nigel's Performance Monitor

  • Description: Various resource monitor screens for the command line
  • Syntax: nmon
  • Install: For CentOS 7 (thanks to sebkouba)
mkdir nmon-temp
cd nmon-temp
wget http://sourceforge.net/projects/nmon/files/nmon16e_mpginc.tar.gz
tar -xzvf nmon16e_mpginc.tar.gz
cp nmon_x86_64_centos7 /usr/local/bin/
chmod a+x /usr/local/bin/nmon_x86_64_centos7
ln -s /usr/local/bin/nmon_x86_64_centos7 /usr/local/bin/nmon
cd ..
rm -rf nmon-temp
  • Note: Toggle the different screens using keyboard shortcuts, h for help

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

pkill - kill processes

  • Description: Quick way to kill all processes with a given name
  • Syntax: pkill [process (partial) name]
  • Install: yum install -y pkill
  • Note: will kill all instances of matching processes

Template

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

Shells and Shell Applications

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

Leave a Reply