diff --git a/SC2012.md b/SC2012.md index 224b7fa..78f6840 100644 --- a/SC2012.md +++ b/SC2012.md @@ -27,7 +27,7 @@ numgz=${#gz_files[@]} # Sometimes, you just need a count Here's an example: -```sh +```console $ ls -l total 0 -rw-r----- 1 me me 0 Feb 5 20:11 foo?bar @@ -45,7 +45,7 @@ It shows three seemingly identical filenames, and did you spot the time format c `ls` can usually be replaced by `find` if it's just the filenames, or a count of them, that you're after. Note that if you are using `ls` to get at the contents of a directory, a straight substitution of `find` may not yield the same results as `ls`. Here is an example: -``` +```console $ ls -c1 .snapshot rnapdev1-svm_4_05am_6every4hours.2019-04-01_1605 rnapdev1-svm_4_05am_6every4hours.2019-04-01_2005 @@ -56,7 +56,7 @@ rnapdev1-svm_4_05am_6every4hours.2019-04-02_1205 snapmirror.1501b4aa-3f82-11e8-9c31-00a098cef13d_2147868328.2019-04-01_190000 ``` versus -``` +```console $ find .snapshot -maxdepth 1 .snapshot .snapshot/rnapdev1-svm_4_05am_6every4hours.2019-04-02_0005 @@ -70,7 +70,7 @@ $ find .snapshot -maxdepth 1 You can see two differences here. The first is that the `find` output has the full paths to the found files, relative to the current working directory from which `find` was run whereas `ls` only has the filenames. You may have to adjust your code to not add the directory to the filenames as you process them when moving from `ls` to `find`, or (with GNU find) use `-printf '%P\n'` to print just the filename. The second difference in the two outputs is that the `find` command includes the searched directory as an entry. This can be eliminated by also using `-mindepth 1` to skip printing the root path, or using a negative name option for the searched directory: -``` +```console $ find .snapshot -maxdepth 1 ! -name .snapshot .snapshot/rnapdev1-svm_4_05am_6every4hours.2019-04-02_0005 .snapshot/rnapdev1-svm_4_05am_6every4hours.2019-04-02_0405 @@ -83,7 +83,7 @@ $ find .snapshot -maxdepth 1 ! -name .snapshot **Note:** If the directory argument to `find` is a fully expressed path (`/home/somedir/.snapshot`), then you should use `basename` on the `-name` filter: -``` +```console $ theDir="$HOME/.snapshot" $ find "$theDir" -maxdepth 1 ! -name "$(basename $theDir)" /home/matt/.snapshot/rnapdev1-svm_4_05am_6every4hours.2019-04-02_0005