Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have a directory html. I would like to output the files of the directory, including the path, to a file.

You can do something like this with the command:

ls -R scripts/html > out.txt

But the results are like:

scripts/html
1.html
2.html
...

I would like the result as:

scripts/html/1.html
scripts/html/2.html
...
share|improve this question
2  
stackoverflow.com/questions/1767384/… - Several good solutions on that question / answer –  bodhi.zazen Jan 24 at 22:10

3 Answers 3

up vote 2 down vote accepted

Use find instead of ls. It'll give you a relative path based on what you pass it. I'm using tail to snip off the first line which would normally show the base directory.

find scripts/html | tail -n+2 > out.txt
share|improve this answer
    
Thank you. That is perfect. But is there any way to exclude the directory from the first line? I'll try something, but am a novice. I believe sed could be used. –  Kohjah Breese Jan 24 at 22:32
1  
@KohjahBreese I've edited to do that. And it turns out you don't need stdbuf for find (I wonder what I was thinking of). –  Oli Jan 25 at 8:48
    
A simpler solution is simply: find dir/* > file.txt –  Kohjah Breese Jan 28 at 16:08
1  
@KohjahBreese The only problem I can see from that is won't (it might) list hidden directories in the first layer (but it will in subsequent). –  Oli Jan 28 at 16:25

You should be able to use this to print files only:

find scripts/html '!' -type d

Anything that is not a directory will be printed.

share|improve this answer

in the directory you want to show the contents of:

for all (folders and files)

ls -d1 $PWD/**/*

for just folders

ls -d1 $PWD/**

for just files

ls -d1 $PWD/*.*
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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