调用文件系统(FS)Shell命令应使用 $HADOOP_HOME/bin/hadoop fs 的形式。

所有的FS Shell命令使用URI路径作为参数。

URI格式是scheme://authority/path。

对于HDFS,HDFS的scheme是hdfs,如hdfs://localhost:9000/   , 对于本地,本地的scheme是file,如file://

其中,scheme和authority参数都是可选的,如果未加指定,就会使用配置中指定的默认scheme。

例如,/parent/child可以表示成hdfs://namenode:namenodePort/parent/child,或/parent/child(假设配置文件是namenode:namenodePort)

大多数FS Shell命令的行为和对应的Unix Shell命令类似。

进一步,可以参考  http://www.cnblogs.com/zlslch/p/5107847.html

bin/hdfs dfs命令

appendToFile

Usage: hdfs dfs -appendToFile <localsrc> ... <dst>

追加一个或者多个文件到hdfs制定文件中.也可以从命令行读取输入.

  • hdfs dfs -appendToFile localfile /user/hadoop/hadoopfile
  • hdfs dfs -appendToFile localfile1 localfile2 /user/hadoop/hadoopfile
  • hdfs dfs -appendToFile localfile hdfs://nn.example.com/hadoop/hadoopfile
  • hdfs dfs -appendToFile - hdfs://nn.example.com/hadoop/hadoopfile Reads the input from stdin.

Exit Code:

Returns 0 on success and 1 on error.

cat

Usage: hdfs dfs -cat URI [URI ...]

查看内容.

Example:

  • hdfs dfs -cat hdfs://nn1.example.com/file1 hdfs://nn2.example.com/file2
  • hdfs dfs -cat file:///file3 /user/hadoop/file4

Exit Code:

Returns 0 on success and -1 on error.

Chgrp【change group】

Usage: hdfs dfs -chgrp [-R] GROUP URI [URI ...]

修改所属组.

Options

  • The -R option will make the change recursively through the directory structure.

chmod

Usage: hdfs dfs -chmod [-R] <MODE[,MODE]... | OCTALMODE> URI [URI ...]

修改权限.

Options

  • The -R option will make the change recursively through the directory structure.

chown

Usage: hdfs dfs -chown [-R] [OWNER][:[GROUP]] URI [URI ]

修改所有者.

Options

  • The -R option will make the change recursively through the directory structure.

copyFromLocal

Usage: hdfs dfs -copyFromLocal <localsrc> URI

Similar to put command, except that the source is restricted to a local file reference.

Options:

  • The -f option will overwrite the destination if it already exists.

copyToLocal

Usage: hdfs dfs -copyToLocal [-ignorecrc] [-crc] URI <localdst>

Similar to get command, except that the destination is restricted to a local file reference.

count

Usage: hdfs dfs -count [-q] [-h] <paths>

列出文件夹数量、文件数量、内容大小. The output columns with -count are: DIR_COUNT, FILE_COUNT, CONTENT_SIZE FILE_NAME

The output columns with -count -q are: QUOTA, REMAINING_QUATA, SPACE_QUOTA, REMAINING_SPACE_QUOTA, DIR_COUNT, FILE_COUNT, CONTENT_SIZE, FILE_NAME

The -h option shows sizes in human readable format.

Example:

  • hdfs dfs -count hdfs://nn1.example.com/file1 hdfs://nn2.example.com/file2
  • hdfs dfs -count -q hdfs://nn1.example.com/file1
  • hdfs dfs -count -q -h hdfs://nn1.example.com/file1

Exit Code:

Returns 0 on success and -1 on error.

cp

Usage: hdfs dfs -cp [-f] [-p | -p[topax]] URI [URI ...] <dest>

复制文件(夹),可以覆盖,可以保留原有权限信息

Options:

  • The -f option will overwrite the destination if it already exists.
  • The -p option will preserve file attributes [topx] (timestamps, ownership, permission, ACL, XAttr). If -p is specified with no arg, then preserves timestamps, ownership, permission. If -pa is specified, then preserves permission also because ACL is a super-set of permission. Determination of whether raw namespace extended attributes are preserved is independent of the -p flag.

Example:

  • hdfs dfs -cp /user/hadoop/file1 /user/hadoop/file2
  • hdfs dfs -cp /user/hadoop/file1 /user/hadoop/file2 /user/hadoop/dir

Exit Code:

Returns 0 on success and -1 on error.

du

Usage: hdfs dfs -du [-s] [-h] URI [URI ...]

显示文件(夹)大小.

Options:

  • The -s option will result in an aggregate summary of file lengths being displayed, rather than the individual files.
  • The -h option will format file sizes in a "human-readable" fashion (e.g 64.0m instead of 67108864)

Example:

  • hdfs dfs -du /user/hadoop/dir1 /user/hadoop/file1 hdfs://nn.example.com/user/hadoop/dir1

