2

Using ls -R / i get every file and directory listed that exists, but not in the desired format.

What do I need to write on the command line in order to get a list in such a format, that every line contains an absolute path.

  • 1
    Just look for find – unxnut Feb 14 '15 at 15:59
  • Please edit your question and show us exactly what format you want. Also clarify if this is for you to read or if it will be processed by a script. Finally, what do you want to do with directory names that contain newline characters? – terdon Feb 14 '15 at 15:59
  • I tried at first, but I had to delete it because I do not know how to put lines one under the other, the text format here is automatically changed. – Abdul Al Hazred Feb 14 '15 at 16:11
  • I don't understand the question. Are you trying to get the list of all files and dirs under / . Anyways i thought my answer might help someone who just need to find absolute path for the files and subdirectories under a dir. – bluefoggy Feb 14 '15 at 16:39
  • 1
    please watch Romeo Ninov's answer:"find /". If you type it into the command line you get for each line one absolute path for every directory and file on the filesystem. – Abdul Al Hazred Feb 14 '15 at 17:07
12

You can get the files with full path with this command:

find / -type f

or list files from the current directory down:

find $(pwd) -type f
  • When I run find $(pwd), I get list of folders and files with absolute path under current directory, I just want the paths of files and ignore the folder paths, is there a way to do it? – hadooper Jul 27 '17 at 19:12
  • nvm.. I found the answer, just need to add an option -type f to the above command. thanks – hadooper Jul 27 '17 at 19:15
  • 1
    @hadooper, in UNIX/Linux (almost) everything is file :) But yes, this can help, will add it to answer – Romeo Ninov Jul 27 '17 at 21:32
4

There are two commands you can use along with ls if you intend just for the files in a particular directory.

  1. realpath
  2. readlink

I can't show you realpath output as i don't have it in my system.

You can make readlink to do that for you.

ls | xargs -n 1 readlink -f

WARNING: you may not get the abs path for the soft links as that will be converted to the files which are the linked to.

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.