Sunday, April 28, 2024
2
rated 0 times [  2] [ 0]  / answers: 1 / hits: 2036  / 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
lowstonnequ questions
Wed, Oct 26, 22, 14:40, 2 Years ago
Tue, Feb 28, 23, 01:39, 1 Year ago
Wed, Dec 1, 21, 23:44, 2 Years ago
Thu, Apr 21, 22, 13:13, 2 Years ago
;