Upendra Singh
Assistant Professor
Department of AIML, School of Computer Science and Engineering
Manipal University Jaipur.
Illustration of shell functions such as wild cards, redirection, pipes,
sequencing, grouping, background processing, command substitution,
and subshells.
Outline
• Wildcards
• Redirection
• Pipes
• Sequencing
• Grouping
• Background Processing
• Command Substitution
• Subshells
15-01-2025 Dept. of AIML, SCSE, Manipal University Jaipur 3
Wildcards
• Wildcards are special characters used to match file names or patterns
in the shell.
15-01-2025 Dept. of AIML, SCSE, Manipal University Jaipur 4
Redirection
• Redirects input/output of commands to files or other commands.
15-01-2025 Dept. of AIML, SCSE, Manipal University Jaipur 5
Pipes
• Connects the output of one command to the input of another.
15-01-2025 Dept. of AIML, SCSE, Manipal University Jaipur 6
Sequencing
• Executes multiple commands sequentially, regardless of success or
failure.
15-01-2025 Dept. of AIML, SCSE, Manipal University Jaipur 7
Grouping
• Groups commands together so they run as a single unit.
15-01-2025 Dept. of AIML, SCSE, Manipal University Jaipur 8
Background Processing
• Runs a command in the background, allowing the shell to accept
other commands.
15-01-2025 Dept. of AIML, SCSE, Manipal University Jaipur 9
Command Substitution
• Captures the output of a command and uses it as input in another
context.
15-01-2025 Dept. of AIML, SCSE, Manipal University Jaipur 10
Subshells
• Creates a new shell to execute commands, isolating changes to
variables or the environment.
15-01-2025 Dept. of AIML, SCSE, Manipal University Jaipur 11
Exercises : Prepared Input Data
• Directory Structure: A directory project contains the
following files:
• [Link], [Link], [Link], [Link], [Link],
[Link], [Link]
• Commands for Prepared Data:
• Commands provided include ls, cat, grep, wc, echo, date, touch,
and mkdir.
15-01-2025 Dept. of AIML, SCSE, Manipal University Jaipur 12
Exercise Questions
• Wildcards
• Write a command to list all .txt files in the project directory.
• Using a wildcard, write a command to delete all .log files from the project
directory.
• Predict the output of the command: ls project/temp?.log
• Redirection
• Write a command to redirect the list of .csv and .png files into a file named
[Link].
• Append the message "Backup completed" to [Link].
• Predict the output of the following sequence:
• cat [Link] > error_report.txtgrep "Error" [Link] >> error_report.txt
15-01-2025 Dept. of AIML, SCSE, Manipal University Jaipur 13
Exercise Questions
• Pipes
• Combine commands to filter only lines containing "Error" from [Link] and count
them.
• Predict the output of the following command:
• ls project | grep ".txt" | wc –l
• Write a pipeline to list files in project and display only the first 3 entries.
• Sequencing
• Write a sequence of commands to:
• Create a directory output.
• Move all .log files into the output directory.
• List the files in output.
• Predict the outcome if one of the commands fails in this sequence:
• mkdir new_folder; mv project/*.csv new_folder; ls new_folder
15-01-2025 Dept. of AIML, SCSE, Manipal University Jaipur 14
Exercise Questions
• Grouping
• Write grouped commands to:
• Create a file [Link] in project.
• Write "This is a summary" into it.
• Redirect all output (including errors) to [Link].
• Predict the result of:
• { echo "Start"; ls project; echo "End"; } > [Link]
15-01-2025 Dept. of AIML, SCSE, Manipal University Jaipur 15
Exercise Questions
• Command Substitution
• Write a command to store the current date in a variable today and use it in a
sentence: "Today's date is <date>".
• Predict the output of the following:
• echo "Number of .txt files: $(ls project/*.txt | wc -l)"
15-01-2025 Dept. of AIML, SCSE, Manipal University Jaipur 16
15-01-2025 Dept. of AIML, SCSE, Manipal University Jaipur 17