2025/02/16

Topic 715: Basic Unix Skills and Shell Scripting

This topic covers using the shell, managing files, processes, regular expressions, editing with vi, and writing simple shell scripts. Detailed explanations and examples are provided below.


715.1: Use the Shell and Work on the Command Line

Environment Variables:

Redirection and Pipes:

Manpages and Documentation:

History and Aliases (csh/tcsh):


715.2: Perform Basic File Management

Copying Files and Directories:

Moving Files:

Removing Files and Directories:

Identifying File Types:

Archiving/Backup:


715.3: Create, Monitor and Kill Processes

Monitoring Processes:

Killing Processes:

Changing Process Priority:

Background and Foreground Jobs:


715.4: Use Simple Regular Expressions

Using grep:

Using egrep:


715.5: Perform Basic File Editing Operations (vi)

Basic vi commands:

Line operations in vi:

Searching in vi:


715.6: Customize or Write Simple Scripts

Example script (Bourne shell):

#!/bin/sh
# A simple backup script

BACKUPDIR="/backup"
SRCDIR="/home/user"

tar cvf $BACKUPDIR/home.tar $SRCDIR
echo "Backup completed!"

To make a script executable, use:

chmod +x backup.sh
./backup.sh

In shell scripting, positional parameters allow access to arguments passed to the script:

#!/bin/sh
echo "Script name: $0"
echo "First argument: $1"