Using bash
, how can I find a file with a specific name somewhere up the directory tree from the pwd
?
To be more clear. I want to find a file that sits in my working directory's root, but I don't know where the root is, and my pwd
might be anywhere below the root.
To search for files in File Explorer, open File Explorer and use the search box to the right of the address bar. Tap or click to open File Explorer. Search looks in all folders and subfolders within the library or folder you're viewing. When you tap or click inside the search box, the Search Tools tab appears.
You need to utilize the “-L” option and the path and “-name” option in your command. The “*” in the name specification is used for searching “all” the bash files with “.
Checking If a Directory Exists In a Bash Shell Script-h "/path/to/dir" ] && echo "Directory /path/to/dir exists." || echo "Error: Directory /path/to/dir exists but point to $(readlink -f /path/to/dir)." The cmd2 is executed if, and only if, cmd1 returns a non-zero exit status.
Find file.txt
up to root
x=`pwd`
while [ "$x" != "/" ] ; do
x=`dirname "$x"`
find "$x" -maxdepth 1 -name file.txt
done
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With