'Make `find` returns only sub-relative path in Linux?
I am using find in Ubuntu to list all files in one directory into a text file. With the command below:
find ./ -name "*.txt"
I get results:
./a.txt
./dir/b.txt
But I want the results to be like:
a.txt
dir/b.txt
What should I do? Thanks!
Solution 1:[1]
Thanks to @Barmar, the below commad works:
find * -name "*.txt"
If you want sorted output:
find * -name "*.txt" | sort
If you want to save the output into txt file:
find * -name "*.txt" | sort > res.txt
Solution 2:[2]
Suggesting to use simple ls command. With ** glob pattern to recurse sub-directories.
shopt -s globstar
ls {,**}/*.txt
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | ToughMind |
| Solution 2 | Dudi Boy |
