Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find all files in a directory that are not directories themselves

Tags:

bash

unix

ksh

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.

like image 665
Alex Avatar asked Aug 19 '09 15:08

Alex


People also ask

How do you list only files not directories in Linux?

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.

Which command is used to list out all the hidden files along with the other files in Unix?

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.


1 Answers

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 
like image 169
John Kugelman Avatar answered Oct 13 '22 13:10

John Kugelman