I am looking for a way to list all the files in a directory excluding directories themselves, and the files in those sub-directories.
So if I have:
./test.log ./test2.log ./directory ./directory/file2
I want a command that returns: ./test.log ./test2.log and nothing else.
Open the command-line shell and write the 'ls” command to list only directories. The output will show only the directories but not the files. To show the list of all files and folders in a Linux system, try the “ls” command along with the flag '-a” as shown below.
You need to use the find command to list all hidden files recursively on a Linux or Unix like systems. You can also use the ls command to list hidden files.
If you want test.log
, test2.log
, and file2
then:
find . -type f
If you do not want file2
then:
find . -maxdepth 1 -type f
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