tags:

views:

90

answers:

7

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.

A: 

Try looking up "find", it should be able to do that.

redtuna
A: 
find . -type f
amrox
You are right, misread the question. John Kugelman posted a more complete answer.
amrox
+4  A: 

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
John Kugelman
+1  A: 

using find is simple as:

find . -maxdepth 1 -type f
dfa
A: 
find /some/directory -type f
Eric M
wrong, this is recursive (file2 must no be included)
dfa
A: 

$ find . -type f -print

Each file will be on its own line. You must be in the directory you want to search.

Rob Jones
wrong, this is recursive (file2 must no be included)
dfa
A: 

One more option

ls -ltr | grep ^d
Sachin Chourasiya