No. The paths you get from your command are not relative.
The command does not explicitly specify an action for find
, so implicit -print
is used. -print
prints pathnames. Pathnames are created this way:
[…] 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 <slash> if the current path operand did not end in one, and the filename relative to the path operand. […]
This means if you specify /srv/SAMPLE001/../SAMPLE002
as the only path operand (stating point) then you can only get lines from -print
that start with this exact string.
Now check the definition of the relative pathname:
Relative Pathname
A pathname not beginning with a <slash> character.
Anything you can get from your command must start with /
(a <slash> character) because the path operand you used starts with /
. Then by definitions these pathnames are not relative. The only way to get relative pathnames from find … -print
is to provide a relative path operand (starting point).
In your case it can be like this:
cd /srv/SAMPLE001 && find ../SAMPLE002 -type f -name "*.tar"
(&&
in case cd
fails). Now every pathname must start with ../SAMPLE002
. The paths to the .tar
files you're after will start with ../SAMPLE002/
. By definition they will be relative.
The definition is very terse. To know where the relativeness comes from, one needs to know how *nix resolves paths. If you know this then you will agree that
/srv/SAMPLE001/../SAMPLE002/foo.rar
will point to the same foo.rar
, no matter what the current working directory is. But
../SAMPLE002/foo.rar
will depend (rely) on the current working directory. The latter path may or may not point to the right foo.rar
, depending on the current working directory. This is the point of being relative. If the current working directory is /srv/SAMPLE001
then the path will point to the right file.
Note if /srv/SAMPLE001/
didn't exist or if /srv/SAMPLE001/..
didn't exist (e.g. SAMPLE001
is a regular file), then /srv/SAMPLE001/../SAMPLE002/foo.rar
could not be resolved. This is the only dependence from /srv/SAMPLE001
in this case. The dependence does not make /srv/SAMPLE001/../SAMPLE002/foo.rar
a relative path though.
Your original command does not write to /opt/SAMPLE002/toBeCompressed.txt
at all. Use a proper operator to redirect the output from find
. E.g.:
cd /srv/SAMPLE001 && find ../SAMPLE002 -type f -name "*.tar" >/opt/SAMPLE002/toBeCompressed.txt