Thursday, May 2, 2024
2
rated 0 times [  2] [ 0]  / answers: 1 / hits: 2041  / 3 Years ago, tue, september 14, 2021, 11:48:41

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
...

More From » command-line

 Answers
4

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

[#27295] Tuesday, September 14, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
lowstonnequ

Total Points: 279
Total Questions: 125
Total Answers: 123

Location: Finland
Member since Sun, Dec 5, 2021
2 Years ago
;