diff --git a/sh/tests/largest-dir/.abc b/sh/tests/largest-dir/.abc new file mode 100644 index 000000000..f765db107 --- /dev/null +++ b/sh/tests/largest-dir/.abc @@ -0,0 +1 @@ +ciao mamma guarda come mi diverto diff --git a/sh/tests/largest-dir/folder1/.hello b/sh/tests/largest-dir/folder1/.hello new file mode 100644 index 000000000..769428876 --- /dev/null +++ b/sh/tests/largest-dir/folder1/.hello @@ -0,0 +1 @@ +ciao mamma guarda qu diff --git a/sh/tests/largest-dir/folder1/ab b/sh/tests/largest-dir/folder1/ab new file mode 100644 index 000000000..190a18037 --- /dev/null +++ b/sh/tests/largest-dir/folder1/ab @@ -0,0 +1 @@ +123 diff --git a/sh/tests/largest-dir/folder1/ac b/sh/tests/largest-dir/folder1/ac new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/sh/tests/largest-dir/folder1/ac @@ -0,0 +1 @@ +1 diff --git a/sh/tests/largest-dir/folder1/az b/sh/tests/largest-dir/folder1/az new file mode 100644 index 000000000..48082f72f --- /dev/null +++ b/sh/tests/largest-dir/folder1/az @@ -0,0 +1 @@ +12 diff --git a/sh/tests/largest-dir/folder1/bz b/sh/tests/largest-dir/folder1/bz new file mode 100644 index 000000000..48082f72f --- /dev/null +++ b/sh/tests/largest-dir/folder1/bz @@ -0,0 +1 @@ +12 diff --git a/sh/tests/largest-dir/folder1/cz b/sh/tests/largest-dir/folder1/cz new file mode 100644 index 000000000..97b5955f7 --- /dev/null +++ b/sh/tests/largest-dir/folder1/cz @@ -0,0 +1 @@ +12345678 diff --git a/sh/tests/largest-dir/folder1/za! b/sh/tests/largest-dir/folder1/za! new file mode 100644 index 000000000..48082f72f --- /dev/null +++ b/sh/tests/largest-dir/folder1/za! @@ -0,0 +1 @@ +12 diff --git a/sh/tests/largest-dir/folder2/aa/.salut b/sh/tests/largest-dir/folder2/aa/.salut new file mode 100644 index 000000000..9f358a4ad --- /dev/null +++ b/sh/tests/largest-dir/folder2/aa/.salut @@ -0,0 +1 @@ +123456 diff --git a/sh/tests/largest-dir/folder2/aa/aa b/sh/tests/largest-dir/folder2/aa/aa new file mode 100644 index 000000000..48082f72f --- /dev/null +++ b/sh/tests/largest-dir/folder2/aa/aa @@ -0,0 +1 @@ +12 diff --git a/sh/tests/largest-dir/folder2/aa/az b/sh/tests/largest-dir/folder2/aa/az new file mode 100644 index 000000000..190a18037 --- /dev/null +++ b/sh/tests/largest-dir/folder2/aa/az @@ -0,0 +1 @@ +123 diff --git a/sh/tests/largest-dir/folder2/aa/ba/ab b/sh/tests/largest-dir/folder2/aa/ba/ab new file mode 100644 index 000000000..e69de29bb diff --git a/sh/tests/largest-dir/folder2/aa/ba/bz b/sh/tests/largest-dir/folder2/aa/ba/bz new file mode 100644 index 000000000..e69de29bb diff --git a/sh/tests/largest-dir/folder2/ab b/sh/tests/largest-dir/folder2/ab new file mode 100644 index 000000000..9f358a4ad --- /dev/null +++ b/sh/tests/largest-dir/folder2/ab @@ -0,0 +1 @@ +123456 diff --git a/sh/tests/largest-dir/folder2/ac b/sh/tests/largest-dir/folder2/ac new file mode 100644 index 000000000..e69de29bb diff --git a/sh/tests/largest-dir/folder2/alphabet b/sh/tests/largest-dir/folder2/alphabet new file mode 100644 index 000000000..e69de29bb diff --git a/sh/tests/largest-dir/folder2/az b/sh/tests/largest-dir/folder2/az new file mode 100644 index 000000000..e69de29bb diff --git a/sh/tests/largest-dir/folder2/ba/.ola b/sh/tests/largest-dir/folder2/ba/.ola new file mode 100644 index 000000000..a1e5c5096 --- /dev/null +++ b/sh/tests/largest-dir/folder2/ba/.ola @@ -0,0 +1 @@ +1234512312312312 diff --git a/sh/tests/largest-dir/folder2/ba/aa/.ciao b/sh/tests/largest-dir/folder2/ba/aa/.ciao new file mode 100644 index 000000000..9f358a4ad --- /dev/null +++ b/sh/tests/largest-dir/folder2/ba/aa/.ciao @@ -0,0 +1 @@ +123456 diff --git a/sh/tests/largest-dir/folder2/ba/aa/alphabetz! b/sh/tests/largest-dir/folder2/ba/aa/alphabetz! new file mode 100644 index 000000000..e69de29bb diff --git a/sh/tests/largest-dir/folder2/ba/aa/cz b/sh/tests/largest-dir/folder2/ba/aa/cz new file mode 100644 index 000000000..e69de29bb diff --git a/sh/tests/largest-dir/folder2/ba/aa/za! b/sh/tests/largest-dir/folder2/ba/aa/za! new file mode 100644 index 000000000..e69de29bb diff --git a/sh/tests/largest-dir/folder2/ba/ac b/sh/tests/largest-dir/folder2/ba/ac new file mode 100644 index 000000000..e69de29bb diff --git a/sh/tests/largest-dir/folder2/ba/alphabetz b/sh/tests/largest-dir/folder2/ba/alphabetz new file mode 100644 index 000000000..e69de29bb diff --git a/sh/tests/largest-dir/folder2/bz b/sh/tests/largest-dir/folder2/bz new file mode 100644 index 000000000..190a18037 --- /dev/null +++ b/sh/tests/largest-dir/folder2/bz @@ -0,0 +1 @@ +123 diff --git a/sh/tests/largest-dir/folder2/cz b/sh/tests/largest-dir/folder2/cz new file mode 100644 index 000000000..e69de29bb diff --git a/sh/tests/largest-dir/folder2/za! b/sh/tests/largest-dir/folder2/za! new file mode 100644 index 000000000..42b89b0af --- /dev/null +++ b/sh/tests/largest-dir/folder2/za! @@ -0,0 +1 @@ +12312312312 12 312 312 12 3 diff --git a/sh/tests/largest_test.sh b/sh/tests/largest_test.sh new file mode 100644 index 000000000..a4e47e5d1 --- /dev/null +++ b/sh/tests/largest_test.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash + +set -euo pipefail +IFS=' +' + +FILENAME="student/largest.sh" +script_dirS=$(cd -P "$(dirname "$BASH_SOURCE")" &>/dev/null && pwd) + +challenge () { + submitted=$(cd "$1" && bash "$script_dirS"/"$FILENAME") + expected=$(cd "$1" && bash "$script_dirS"/solutions/largest.sh) + + diff <(echo "$submitted") <(echo "$expected") +} + +if [ $(cat "$script_dirS"/"$FILENAME" | grep echo) ]; then + echo "echo is not allowed in this exercise!" + exit 1 +fi + +challenge largest-dir/folder1 +challenge largest-dir/folder2 +challenge largest-dir diff --git a/sh/tests/solutions/largest.sh b/sh/tests/solutions/largest.sh new file mode 100644 index 000000000..8ee804408 --- /dev/null +++ b/sh/tests/solutions/largest.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +find . -type f -exec ls -lha {} \; | sort -hrk5 | head -7 | awk '{printf("%5s | ", $5); print $NF}' diff --git a/subjects/devops/largest/README.md b/subjects/devops/largest/README.md new file mode 100644 index 000000000..e068b7504 --- /dev/null +++ b/subjects/devops/largest/README.md @@ -0,0 +1,46 @@ +## largest + +### Instructions + +Crate a script `largest.sh` that will look for, and display on the console, the seven biggest files in the current directory (including subdirectories) in a specific format. + +The script will also have to find and take into account hidden files. + +### Usage + +Here is an example of how to use the script: + +```console +$ tree -ha +[4.0K] . +├── [4.0K] d1 +│   ├── [4.0K] d1-1 +│   ├── [ 2] f1-1 +│   ├── [ 27] f1-2 +│   ├── [ 24] f1-3 +│   ├── [ 24] f1-4 +│   ├── [ 3] f2-1 +│   ├── [ 34] f2-2 +│   ├── [ 38] f2-3 +│   └── [ 87] .hf1-1 +├── [ 5] f1 +├── [ 18] f2 +└── [ 34] f3 + +2 directories, 11 files +$ bash largest.sh | cat -e + 87 | ./d1/.hf1-1$ + 5 | ./f1$ + 3 | ./d1/f2-1$ + 38 | ./d1/f2-3$ + 34 | ./d1/f2-2$ + 34 | ./f3$ + 2 | ./d1/f1-1$ +$ +``` + +> The output needs to be formatted as the example shown above + +### Hints + +- `awk` might be handy