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
| Shell | Name | Description |
|---|
| ksh | Korn Shell | Typically used on proprietary UNIX systems, such as IBM’s AIX. |
| sh | Bourne Shell | A simple, lightweight shell found on most *nix systems and devices. |
| csh | C Shell | Often associated with proprietary UNIX, such as Oracle’s Solaris. |
| tcsh | C Shell | An improved version of C Shell, available for many platforms. |
| bash | Bourne Again Shell | An improved version of sh and very widely used. |
| zsh | Z Shell | Expands upon Bash shell and supports many plugins to expand its functionality. |
Common Shell Commands
| Command | Description |
|---|
cat | Display the content of a file. |
tail | Display the last 10 lines of a file. |
head | Display the first 10 lines of a file. |
touch | Create an empty file. |
mkdir | Create a directory. |
cp | Copy a file (or directory). |
mv | Move an object, such as a file. Also used to rename files and directories. |
rm | Remove a file or directory. |
file | Determine the type of a file. |
ls | Display the contents of a directory. |
locate | Search for files. Locate uses a database to improve speed and efficiency of searches. |
find | Search for files by parsing the file system. |
wget | Simple command to retrieve content from an HTTP server. |
curl | Similar to wget but includes more sophisticated options. |
Administrative Shell Commands
| Command | Description |
|---|
vi/vim | A file editor for use in a terminal. Very popular but nonintuitive to use. |
su | Substitute or switch user. |
sudo | Precedes a command that requires elevated privileges. |
useradd | Create a user account. |
usermod | Change the attributes of a user account. |
chmod | Determines who is allowed to make what changes to a particular file or folder. |
chown | Determines who owns a particular file or folder. |
mkfifo | Similar in concept to a standard | style pipe but implemented as an actual file. |