unixfind-util

bash find command with path as requirement


I want to get file names of files in /bin that contain letter 'm' using find command not beeing in /bin. When /bin is my working directory it works fine but when I add /bin as requirement in path it returns nothing independently of current directory.

Works:

find -type f -name "*m*" -exec basename {} \;

Doesn't:

find -type f -name "*m*" -path "/bin/*" -exec basename {} \;

Solution

  • This will work.

    find /bin/* -type f -name "*m*" -exec basename {} \;
    

    It is equivalent to going to /bin folder and executing

    find -type f -name "*m*" -exec basename {} \;