Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions exercises/shell/solutions/directories_comparison.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
## Directories Comparison

### Objectives

1. You are given two directories as arguments and the output should be any difference between the two directories

### Solution

Suppose the name of the bash script is ```dirdiff.sh```

```
#!/bin/bash

if test $# -ne 2
then
echo -e "USAGE: ./dirdiff.sh directory1 directory2"
exit 1
fi

# check for the checksums.
# If both the checksums same, then both directories are same
if test `ls -1 $1 | sort | md5sum | awk -F " " '{print $1}'` == `ls -1 $2 | sort | md5sum | awk -F " " '{print $1}'`
then
echo -e "No difference between the 2 directories"
exit 0
fi

diff -q $1 $2

```