Tuesday, May 21, 2024
2
rated 0 times [  2] [ 0]  / answers: 1 / hits: 3122  / 3 Years ago, fri, october 15, 2021, 11:30:09

If my terminal is currently in home/stuff/stuff2 and there are more folders and files under stuff2, how can I launch a command to get the file names of all the files and folders from this directory and onwards (Including all sub directories).



The operation needs to do the following:




  1. The file path must start at the location of the terminal command, so I don't want full files paths. Example, instead of the read out being home/stuff/stuff2/stuff3/cat.png I would prefer the read out to be stuff3/cat.png

  2. It must capture every file and folder and files within those folders.

  3. It needs to be piped (I think this is the term) to a text file.



Any ideas?


More From » command-line

 Answers
2

The command



find -printf "%P
" > file


will list all files and directories below the current directory and redirect the list to file. From the printf section of man find



  %P     File's name with the name of the command  line  argument
under which it was found removed.

[#22388] Saturday, October 16, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ainubt

Total Points: 496
Total Questions: 98
Total Answers: 126

Location: Sao Tome and Principe
Member since Wed, Dec 21, 2022
1 Year ago
;