Question

I want to check if the particular file is in a folder or its sub folder or not using Linux terminal.

Which should I use for this? I use find and grep command but it travels only one folder.

No correct solution

OTHER TIPS

In order to search from your current directory, use

find . -name filename

In order to search from root directory use

find / -name filename

If you don't know the file extension try

find . -name filename.*

Also note that find command only displays the files in the path which you have permission to view. If you don't have permission for a/b/c path then it will just display a message mentioning that path can't be searched

By default, find will traverse all subdirectories, for example:

mkdir level1
mkdir level1/level2
touch level1/level2/file

find . -name "file"

Output:

./level1/level2/file

If you want to search for by filename, use find:

find /path -name "filename"

example:

find . -name myfile.txt

If need to find all files containing a specific string, use grep:

grep -r "string" /path

example:

grep -r foobar . 
locate file name 

This is the simple command

I also prefer using a combination of tree and grep. Something like

tree | grep filename

Try

find . -name "filename" -type f

-type f restricts to only files in the current directory (replace . with your path).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top