Search code examples
linuxgreppipedepth

How do I retrieve all files in linux for given directory level. I want to absolute path aswell as the filename


I'm trying to retrieve all files for a given directory level. The files retrieved should also show absolute path.

git ls-files | cut -f1 | uniq | grep '.xml'

I expect the results to be a list of files in the directory level/depth 1.


Solution

  • Using find: using -maxdepth flag set to 1, -type f to list only files, -iname to list file of matching type. -exec to perform some action on the matched files. readlink -f to print the full path of the files.

    find . -maxdepth 1 -type f -iname "*.xml" -exec readlink -f {} \;