File list grep or other scripts for top level folders or max depth

I’m trying to restore files incrementally, but I’m having a difficult time trying to remember some of the folder paths, etc. The file list option for a revision is returning too much information. I was wondering if anyone has any scripts or tricks for listing unique folders with a max depth. Something like

folders, maxDepth:4

toplevel
toplevel/level2a
toplevel/level2b
toplevel/level2c
toplevel/level2a/level3a
toplevel/level2a/level3b
toplevel/level2b/level3a
toplevel/level2a/level3b/level4a

Some sort of tree structure for file lists or options like this would be nice for the list functionality.

I’ve tried coming up with a good grep for this by listing stuff with a max line length, but even then I just get hundreds of lines for the trash folder or something and the results are too much to sift through.

Any advice is appreciated.

So far, the closest thing I’ve been able to come up with

cut -c 99- filelist.txt |grep --only-matching '.*/.*/' |grep -E '^.{,25}$' |sort --unique

cut only returns the end of the line wiht the path. Probably not that efficient and the folder depth is pretty arbitrary due to the second grep with the regex only returning lines less than a certain length, but the results are much more managable. If I could return matches only containing a certain number of slashes etc, that would be nice.

Edit: this actually ended up working fairly well. I’ll mark it as a solution for now. Hope this helps others. Feel free to suggest alternatives if you come across this.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.