1

I need a shell script that writes the tree structure (including all data in the folders) from a specific folder to a text/dat file.

So far I got this:

find . -type f|sed 's_\.\/__' > PATH/Input.dat

I dont want a "/" as the first char of the path.

This script works fine, but it returns ALL folder structures. I need something that returns only structures from a specific folder, like "Sales".

user2428207
  • 825
  • 4
  • 16
  • 29

1 Answers1

2

I need something that returns only structures from a specific folder, like "Sales".

Specify the desired folder name. Say:

find Sales -type f | sed 's_\.\/__'
     ^^^^^

Saying find . ... would search in . (i.e. the current directory and subdirectories).

If you need to search more folders, say Purchase, specify those too:

find Sales Purchase -type f | sed 's_\.\/__'
devnull
  • 118,548
  • 33
  • 236
  • 227
  • Probably that `sed` then becomes obsolete. – Alfe Oct 16 '13 at 12:12
  • @Alfe Yes, if you are specifying a path the result wouldn't have a leading `./`. I'd say it becomes _redundant_ rather than _obsolete_ :) – devnull Oct 16 '13 at 12:13
  • If I specify a path ≠ `.`, that is ;-) – Alfe Oct 16 '13 at 12:14
  • @Alfe `.` is default (even if you don't specify it). – devnull Oct 16 '13 at 12:15
  • Actually, paths like `Sales/some/weird/path./with./strange./names` would get ugly garbled by that `sed`, so it does not really get _redundant_ but _wrong_, so _obsolete_ fits better. – Alfe Oct 16 '13 at 12:16
  • Is it somehow possible to order the output in a some kind of order? – user2428207 Oct 16 '13 at 12:26
  • @user2428207 Could you elaborate _some kind of order_? – devnull Oct 16 '13 at 12:28
  • for example order by subfolder and then filename. Lets say I have three folders in my "find Sales" folder. A, B and C. Each folder has files 1, 2 and 3. Now I would like to have Folder A;1,2,3 Folder B;1,2,3 and so on. – user2428207 Oct 16 '13 at 12:30