I am using find to locate a file, but I want to only return the path to the parent directory of the file.
find /home/ -name 'myfile' -type f
That returns a list of the full path to all of the file matches, but I want to
one way of many:
find / -name 'myfile' -type f -exec dirname {} \;
The -printf action lets you extract lots of information about the file. '%h' is the directive to get the path part of the file name.
find /home/ -name 'myfile' -type f -printf '%h\n'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With