Exit Code: Returns 0 on success and -1 on error.

dus

Usage: hdfs dfs -dus <args>

Displays a summary of file lengths.

Note: This command is deprecated. Instead use hdfs dfs -du -s.

expunge

Usage: hdfs dfs -expunge

清空回收站.

get

Usage: hdfs dfs -get [-ignorecrc] [-crc] <src> <localdst>

Copy files to the local file system. Files that fail the CRC check may be copied with the -ignorecrc option. Files and CRCs may be copied using the -crc option.

Example:

  • hdfs dfs -get /user/hadoop/file localfile
  • hdfs dfs -get hdfs://nn.example.com/user/hadoop/file localfile

Exit Code:

Returns 0 on success and -1 on error.

getfacl

Usage: hdfs dfs -getfacl [-R] <path>

显示权限信息.

Options:

  • -R: List the ACLs of all files and directories recursively.
  • path: File or directory to list.

Examples:

  • hdfs dfs -getfacl /file
  • hdfs dfs -getfacl -R /dir

Exit Code:

Returns 0 on success and non-zero on error.

getfattr

Usage: hdfs dfs -getfattr [-R] -n name | -d [-e en] <path>

Displays the extended attribute names and values (if any) for a file or directory.

Options:

  • -R: Recursively list the attributes for all files and directories.
  • -n name: Dump the named extended attribute value.
  • -d: Dump all extended attribute values associated with pathname.
  • -e encoding: Encode values after retrieving them. Valid encodings are "text", "hex", and "base64". Values encoded as text strings are enclosed in double quotes ("), and values encoded as hexadecimal and base64 are prefixed with 0x and 0s, respectively.
  • path: The file or directory.

Examples:

  • hdfs dfs -getfattr -d /file
  • hdfs dfs -getfattr -R -n user.myAttr /dir

Exit Code:

Returns 0 on success and non-zero on error.

getmerge

Usage: hdfs dfs -getmerge <src> <localdst> [addnl]

合并.

ls

Usage: hdfs dfs -ls [-R] <args>

Options:

  • The -R option will return stat recursively through the directory structure.

For a file returns stat on the file with the following format:

permissions number_of_replicas userid groupid filesize modification_date modification_time filename

For a directory it returns list of its direct children as in Unix. A directory is listed as:

permissions userid groupid modification_date modification_time dirname

Example:

  • hdfs dfs -ls /user/hadoop/file1

Exit Code:

Returns 0 on success and -1 on error.

lsr

Usage: hdfs dfs -lsr <args>

Recursive version of ls.

Note: This command is deprecated. Instead use hdfs dfs -ls -R

mkdir

Usage: hdfs dfs -mkdir [-p] <paths>

Takes path uri's as argument and creates directories.

Options:

  • The -p option behavior is much like Unix mkdir -p, creating parent directories along the path.

Example:

  • hdfs dfs -mkdir /user/hadoop/dir1 /user/hadoop/dir2
  • hdfs dfs -mkdir hdfs://nn1.example.com/user/hadoop/dir hdfs://nn2.example.com/user/hadoop/dir

Exit Code:

Returns 0 on success and -1 on error.

moveFromLocal

Usage: hdfs dfs -moveFromLocal <localsrc> <dst>

Similar to put command, except that the source localsrc is deleted after it's copied.

moveToLocal

Usage: hdfs dfs -moveToLocal [-crc] <src> <dst>

Displays a "Not implemented yet" message.

mv

Usage: hdfs dfs -mv URI [URI ...] <dest>

Moves files from source to destination. This command allows multiple sources as well in which case the destination needs to be a directory. Moving files across file systems is not permitted.

Example:

  • hdfs dfs -mv /user/hadoop/file1 /user/hadoop/file2
  • hdfs dfs -mv hdfs://nn.example.com/file1 hdfs://nn.example.com/file2 hdfs://nn.example.com/file3 hdfs://nn.example.com/dir1

Exit Code:

Returns 0 on success and -1 on error.

put

Usage: hdfs dfs -put <localsrc> ... <dst>

Copy single src, or multiple srcs from local file system to the destination file system. Also reads input from stdin and writes to destination file system.

  • hdfs dfs -put localfile /user/hadoop/hadoopfile
  • hdfs dfs -put localfile1 localfile2 /user/hadoop/hadoopdir
  • hdfs dfs -put localfile hdfs://nn.example.com/hadoop/hadoopfile
  • hdfs dfs -put - hdfs://nn.example.com/hadoop/hadoopfile Reads the input from stdin.

Exit Code:

Returns 0 on success and -1 on error.

rm

Usage: hdfs dfs -rm [-f] [-r|-R] [-skipTrash] URI [URI ...]

Delete files specified as args.

Options:

  • The -f option will not display a diagnostic message or modify the exit status to reflect an error if the file does not exist.
  • The -R option deletes the directory and any content under it recursively.
  • The -r option is equivalent to -R.
  • The -skipTrash option will bypass trash, if enabled, and delete the specified file(s) immediately. This can be useful when it is necessary to delete files from an over-quota directory.

Example:

  • hdfs dfs -rm hdfs://nn.example.com/file /user/hadoop/emptydir

Exit Code:

Returns 0 on success and -1 on error.

rmr

Usage: hdfs dfs -rmr [-skipTrash] URI [URI ...]

Recursive version of delete.

Note: This command is deprecated. Instead use hdfs dfs -rm -r

setfacl

Usage: hdfs dfs -setfacl [-R] [-b|-k -m|-x <acl_spec> <path>]|[--set <acl_spec> <path>]

Sets Access Control Lists (ACLs) of files and directories.

Options:

  • -b: Remove all but the base ACL entries. The entries for user, group and others are retained for compatibility with permission bits.
  • -k: Remove the default ACL.
  • -R: Apply operations to all files and directories recursively.
  • -m: Modify ACL. New entries are added to the ACL, and existing entries are retained.
  • -x: Remove specified ACL entries. Other ACL entries are retained.
  • --set: Fully replace the ACL, discarding all existing entries. The acl_spec must include entries for user, group, and others for compatibility with permission bits.
  • acl_spec: Comma separated list of ACL entries.
  • path: File or directory to modify.

Examples:

  • hdfs dfs -setfacl -m user:hadoop:rw- /file
  • hdfs dfs -setfacl -x user:hadoop /file
  • hdfs dfs -setfacl -b /file
  • hdfs dfs -setfacl -k /dir
  • hdfs dfs -setfacl --set user::rw-,user:hadoop:rw-,group::r--,other::r-- /file
  • hdfs dfs -setfacl -R -m user:hadoop:r-x /dir
  • hdfs dfs -setfacl -m default:user:hadoop:r-x /dir

Exit Code:

Returns 0 on success and non-zero on error.

setfattr

Usage: hdfs dfs -setfattr -n name [-v value] | -x name <path>

Sets an extended attribute name and value for a file or directory.

Options:

  • -b: Remove all but the base ACL entries. The entries for user, group and others are retained for compatibility with permission bits.
  • -n name: The extended attribute name.
  • -v value: The extended attribute value. There are three different encoding methods for the value. If the argument is enclosed in double quotes, then the value is the string inside the quotes. If the argument is prefixed with 0x or 0X, then it is taken as a hexadecimal number. If the argument begins with 0s or 0S, then it is taken as a base64 encoding.
  • -x name: Remove the extended attribute.
  • path: The file or directory.

Examples:

  • hdfs dfs -setfattr -n user.myAttr -v myValue /file
  • hdfs dfs -setfattr -n user.noValue /file
  • hdfs dfs -setfattr -x user.myAttr /file

Exit Code:

Returns 0 on success and non-zero on error.

setrep

Usage: hdfs dfs -setrep [-R] [-w] <numReplicas> <path>

Changes the replication factor of a file. If path is a directory then the command recursively changes the replication factor of all files under the directory tree rooted at path.

Options:

  • The -w flag requests that the command wait for the replication to complete. This can potentially take a very long time.
  • The -R flag is accepted for backwards compatibility. It has no effect.

Example:

  • hdfs dfs -setrep -w 3 /user/hadoop/dir1

Exit Code:

Returns 0 on success and -1 on error.

stat

Usage: hdfs dfs -stat URI [URI ...]

Returns the stat information on the path.

Example:

  • hdfs dfs -stat path

Exit Code: Returns 0 on success and -1 on error.

tail

Usage: hdfs dfs -tail [-f] URI

Displays last kilobyte of the file to stdout.

Options:

  • The -f option will output appended data as the file grows, as in Unix.

Example:

  • hdfs dfs -tail pathname

Exit Code: Returns 0 on success and -1 on error.

test

Usage: hdfs dfs -test -[ezd] URI

Options:

  • The -e option will check to see if the file exists, returning 0 if true.
  • The -z option will check to see if the file is zero length, returning 0 if true.
  • The -d option will check to see if the path is directory, returning 0 if true.

Example:

  • hdfs dfs -test -e filename

text

Usage: hdfs dfs -text <src>

Takes a source file and outputs the file in text format. The allowed formats are zip and TextRecordInputStream.

touchz

Usage: hdfs dfs -touchz URI [URI ...]

Create a file of zero length.

Example:

  • hdfs dfs -touchz pathname

Exit Code: Returns 0 on success and -1 on error.

HDFS的Shell的更多相关文章

  1. Hadoop HDFS的shell(命令行客户端)操作实例

    HDFS的shell(命令行客户端)操作实例 3.2 常用命令参数介绍 -help 功能:输出这个命令参数手册 -ls                  功能:显示目录信息 示例: hadoop fs ...

  2. Hadoop开发第6期---HDFS的shell操作

    一.HDFS的shell命令简介 我们都知道HDFS 是存取数据的分布式文件系统,那么对HDFS 的操作,就是文件系统的基本操作,比如文件的创建.修改.删除.修改权限等,文件夹的创建.删除.重命名等. ...

  3. HDFS基本shell操作

    在客户端输入Hadoop fs,可以查看所有的,hadoop shell # -help [cmd] //显示命令的帮助信息,如: hadoop fs -help ls # -ls(r) <pa ...

  4. 大数据:Hadoop(JDK安装、HDFS伪分布式环境搭建、HDFS 的shell操作)

    所有的内容都来源与 Hadoop 官方文档 一.Hadoop 伪分布式安装步骤 1)JDK安装 解压:tar -zxvf jdk-7u79-linux-x64.tar.gz -C ~/app 添加到系 ...

  5. HDFS的Shell、java操作

    HDFS的Shell操作 1.基本语法 bin/hadoop fs 具体命令   OR  bin/hdfs dfs 具体命令 dfs是fs的实现类. 2.命令大全 [Tesla@hadoop102 h ...

  6. HDFS02 HDFS的Shell操作

    HDFS的Shell操作(开发重点) 目录 HDFS的Shell操作(开发重点) 基本语法 常用命令 准备工作 上传 -moveFromLocal 剪切 -copyFromLocal 拷贝 -put ...

  7. 熟练掌握HDFS的Shell访问

    HDFS设计的主要目的是对海量数据进行存储,也就是说在其上能够存储很大量文件 (可以存储TB级的文件).HDFS将这些文件分割之后,存储在不同的DataNode上, HDFS 提供了两种访问接口:Sh ...

  8. HDFS的shell操作

    bin/hadoop命令操作: namenode -format 格式化文件系统 fs(缩写:FileSystem) 运行一个文件系统的用户客户端 bin/hadoop fs常用命令操作: -ls h ...

  9. Hadoop读书笔记(二)HDFS的shell操作

    Hadoop读书笔记(一)Hadoop介绍:http://blog.csdn.net/caicongyang/article/details/39898629 1.shell操作 1.1全部的HDFS ...

随机推荐

  1. 【转】Android 使用ORMLite 操作数据库

    Android 使用ORMLite 操作数据库   用过ssh,s2sh的肯定不会陌生 ,应该一学就会 第一步: 下载ormlite-android-4.41.jar和ormlite-core-4.4 ...

  2. svn:revert to this version 和 revert changes from this version的区别

    假设我们有许多个版本,版本号分别是1-10 如果我们在7这里选择revert to this version那么7之后的8,9,10的操作都会被消除 如果在7选择revert changes from ...

  3. PHP的模板引擎这点事儿

    什么是模板引擎? 为什么要使用它? 为什么要assign一个变量给模板? https://dbforch.wordpress.com/2010/06/26/the-logic-behind-templ ...

  4. DELPHI 里面的迭代

    迭代(Iiterator)的作用:遍历一个集合(Collections)的每一个元素(item). delphi 2005之后新加入一种 for .. in .. 遍历语句,支持String,Set, ...

  5. ionic2rc版常见的一些坑

    1.config.xml里的包名不能有横杠,否则在build android的时候会报错 <widget id="com.ionicframework.name-abc" v ...

  6. 查看mysql存储引擎

    一般情况下,mysql会默认提供多种存储引擎,你可以通过下面的查看: 看你的mysql现在已提供什么存储引擎:mysql> show engines; 看你的mysql当前默认的存储引擎:mys ...

  7. UVa 455 Periodic Strings

    题意:给出一个字符串,找出它的最小的周期,枚举从1到len的周期,看是否满足. #include<iostream> #include<cstdio> #include< ...

  8. .net remoting 客户端与服务端绑定事件,一部电脑当服务器,另一部当客户端,发布后没法接收远程错误信息。

    可以是用下面代码抛出远程错误,客户端和服务端都要设置,因为服务端事件回调时角色变成了远程客户端了. RemotingConfiguration.CustomErrorsMode = CustomErr ...

  9. Dom文档模型

    文档对象模型     通过 JavaScript,您可以重构整个 HTML 文档.您可以添加.移除.改变或重排页面上的项目.要改变页面的某个东西,JavaScript 就需要获得对 HTML 文档中所 ...

  10. (转)CWnd与HWND的区别与转换

    一.区别HWND是句柄,CWnd是MFC窗体类,CWnd中包含HWND句柄成员对象是m_hWnd.HWND是Windows系统中对所有窗口的一种标识,即窗口句柄.这是一个SDK概念.   CWnd是M ...