Linux - find files by file name and directory name
Hi,
I have a task from school - to search for files on the Linux system, but it is to be searched at the same time both by the file name and by the name of the directory in the given location.
E.g. find in the directory "/home/user" a file containing the word "top" in the name, this file should then be located in the directory named "dir2". Please advise how to do it?
Thanks
Hello,
You can search for files by file name and by directory name on Linux in your case as follows:
Alternative:
I have a task from school - to search for files on the Linux system, but it is to be searched at the same time both by the file name and by the name of the directory in the given location.
E.g. find in the directory "/home/user" a file containing the word "top" in the name, this file should then be located in the directory named "dir2". Please advise how to do it?
Thanks
REPLY
Hello,
You can search for files by file name and by directory name on Linux in your case as follows:
find /home/user -type f -path '*dir2*/*' -name '*top*.*'
Alternative:
find /home/user -type f -path '*dir2*/*top*.*'