get all files from a directory without details

13,161

Solution 1

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"

Solution 2

Simplest way: its not L its digit - 1

$ ls -1

Solution 3

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

ls -AF /var/ |grep -v /$ 

Solution 4

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

Share:
13,161
yellowsir
Author by

yellowsir

Updated on June 14, 2022

Comments

  • yellowsir
    yellowsir about 2 years

    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