0

I am looking for a command that lists all files in the current directory.

Requirements:

  1. Absolute paths
  2. One file per line
  3. No other information (like size, permissions...)
  4. Don't show folders

What I got so far is this:

ls -d1 $PWD/*

Which gives:

[User@User-arch Pictures]$ ls -d1 $PWD/*
/home/User/Pictures/folder1
/home/User/Pictures/folder2
/home/User/Pictures/file1.png
/home/User/Pictures/file2.png
/home/User/Pictures/file3.png
/home/User/Pictures/file4.png

or readlink -f $PWD/*, which gives the same output.

They satisfie all but the 4. requirements. How can I tweak it so it does not show folders? Or is there a simpler command?

3
find $PWD -maxdepth 1 -type f

Lists files in current working directory. -type f tells find list only regular files (no folders), -maxdepth 1 prevents content in subfolders showing up in output.

0

You could tell ls to include the trailing forward slash after directory names then pipe it to grep.

ls -pd1 $PWD/* | grep -v /$

Edit: Saw my flaw in original answer.

  • That doesnt show anything for me – Johannes Aug 2 '17 at 15:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.