This document is the property of Al Nafi.
Any unauthorized redistribution or reproduction, including in printed form, is strictly
prohibited. This document can only be read electronically.
Lab 1: Shell Command Proficiency
Objective:
The objective of this lab is to help participants understand and utilize the shell
efficiently. By the end of this lab, participants should have mastered basic shell
commands, their syntax, and the use of input-output redirection to manage command
output. Additionally, participants should be able to combine commands to create simple
td
scripts or command sequences.
tl
Tasks:
Pv
1. Practice Basic Shell Commands and Syntax:
ng
1.1. Command List: ni
● ls: List files and directories.
ar
● cd: Change directory.
● pwd: Print current working directory.
Le
● cp: Copy files or directories.
● mv: Move or rename files or directories.
● rm: Remove files or directories.
IE
● mkdir: Create a new directory.
● rmdir: Remove an empty directory.
AF
● echo: Print text to the terminal.
1.2. Syntax Examples:
N
# Change to the home directory
AL
cd ~
# List files in the current directory
ls
# Create a new directory
mkdir my_directory
# Copy a file to another location
cp file.txt /path/to/destination/
# Remove a file
rm file.txt
2. Use Input-Output Redirection:
2.1. Output Redirection:
td
● >: Redirect standard output to a file, overwriting its content.
tl
● >>: Redirect standard output to a file, appending to its content.
Pv
# Redirect ls output to a file (overwrite if exists)
ls > output.txt
ng
# Redirect ls output to a file (append if exists)
ls >> output.txt
ni
ar
2.2. Pipeline (|):
● Use the output of one command as the input for another.
Le
# List files and directories, then filter for .txt files
IE
ls | grep ".txt"
AF
2.3. Error Redirection (2>):
● Redirect standard error to a file.
N
# Redirect error output to a file
AL
command_that_might_fail 2> error.log
3. Combine Commands to Create Simple Scripts:
3.1. Script Example:
#!/bin/bash
# A simple script to create a backup of a directory
# Define variables
source_dir="/path/to/source/"
backup_dir="/path/to/backup/"
# Create backup directory if not exists
td
mkdir -p $backup_dir
tl
# Copy files to backup directory
cp -r $source_dir* $backup_dir
Pv
# Display success message
echo "Backup completed successfully."
ng
Conclusion: ni
This lab has equipped participants with the necessary skills to navigate the shell and
ar
manipulate command output effectively. Understanding basic commands, their syntax,
and the use of input-output redirection are fundamental skills for system administration
Le
tasks. Participants should now feel confident in their ability to perform more complex
tasks in a Unix-like environment.
IE
AF
N
AL