HDFS 的Shell命令

hadoop fs 等同于 hdfs dfs

1、列出所有受支持的命令

hadoop fs

[root@hadoop-node1 hadoop-3.3.2]# hadoop fs
Usage: hadoop fs [generic options]
        [-appendToFile <localsrc> ... <dst>]
        [-cat [-ignoreCrc] <src> ...]
        [-checksum [-v] <src> ...]
        [-chgrp [-R] GROUP PATH...]
        [-chmod [-R] <MODE[,MODE]... | OCTALMODE> PATH...]
        [-chown [-R] [OWNER][:[GROUP]] PATH...]
        [-concat <target path> <src path> <src path> ...]
        [-copyFromLocal [-f] [-p] [-l] [-d] [-t <thread count>] [-q <thread pool queue size>] <localsrc> ... <dst>]
        [-copyToLocal [-f] [-p] [-crc] [-ignoreCrc] [-t <thread count>] [-q <thread pool queue size>] <src> ... <localdst>]
        [-count [-q] [-h] [-v] [-t [<storage type>]] [-u] [-x] [-e] [-s] <path> ...]
        [-cp [-f] [-p | -p[topax]] [-d] [-t <thread count>] [-q <thread pool queue size>] <src> ... <dst>]
        [-createSnapshot <snapshotDir> [<snapshotName>]]
        [-deleteSnapshot <snapshotDir> <snapshotName>]
        [-df [-h] [<path> ...]]
        [-du [-s] [-h] [-v] [-x] <path> ...]
        [-expunge [-immediate] [-fs <path>]]
        [-find <path> ... <expression> ...]
        [-get [-f] [-p] [-crc] [-ignoreCrc] [-t <thread count>] [-q <thread pool queue size>] <src> ... <localdst>]
        [-getfacl [-R] <path>]
        [-getfattr [-R] {-n name | -d} [-e en] <path>]
        [-getmerge [-nl] [-skip-empty-file] <src> <localdst>]
        [-head <file>]
        [-help [cmd ...]]
        [-ls [-C] [-d] [-h] [-q] [-R] [-t] [-S] [-r] [-u] [-e] [<path> ...]]
        [-mkdir [-p] <path> ...]
        [-moveFromLocal [-f] [-p] [-l] [-d] <localsrc> ... <dst>]
        [-moveToLocal <src> <localdst>]
        [-mv <src> ... <dst>]
        [-put [-f] [-p] [-l] [-d] [-t <thread count>] [-q <thread pool queue size>] <localsrc> ... <dst>]
        [-renameSnapshot <snapshotDir> <oldName> <newName>]
        [-rm [-f] [-r|-R] [-skipTrash] [-safely] <src> ...]
        [-rmdir [--ignore-fail-on-non-empty] <dir> ...]
        [-setfacl [-R] [{-b|-k} {-m|-x <acl_spec>} <path>]|[--set <acl_spec> <path>]]
        [-setfattr {-n name [-v value] | -x name} <path>]
        [-setrep [-R] [-w] <rep> <path> ...]
        [-stat [format] <path> ...]
        [-tail [-f] [-s <sleep interval>] <file>]
        [-test -[defswrz] <path>]
        [-text [-ignoreCrc] <src> ...]
        [-touch [-a] [-m] [-t TIMESTAMP (yyyyMMdd:HHmmss) ] [-c] <path> ...]
        [-touchz <path> ...]
        [-truncate [-w] <length> <path> ...]
        [-usage [cmd ...]]

Generic options supported are:
-conf <configuration file>        specify an application configuration file
-D <property=value>               define a value for a given property
-fs <file:///|hdfs://namenode:port> specify default filesystem URL to use, overrides 'fs.defaultFS' property from configurations.
-jt <local|resourcemanager:port>  specify a ResourceManager
-files <file1,...>                specify a comma-separated list of files to be copied to the map reduce cluster
-libjars <jar1,...>               specify a comma-separated list of jar files to be included in the classpath
-archives <archive1,...>          specify a comma-separated list of archives to be unarchived on the compute machines

The general command line syntax is:
command [genericOptions] [commandOptions]

还可以通过 hadoop fs -help 列出所有命令及其使用指南,内容太多了,我这里就不贴出来了。

2、查看某一个命令的具体用法

hadoop fs -help <具体命令>

