Any command to list the contents of a directory into a txt or csv file?

Hi I searched but couldnt find it…

I dont know linux too well, and was looking for a command that will list the contents of a directory into a txt or csv file.

Any risk of it triggering a gdrive ban?

1 Like

Sussed it

rclone lsd drive:/dir/ >/file.txt

1 Like

If you are scripting stuff then you might like to checkout out the latest beta and lsf which can list into csv format if you want.

lsd only lists directories too, wouldn’t you want ls?

lsf can do everything ls lsd and lsl can. Here is its help

List the contents of the source path (directories and objects) to
standard output in a form which is easy to parse by scripts. By
default this will just be the names of the objects and directories,
one per line. The directories will have a / suffix.

Use the --format option to control what gets listed. By default this
is just the path, but you can use these parameters to control the

p - path
s - size
t - modification time
h - hash

So if you wanted the path, size and modification time, you would use
–format “pst”, or maybe --format “tsp” to put the path last.

If you specify “h” in the format you will get the MD5 hash by default,
use the “–hash” flag to change which hash you want. Note that this
can be returned as an empty string if it isn’t available on the object
(and for directories), “ERROR” if there was an error reading it from
the object and “UNSUPPORTED” if that object does not support that hash

For example to emulate the md5sum command you can use

rclone lsf -R --hash MD5 --format hp --separator "  " --files-only .

(Though “rclone md5sum .” is an easier way of typing this.)

By default the separator is “;” this can be changed with the
–separator flag. Note that separators aren’t escaped in the path so
putting it last is a good strategy.

Any of the filtering options can be applied to this commmand.

There are several related list commands

  • ls to list size and path of objects only
  • lsl to list modification time, size and path of objects only
  • lsd to list directories only
  • lsf to list objects and directories in easy to parse format
  • lsjson to list objects and directories in JSON format
    ls,lsl,lsd are designed to be human readable.
    lsf is designed to be human and machine readable.
    lsjson is designed to be machine readable.

Note that ls,lsl,lsd all recurse by default - use “–max-depth 1” to stop the recursion.

The other list commands lsf,lsjson do not recurse by default - use “-R” to make them recurse.

rclone lsf remote:path [flags]

-d, --dir-slash Append a slash to directory names. (default true)
–dirs-only Only list directories.
–files-only Only list files.
-F, --format string Output format - see help for details (default “p”)
–hash h Use this hash when h is used in the format MD5|SHA-1|DropboxHash (default “MD5”)
-h, --help help for lsf
-R, --recursive Recurse into the listing.
-s, --separator string Separator for the items in the format. (default “;”)