2

I want the output as shown in below example.

root@aklinux139:~/.atom# du -sh */* | awk '{print $2}'
blob-store/BLOB
blob-store/INVKEYS
blob-store/MAP
compile-cache/less
compile-cache/root
compile-cache/style-manager
packages/README.md
storage/application.json
root@aklinux139:~/.atom# 

But ls does not give this output with any of its options/arguments. 'ls -R' gives path and then its content not the filename with its absolute path.

I need this very often while writing scripts, Can someone help me with this ? Thanks heap in advance.

Bertrand Martel
  • 42,756
  • 16
  • 135
  • 159
akjprajapati
  • 138
  • 2
  • 9
  • 1
    Possible duplicate of [How can I list files with their absolute path in linux?](http://stackoverflow.com/questions/246215/how-can-i-list-files-with-their-absolute-path-in-linux) – parsethis Feb 27 '17 at 18:43
  • see http://stackoverflow.com/questions/246215/how-can-i-list-files-with-their-absolute-path-in-linux – parsethis Feb 27 '17 at 18:44

2 Answers2

0

You can use find, an example for a depth of 2 :

find . -maxdepth 2 -mindepth 2 -printf '%P\n'

If you want to exclude dot files :

find . -maxdepth 2 -mindepth 2 -not -path '*/\.*' -printf '%P\n'

If you want to sort the result (as du -sh) :

find . -maxdepth 2 -mindepth 2 -not -path '*/\.*' -printf '%P\n' | sort
Bertrand Martel
  • 42,756
  • 16
  • 135
  • 159
0

try this -

find / -name "*" |head
/
/var
/var/games
/var/yp
/var/kerberos
/var/kerberos/krb5
/var/kerberos/krb5/user
/var/.updated
/var/nis
/var/account
VIPIN KUMAR
  • 3,019
  • 1
  • 23
  • 34