[root@hadoop-node1 hadoop-3.3.2]# hadoop fs -help ls
-ls [-C] [-d] [-h] [-q] [-R] [-t] [-S] [-r] [-u] [-e] [<path> ...] :
  List the contents that match the specified file pattern. If path is not
  specified, the contents of /user/<currentUser> will be listed. For a directory a
  list of its direct children is returned (unless -d option is specified).

  Directory entries are of the form:
        permissions - userId groupId sizeOfDirectory(in bytes)
  modificationDate(yyyy-MM-dd HH:mm) directoryName

  and file entries are of the form:
        permissions numberOfReplicas userId groupId sizeOfFile(in bytes)
  modificationDate(yyyy-MM-dd HH:mm) fileName

    -C  Display the paths of files and directories only.
    -d  Directories are listed as plain files.
    -h  Formats the sizes of files in a human-readable fashion
        rather than a number of bytes.
    -q  Print ? instead of non-printable characters.
    -R  Recursively list the contents of directories.
    -t  Sort files by modification time (most recent first).
    -S  Sort files by size.
    -r  Reverse the order of the sort.
    -u  Use time of last access instead of modification for
        display and sorting.
    -e  Display the erasure coding policy of files and directories.

示例:列出根目录下的文件的路径

[root@hadoop-node1 hadoop-3.3.2]# hadoop fs -ls -C /
/input
/tmp
/wordcount-out1

3、示例

选取了部分命令来进行示例

动作命令
创建一个名为/foodir的目录hadoop fs -mkdir /foodir
删除一个名为/foodir的目录hadoop fs -rm -R /foodir
从本地复制文件到/foodir目录hadoop fs -put test.txt /foodir
hadoop fs -copyFromLocal test.txt /foodir
下载文件到本地hadoop fs -get /foodir/test.txt ./localdir
hadoop fs -copyToLocal /foodir/test.txt ./localdir
查看名为/foodir/test.txt的文件的内容hadoop fs -cat /foodir/test.txt
设置某个文件的副本数量hadoop fs -setrep 5 /foodir/test.txt
### 回答1: HDFS ShellHadoop分布式文件系统(HDFS)的命令行接口。以下是一些HDFS Shell命令的例子: 1. 查看HDFS文件系统的根目录: ``` hadoop fs -ls / ``` 2. 在HDFS文件系统中创建一个目录: ``` hadoop fs -mkdir /mydirectory ``` 3. 将本地文件上传到HDFS文件系统中的目录中: ``` hadoop fs -put /local/path/to/file /hdfs/path/to/directory ``` 4. 从HDFS文件系统中下载文件到本地: ``` hadoop fs -get /hdfs/path/to/file /local/path/to/file ``` 5. 删除HDFS文件系统中的文件或目录: ``` hadoop fs -rm /hdfs/path/to/file hadoop fs -rm -r /hdfs/path/to/directory ``` 6. 在HDFS文件系统中复制文件或目录: ``` hadoop fs -cp /hdfs/path/to/source /hdfs/path/to/destination ``` 7. 查看HDFS文件系统中文件或目录的内容: ``` hadoop fs -cat /hdfs/path/to/file hadoop fs -tail /hdfs/path/to/file ``` 以上只是一些常用的HDFS Shell命令,还有许多其他命令可以使用。 ### 回答2: HDFS Shell命令是在Hadoop分布式文件系统(HDFS)中使用的命令行界面工具。它提供了一种方便直接访问和操作HDFS的方法,可以在终端或命令行中执行。 HDFS Shell命令通常以"hadoop fs"或"hdfs dfs"作为前缀,后跟具体的命令和参数。它们可以用于创建、复制、删除、移动和查看文件和目录等操作。 以下是一些常用的HDFS Shell命令及其功能: - "ls":列出指定路径下的所有文件和目录。 - "mkdir":创建一个新的目录。 - "copyFromLocal":从本地文件系统复制文件到HDFS。 - "copyToLocal":将HDFS上的文件复制到本地文件系统。 - "mv":移动或重命名文件或目录。 - "rm":删除指定的文件或目录。 - "cat":显示文件的内容。 - "put":将本地文件复制到指定路径下。 - "get":将指定路径下的文件复制到本地文件系统。 - "chmod":更改文件或目录的权限。 - "chown":更改文件或目录的所有者。 - "chgrp":更改文件或目录的组。 - "du":显示指定路径下的文件和目录的大小。 HDFS Shell命令Hadoop生态系统中重要的一部分,可以方便地进行文件系统的操作。它也可以与其他Hadoop工具和组件集成,如MapReduce、Hive和Spark等,来进行更复杂的数据处理和分析工作。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值