I believe you want
find -mindepth 2 -maxdepth 2 -name "*.txt"
Question
What I want to do is searching for all files that end with .txt in the subdirectories, for example, I am in directory called user, which holds only the directories Test1 and Test2. Test1 contains t1.txt and another subdirectory Test3. Test2 contains t2.txt. Test3 contains t3.txt
I try to use find and egrep
find */ -name "*.txt" | egrep "*/[^/]*(.txt)$"
but it gives me
Test1/Test3/t3.txt
Test1/t1.txt
Test2/t2.txt
I want to print something like
Test1/t1.txt
Test2/t2.txt
Since I just want files end with .txt in subdirectories (not subdirectories of subdirectories) What am I supposed to do in order to get the result I want? Thanks in advance
Solution 2
I believe you want
find -mindepth 2 -maxdepth 2 -name "*.txt"
OTHER TIPS
from man find
:
-maxdepth levels
Descend at most levels (a non-negative integer) levels of direc-
tories below the command line arguments. '-maxdepth 0' means
only apply the tests and actions to the command line arguments.
You can use awk
or basename
or dirname
awk -F/ '{print $(NF-1)}'