Provide better alternatives for dealing with find/ls differences

Vladimir Panteleev
2020-01-29 12:57:48 +00:00
parent 95c531f6fe
commit 97a1505c7a

@@ -56,9 +56,9 @@ $ find .snapshot -maxdepth 1
.snapshot/rnapdev1-svm_4_05am_6every4hours.2019-04-02_1205 .snapshot/rnapdev1-svm_4_05am_6every4hours.2019-04-02_1205
.snapshot/snapmirror.1501b4aa-3f82-11e8-9c31-00a098cef13d_2147868328.2019-04-01_190000 .snapshot/snapmirror.1501b4aa-3f82-11e8-9c31-00a098cef13d_2147868328.2019-04-01_190000
``` ```
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`. 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 always using a negative name option for the searched directory: 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:
``` ```
$ find .snapshot -maxdepth 1 ! -name .snapshot $ 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_0005