Search⌘ K

Exercise: The [[ Operator and Directories

Explore how to create a Bash script that compares the contents of two directories by identifying files present in one but missing in the other. Understand the use of find and test commands, and how to apply conditional logic for file comparison to automate directory checks.

We'll cover the following...

Exercise

Write a script to compare two directories named dir1 and dir2. The script should print all files from one directory that are absent in the other one.

# Write the code here.
Operator [[ exercise

Solution

Let’s compare the contents of the two directories. The result of the comparison is a list of files that differ.

First, we have to go through all the files in each directory. The find utility does this task. Here is a command ...