Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get all files from a directory without details

Tags:

linux

ls

I discovered that

ls -AF /var/ |grep \/$

helps me to find all directories from a directories without more information. Now i need exactly the opposite - showing all files without any further information just the file name in each line

file1
file2
file3

and filtering the directories because those - i don't need

like image 547
yellowsir Avatar asked Oct 25 '12 08:10

yellowsir


4 Answers

Simplest way: its not L its digit - 1

$ ls -1
like image 173
Shaunak Sontakke Avatar answered Oct 17 '22 12:10

Shaunak Sontakke


For finding files matching a certain expression there exists find. Its man-page is quite good and includes also some interesting examples. For getting only the files of a directory you can use:

find /var -maxdepth 1 -type f -printf "%f\n"
like image 41
Lothar Avatar answered Oct 17 '22 10:10

Lothar


Just use the -v switch for grep to invert the match:

ls -AF /var/ |grep -v /$ 
like image 3
choroba Avatar answered Oct 17 '22 12:10

choroba


ls -1Ap /var/ | grep -v /

Similar to @choroba's answer, but this version will list clean file names on each line without appending additional classification indicators, if you don't want them.

-p flag appends / to directories

-1 flag is always handy to list one file per line

like image 3
frank Avatar answered Oct 17 '22 10:10

frank