Essential Shell Scripting Commands


Shell Scripts

Shell scripts allow users and administrators to automate tasks using a scripting language like Bash or PowerShell.

  • essential for automation
  • good for:
    • creating backups
    • automating software updates
    • installing software
    • automating system maintenance
  • Analysts can use shell scripts to
    • locate important information stored in logs
    • automate complicated commands

Shell Command Processor Types

ShellNameDescription
kshKorn ShellTypically used on proprietary UNIX systems, such as IBM’s AIX.
shBourne ShellA simple, lightweight shell found on most *nix systems and devices.
cshC ShellOften associated with proprietary UNIX, such as Oracle’s Solaris.
tcshC ShellAn improved version of C Shell, available for many platforms.
bashBourne Again ShellAn improved version of sh and very widely used.
zshZ ShellExpands upon Bash shell and supports many plugins to expand its functionality.

Common Shell Commands

CommandDescription
catDisplay the content of a file.
tailDisplay the last 10 lines of a file.
headDisplay the first 10 lines of a file.
touchCreate an empty file.
mkdirCreate a directory.
cpCopy a file (or directory).
mvMove an object, such as a file. Also used to rename files and directories.
rmRemove a file or directory.
fileDetermine the type of a file.
lsDisplay the contents of a directory.
locateSearch for files. Locate uses a database to improve speed and efficiency of searches.
findSearch for files by parsing the file system.
wgetSimple command to retrieve content from an HTTP server.
curlSimilar to wget but includes more sophisticated options.

Administrative Shell Commands

CommandDescription
vi/vimA file editor for use in a terminal. Very popular but nonintuitive to use.
suSubstitute or switch user.
sudoPrecedes a command that requires elevated privileges.
useraddCreate a user account.
usermodChange the attributes of a user account.
chmodDetermines who is allowed to make what changes to a particular file or folder.
chownDetermines who owns a particular file or folder.
mkfifoSimilar in concept to a standard | style pipe but implemented as an actual file.