HDFS的命令行操作及可视化

时间:2021-12-17 17:39:43

想在这里把一些自己用过常用的操作练习,总结一下备忘。其实基本上是是linux命令的一部分,这部分命令和linux中的用法基本一致。在使用时可以用$bin/hadoop fs来全部列出查看或者学习。

 1. $bin/hadoop fs -ls path //列出目录下文件
 2. $bin/hadoop fs -mkdir path //创建目录
 3. $bin/hadoop fs -rm path //删除文件或者目录
 4. $bin/hadoop fs -rmdir path //删除目录
 5. $bin/hadoop fs -put localfile path //将文件从本地上传到HDFS的指定文件夹中
 6. $bin/hadoop fs -cat filename //查看指定的文件内容
 7. $bin/hadoop fs -get HDFSfile localfilename  //将HDFS文件下载到本地,命名为localfilename

在日常开发中我们可以使用eclipse的mapreduce插件,直接在eclipse中开发MR程序,并且直接运行。在这个环境中HDFS就是可视化的,如下:
HDFS的命令行操作及可视化
在这里可以右键实现

  • 创建新目录
  • 上传文件到DFS
  • 上传目录到DFS
  • 从DFS下载文件
  • 删除DFS的目录或者文件
  • 刷新以实现当前视窗和DFS的一致性

下面是hdfs现有的全部命令

Usage: hadoop fs [generic options]
    [-appendToFile <localsrc> ... <dst>]
    [-cat [-ignoreCrc] <src> ...]
    [-checksum <src> ...]
    [-chgrp [-R] GROUP PATH...]
    [-chmod [-R] <MODE[,MODE]... | OCTALMODE> PATH...]
    [-chown [-R] [OWNER][:[GROUP]] PATH...]
    [-copyFromLocal [-f] [-p] [-l] <localsrc> ... <dst>]
    [-copyToLocal [-p] [-ignoreCrc] [-crc] <src> ... <localdst>]
    [-count [-q] [-h] <path> ...]
    [-cp [-f] [-p | -p[topax]] <src> ... <dst>]
    [-createSnapshot <snapshotDir> [<snapshotName>]]
    [-deleteSnapshot <snapshotDir> <snapshotName>]
    [-df [-h] [<path> ...]]
    [-du [-s] [-h] <path> ...]
    [-expunge]
    [-find <path> ... <expression> ...]
    [-get [-p] [-ignoreCrc] [-crc] <src> ... <localdst>]
    [-getfacl [-R] <path>]
    [-getfattr [-R] {-n name | -d} [-e en] <path>]
    [-getmerge [-nl] <src> <localdst>]
    [-help [cmd ...]]
    [-ls [-d] [-h] [-R] [<path> ...]]
    [-mkdir [-p] <path> ...]
    [-moveFromLocal <localsrc> ... <dst>]
    [-moveToLocal <src> <localdst>]
    [-mv <src> ... <dst>]
    [-put [-f] [-p] [-l] <localsrc> ... <dst>]
    [-renameSnapshot <snapshotDir> <oldName> <newName>]
    [-rm [-f] [-r|-R] [-skipTrash] <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] <file>]
    [-test -[defsz] <path>]
    [-text [-ignoreCrc] <src> ...]
    [-touchz <path> ...]
    [-truncate [-w] <length> <path> ...]
    [-usage [cmd ...]]

Generic options supported are
-conf <configuration file>     specify an application configuration file
-D <property=value>            use value for given property
-fs <local|namenode:port>      specify a namenode
-jt <local|resourcemanager:port>    specify a ResourceManager
-files <comma separated list of files>    specify comma separated files to be copied to the map reduce cluster
-libjars <comma separated list of jars>    specify comma separated jar files to include in the classpath.
-archives <comma separated list of archives>    specify comma separated archives to be unarchived on the compute machines.