Sunday, October 3, 2010

Recursively List all directories and files

SkyHi @ Sunday, October 03, 2010
Question:
Suppose the directory structure on the file system is like this:

-dir1
-dir2
-file1
-file2
-dir3
-file3
-file4
-dir4
-file5
-dir5
-dir6
-dir7

The output from the script must be like:

Directories:

/dir1
/dir1/dir2
/dir1/dir2/dir3
/dir1/dir2/dir4
/dir1/dir5
/dir1/dir5/dir6
/dir1/dir5/dir7

Files:

/dir1
/dir1/dir2/file1
/dir1/dir2/file2
/dir1/dir2/dir3/file3
/dir1/dir2/dir3/file4
/dir1/dir2/dir4/file5
/dir1/dir5/dir6
/dir1/dir5/dir7


Hi could you guys tell me how to keep the output of "find . -type d" and "find . -type f" into another file.. thanks a lot guys


Solution
:

Bash/Shell Into a file

Directories:

find ./ -type d  > somefile.txt

Files:

find ./ -type f  > somefile.txt

In windows, to list only directories:
dir /ad /b /s

to list all files (and no directories)

dir /a-d /b /s 

redirect the output to a file by adding (without quotes)

> filename.txt' 


REFERENCES:
http://stackoverflow.com/questions/747465/recursively-list-all-directories-and-files