0

The command:

find . ! -name '*153902*.json' -exec ls -nls {} + | sort -k 10

returns:

12 -rw-rw-r-- 1 1000 1000  8359 May  6 15:11 ./Flights20180506-151026_KSEA_300.json
12 -rw-rw-r-- 1 1000 1000  8359 May  6 15:11 Flights20180506-151026_KSEA_300.json
44 -rw-rw-r-- 1 1000 1000 40999 May  6 15:39 Flights20180506-153902_KATL_0.json

This snippet of the response shows that the first two line-items appear to represent the same file: the difference is a './' prepended to the filename. What does this first line-item represent and why does the third line item not have a ./ ?

myname@Metropolitan:~/FlightAwareXML3/Thanksgiving18$ find . ! -name '*153902*.json' -exec ls -nlst {} \; | grep 153902_KATL_0
44 -rw-rw-r-- 1 1000 1000 40999 May  6 15:39 Flights20180506-153902_KATL_0.json

QUESTIONS

  1. What is the unique keywords to Google to learn more about ./ syntax?

  2. Is it possible (if yes how) to eliminate first-line-item response with the ./

6

Here's the process:

find . ! -name '*153902*.json'

will return:

.
./Flights20180506-151026_KSEA_300.json

then the exec executes:

ls -nls . ./Flights20180506-151026_KSEA_300.json

which give you the content of .:

12 -rw-rw-r-- 1 1000 1000  8359 May  6 15:11 Flights20180506-151026_KSEA_300.json
44 -rw-rw-r-- 1 1000 1000 40999 May  6 15:39 Flights20180506-153902_KATL_0.json

and ./Flights20180506-151026_KSEA_300.json itself.


The ./ you see in the output, is the result of concatenate the path . with the filename which matches your condition. The behavior is described in POSIX find document:

Each path operand shall be evaluated unaltered as it was provided, including all trailing characters; all pathnames for other files encountered in the hierarchy shall consist of the concatenation of the current path operand, a if the current path operand did not end in one, and the filename relative to the path operand

0

When looking for regular files with find, make sure you use -type f:

find . -type f ! -name '*153902*.json'

This way, you avoid matching directory names, in particular . in this case.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.