Skip to content

Ls command

show each file on seperate line , filename only

ls -1a
note : -1 must be supported by libraries , such as GNU coreutils [is ok in LXM]

show only files , not the directories

ls -p | grep -v '/$'
or
find . -maxdepth 1 -type f

The “find” solutions above lose some of the capabilities of ls - for example: list only files, sorted in descending modification time.
The “ls -p | grep” answers do not elegantly deal with other elements of ls such as -R should they be desired
The following answer, while more verbose, in my opinion reflects the truest ls behaviour and most flexibility for selecting “files only”

ls -t . | while read line; do
  if [ -f $line ]; then
    echo $line
  fi 
done

Simply replace the ls switches as desired and the result will be returned with files only.
If links and other items are also required then minor rework would need to be done to the test for inclusion.
zie voor nog dieper gaande oplossingen : https://serverfault.com/questions/368370/how-do-i-exclude-directories-when-listing-files

show all subfolders of a location (recursevely)

in the exapmle current dir . (replace with valid pathname)
find . -type d -print

list all folders in this directory

`ls -l | grep ‘drwx’
ugly , but it works ( at least for root , and your data if normal user)

ls -ltr