Currently, I have a function to find the filename, size and type; however, it includes the path as well, which I don't really need.

find . -type f -exec stat --format="%n %s %F"

which returns

directory/file size file type

Is there any way I could get it to show only the name of the file without the path using find, or do I have to use something else?


If you’re using GNU find (which I’m guessing is the case, given the tag), you can use its -printf action:

find . -type f -printf "%p %s %y\n"

(%y gives the same information as stat’s %F, as a single letter).

Alternatively, also assuming GNU find, use -execdir so that the executed command happens in the containing directory:

find . -type f -execdir stat --format="%n %s %F" {} +
  • the alternative sort of gives me what im looking for. however it returns the filenames as ./filename instead of just the filename, do you know if there is anyway if i could change this?
    – Jason Kyle
    Oct 31 '18 at 14:46

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.