Ideally, I would be able to use a program like
find [file or directory name]
to report the paths with matching filenames/directories. Unfortunately this seems to only check the current directory, not the entire folder.
I've also tried locate and which, but none find the file, even though I know its on the computer somewhere.
To get rid of permission errors (and such), you can redirect stderr to nowhere
find / -name "something" 2>/dev/null
I hope this comment will help you to find out your local & server file path using terminal
find "$(cd ..; pwd)" -name "filename"
Or just you want to see your Current location then run
pwd "filename"
If need to find nested in some dirs:
find / -type f -wholename "*dirname/filename"
Or connected dirs:
find / -type d -wholename "*foo/bar"
Below example will help to find the specific folder in the current directory. This example only search current direct and it'll search sub directory available in the current directory
#!/bin/bash
result=$(ls -d operational)
echo $result
test="operational"
if [ "$result" == "$test" ]
then
echo "TRUE"
else
echo "FALSE"
fi
If it is a command file you are looking for, the fastest and most accurate way is with
which "commandname"
That will show you the actual file being used for the command, even if you have many files with the same name on the system.
The find
command will take long time, the fastest way to search for file is using locate
command, which looks for file names (and path) in a indexed database (updated by command updatedb
).
The result will appear immediately with a simple command:
locate {file-name-or-path}
If the command is not found, you need to install mlocate
package and run updatedb
command first to prepare the search database for the first time.
More detail here: https://medium.com/@thucnc/the-fastest-way-to-find-files-by-filename-mlocate-locate-commands-55bf40b297ab
Source: Stackoverflow.com