From eb6e281da04a91367c04e78f5949341bc6c3f68e Mon Sep 17 00:00:00 2001 From: miguel Date: Tue, 20 Dec 2022 15:32:27 +0000 Subject: [PATCH] feat(file-details): add subject, test and solution for the exercise --- sh/tests/file-details_test.sh | 17 ++++++ sh/tests/solutions/file-details.sh | 1 + subjects/devops/file-details/README.md | 71 ++++++++++++++++++++++++++ 3 files changed, 89 insertions(+) create mode 100755 sh/tests/file-details_test.sh create mode 100755 sh/tests/solutions/file-details.sh create mode 100644 subjects/devops/file-details/README.md diff --git a/sh/tests/file-details_test.sh b/sh/tests/file-details_test.sh new file mode 100755 index 00000000..7d7cc3f5 --- /dev/null +++ b/sh/tests/file-details_test.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash + +# Unofficial Bash Strict Mode +set -euo pipefail +IFS=' +' + +script_dirS=$(cd -P "$(dirname "$BASH_SOURCE")" &>/dev/null && pwd) + +challenge() { + submitted=$(cd "$1" && bash "$script_dirS"/student/file-details.sh) + expected=$(cd "$1" && bash "$script_dirS"/solutions/file-details.sh) + + diff <(echo "$submitted") <(echo "$expected") +} + +challenge hard-perm diff --git a/sh/tests/solutions/file-details.sh b/sh/tests/solutions/file-details.sh new file mode 100755 index 00000000..3a6fe9cb --- /dev/null +++ b/sh/tests/solutions/file-details.sh @@ -0,0 +1 @@ +TZ=utc ls -l --time-style='+%F %R' | sed 1d | awk '{print $1, $6, $7, $8, $9, $10}' diff --git a/subjects/devops/file-details/README.md b/subjects/devops/file-details/README.md new file mode 100644 index 00000000..e5df236d --- /dev/null +++ b/subjects/devops/file-details/README.md @@ -0,0 +1,71 @@ +## files-details + +### Instructions + +Create a script `files-details.sh`, which will allow you to see the files inside the folder `hard-perms`, this way: + +Expected output: + +```console +$ ./files-details.sh +dr-------x 2 user user 4096 dez 13 17:50 0 +-r------w- 1 user user 0 dez 13 17:51 1 +-rw----r-- 1 user user 0 dez 13 17:51 2 +drwxrwxrwx 2 user user 4096 dez 13 17:51 3 +-r-x--x--- 1 user user 0 dez 13 17:51 4 +-r--rw---- 1 user user 0 dez 13 17:51 5 +-r--rw---- 1 user user 0 dez 13 17:51 6 +-r-x--x--- 1 user user 0 dez 13 17:51 7 +-rw----r-- 1 user user 0 dez 13 17:51 8 +-r------w- 1 user user 0 dez 13 17:51 9 +dr-------x 2 user user 4096 dez 13 17:50 A +``` + +### Hints + +- `ls -l --time-style=TIME_STYLE` + + - Time conversion specifiers you need to know: + + - `%R`, 24-hour hour and minute. Same as ‘%H:%M’. + + - Date conversion specifiers you need to know: + + - `%F`, full date in ISO 8601 format; like ‘%+4Y-%m-%d’ except that any flags or field width override the ‘+’ and (after subtracting 6) the ‘4’. This is a good choice for a date format, as it is standard and is easy to sort in the usual case where years are in the range 0000…9999. + +- You can use `sed` to remove the first line of the output. + +```console +$ ./files-details.sh # without using sed +total +-rw-rw-r-- 2022-12-20 03:10:18 README.md +$ ./files-details.sh # using sed +-rw-rw-r-- 2022-12-20 03:10:18 README.md +$ +``` + +- `awk`. + +You can specify specific column names to display or include in the awk output using the field numbers. For example: + +```console +$ ls -l | awk '{print $1, $2, $3, $4, $5, $6, $7, $8, $9, $10}' # print all the given fields +total 4 +-rw-rw-r-- 1 user user 1989 dez 20 15:19 README.md +$ ls -l | awk '{print $1, $2, $4, $5, $7, $8, $10}' # print all the given fields +total 4 +-rw-rw-r-- 1 user 2350 20 15:25 +$ +``` + +awk ‘{print $1}’ emp_records.txt +awk {print $1, $6, $7, $8, $9, $10}' + +> You have to use Man or Google to know more about commands flags, in order to solve this exercise! +> Google and Man will be your friends! + +### References + +- [Time conversion specifiers](https://www.gnu.org/software/coreutils/manual/html_node/Time-conversion-specifiers.html). +- [Date conversion specifiers](https://www.gnu.org/software/coreutils/manual/html_node/Date-conversion-specifiers.html). +- [awk](https://www.gnu.org/software/gawk/manual/html_node/Print-Examples.html).