github.com/ncw/rclone@v1.48.1-0.20190724201158-a35aa1360e3e/cmd/lsd/lsd.go (about)

     1  package lsd
     2  
     3  import (
     4  	"context"
     5  	"os"
     6  
     7  	"github.com/ncw/rclone/cmd"
     8  	"github.com/ncw/rclone/cmd/ls/lshelp"
     9  	"github.com/ncw/rclone/fs"
    10  	"github.com/ncw/rclone/fs/operations"
    11  	"github.com/spf13/cobra"
    12  )
    13  
    14  var (
    15  	recurse bool
    16  )
    17  
    18  func init() {
    19  	cmd.Root.AddCommand(commandDefintion)
    20  	commandDefintion.Flags().BoolVarP(&recurse, "recursive", "R", false, "Recurse into the listing.")
    21  }
    22  
    23  var commandDefintion = &cobra.Command{
    24  	Use:   "lsd remote:path",
    25  	Short: `List all directories/containers/buckets in the path.`,
    26  	Long: `
    27  Lists the directories in the source path to standard output. Does not
    28  recurse by default.  Use the -R flag to recurse.
    29  
    30  This command lists the total size of the directory (if known, -1 if
    31  not), the modification time (if known, the current time if not), the
    32  number of objects in the directory (if known, -1 if not) and the name
    33  of the directory, Eg
    34  
    35      $ rclone lsd swift:
    36            494000 2018-04-26 08:43:20     10000 10000files
    37                65 2018-04-26 08:43:20         1 1File
    38  
    39  Or
    40  
    41      $ rclone lsd drive:test
    42                -1 2016-10-17 17:41:53        -1 1000files
    43                -1 2017-01-03 14:40:54        -1 2500files
    44                -1 2017-07-08 14:39:28        -1 4000files
    45  
    46  If you just want the directory names use "rclone lsf --dirs-only".
    47  
    48  ` + lshelp.Help,
    49  	Run: func(command *cobra.Command, args []string) {
    50  		cmd.CheckArgs(1, 1, command, args)
    51  		if recurse {
    52  			fs.Config.MaxDepth = 0
    53  		}
    54  		fsrc := cmd.NewFsSrc(args)
    55  		cmd.Run(false, false, command, func() error {
    56  			return operations.ListDir(context.Background(), fsrc, os.Stdout)
    57  		})
    58  	},
    59  }