Star Hype News.

Premium celebrity moments with standout appeal.

updates

print contents of a directory structure (filesystem) to CSV on the command line

By John Thompson

How can I catalog the contents of a filesystem to a CSV file? This is particularly useful for removable media.

I've found a couple links that point in this direction:

Thank you!

2 Answers

This creates a CSV file listing.csv with file name, time stamp and size for all files in /some/folder/ and its subfolders:

find /some/folder -printf '"%P";"%Tc";"%s";\n' > listing.csv

See the documentation for -printf in the manpage for find if you want to use other fields.

Note that it doesn't work for file names containing " characters.

1

If you need this to access the files on your external harddrive a better solution would be to create an index with extra options on updatedb

add this to your ~/.bashrc:

alias updatedb-external='sudo updatedb -l 0 -o ~/.externalharddisk.db -U /media/path/to/harddrive/'
alias locate-external='locate -d ~/.externalharddisk.db:'

then you can query that list with that alias:

locate-external some-file

update your list with

updatedb-external

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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