I have a file that contains the output of find called on a directory on another computer. I'd like to browse the file/directory structure with commands cd, ls, etc. as if it would be in my file system. How can I do this?

Example of my find output file


In my case, all paths are absolute. I have around 755,000 entries in the full file.

  • I have added an example of my find output file to the description. – maiermic Oct 3 '16 at 10:46
  • Excellent. (1) Is a2 an empty directory or a file? (More importantly, how should the file browser respond for this situation?) (2) Why does the directory name a1 end with / but the directory name a2b doesn't? – roaima Oct 3 '16 at 11:53
  • (1) Good question. I'm not sure if it is even possible to distinguish file and directory by the output of find. I can not tell if a2 is a directory or a file. (2) Another good question, but this time I know the answer. It depends on how you pass the path you'd like to search to find. If you call find /a0/a1 it doesn't end with /, but it does if you call find /a0/a1/. However, no subdirectory ends with /. – maiermic Oct 3 '16 at 12:14
  • I counted 755066 entries using wc -l find.output. – maiermic Oct 3 '16 at 13:47

I found a solution to create a dummy file structure of all file paths in my current directoy that I can browse afterwards:

cat find.output | sed -r 's/^\/(.*)$/"\.\/\1"/' | xargs mkdir
  • find.output is my file
  • I use sed to make absolute paths relative and quote them (in case they contain spaces)
  • xargs is used to create a directory for each path

However, I would be happy about a solution that does not touch my real file system.

  • 1
    Since you're already using GNUisms (-r): cut -c2- < find.output | xargs -rd '\n' mkdir -p -- (would also avoid problems with filenames containing double quote characters; note that the newline characters will always be a problem as the format of your found.output file doesn't allow for them). – Stéphane Chazelas Oct 3 '16 at 10:53
  • 2
    Do this on a tmpfs filesystem. – Gilles Oct 4 '16 at 23:34
  • @Gilles Thanks. If you or someone else writes an answer that describes how to use tmpfs in my use case, I will accept it as my favorite answer. – maiermic Oct 5 '16 at 11:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.