`

HDFS常用命令

 
阅读更多

bin/hdfs dfs命令

appendToFile

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

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

<!--[if !supportLists]-->·        <!--[endif]-->hdfs dfs -appendToFile localfile /user/hadoop/hadoopfile

<!--[if !supportLists]-->·        <!--[endif]-->hdfs dfs -appendToFile localfile1 localfile2 /user/hadoop/hadoopfile

<!--[if !supportLists]-->·        <!--[endif]-->hdfs dfs -appendToFile localfile hdfs://nn.example.com/hadoop/hadoopfile

<!--[if !supportLists]-->·        <!--[endif]-->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:

<!--[if !supportLists]-->·        <!--[endif]-->hdfs dfs -cat hdfs://nn1.example.com/file1 hdfs://nn2.example.com/file2

<!--[if !supportLists]-->·        <!--[endif]-->hdfs dfs -cat file:///file3 /user/hadoop/file4

Exit Code:

Returns 0 on success and -1 on error.

Chgrpchange group

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

修改所属组.

Options

<!--[if !supportLists]-->·        <!--[endif]-->The -R option will make the change recursively through the directory structure.

chmod

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

修改权限.

Options

<!--[if !supportLists]-->·        <!--[endif]-->The -R option will make the change recursively through the directory structure.

chown

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

修改所有者.

Options

<!--[if !supportLists]-->·        <!--[endif]-->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:

<!--[if !supportLists]-->·        <!--[endif]-->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:

<!--[if !supportLists]-->·        <!--[endif]-->hdfs dfs -count hdfs://nn1.example.com/file1 hdfs://nn2.example.com/file2

<!--[if !supportLists]-->·        <!--[endif]-->hdfs dfs -count -q hdfs://nn1.example.com/file1

<!--[if !supportLists]-->·        <!--[endif]-->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:

<!--[if !supportLists]-->·        <!--[endif]-->The -f option will overwrite the destination if it already exists.

<!--[if !supportLists]-->·        <!--[endif]-->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:

<!--[if !supportLists]-->·        <!--[endif]-->hdfs dfs -cp /user/hadoop/file1 /user/hadoop/file2

<!--[if !supportLists]-->·        <!--[endif]-->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:

<!--[if !supportLists]-->·        <!--[endif]-->The -s option will result in an aggregate summary of file lengths being displayed, rather than the individual files.

<!--[if !supportLists]-->·        <!--[endif]-->The -h option will format file sizes in a "human-readable" fashion (e.g 64.0m instead of 67108864)

Example:

<!--[if !supportLists]-->·        <!--[endif]-->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:

<!--[if !supportLists]-->·        <!--[endif]-->hdfs dfs -get /user/hadoop/file localfile

<!--[if !supportLists]-->·        <!--[endif]-->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:

<!--[if !supportLists]-->·        <!--[endif]-->-R: List the ACLs of all files and directories recursively.

<!--[if !supportLists]-->·        <!--[endif]-->path: File or directory to list.

Examples:

<!--[if !supportLists]-->·        <!--[endif]-->hdfs dfs -getfacl /file

<!--[if !supportLists]-->·        <!--[endif]-->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:

<!--[if !supportLists]-->·        <!--[endif]-->-R: Recursively list the attributes for all files and directories.

<!--[if !supportLists]-->·        <!--[endif]-->-n name: Dump the named extended attribute value.

<!--[if !supportLists]-->·        <!--[endif]-->-d: Dump all extended attribute values associated with pathname.

<!--[if !supportLists]-->·        <!--[endif]-->-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.

<!--[if !supportLists]-->·        <!--[endif]-->path: The file or directory.

Examples:

<!--[if !supportLists]-->·        <!--[endif]-->hdfs dfs -getfattr -d /file

<!--[if !supportLists]-->·        <!--[endif]-->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:

<!--[if !supportLists]-->·        <!--[endif]-->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:

<!--[if !supportLists]-->·        <!--[endif]-->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:

<!--[if !supportLists]-->·        <!--[endif]-->The -p option behavior is much like Unix mkdir -p, creating parent directories along the path.

Example:

<!--[if !supportLists]-->·        <!--[endif]-->hdfs dfs -mkdir /user/hadoop/dir1 /user/hadoop/dir2

<!--[if !supportLists]-->·        <!--[endif]-->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:

<!--[if !supportLists]-->·        <!--[endif]-->hdfs dfs -mv /user/hadoop/file1 /user/hadoop/file2

<!--[if !supportLists]-->·        <!--[endif]-->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.

<!--[if !supportLists]-->·        <!--[endif]-->hdfs dfs -put localfile /user/hadoop/hadoopfile

<!--[if !supportLists]-->·        <!--[endif]-->hdfs dfs -put localfile1 localfile2 /user/hadoop/hadoopdir

<!--[if !supportLists]-->·        <!--[endif]-->hdfs dfs -put localfile hdfs://nn.example.com/hadoop/hadoopfile

<!--[if !supportLists]-->·        <!--[endif]-->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:

<!--[if !supportLists]-->·        <!--[endif]-->The -f option will not display a diagnostic message or modify the exit status to reflect an error if the file does not exist.

<!--[if !supportLists]-->·        <!--[endif]-->The -R option deletes the directory and any content under it recursively.

<!--[if !supportLists]-->·        <!--[endif]-->The -r option is equivalent to -R.

<!--[if !supportLists]-->·        <!--[endif]-->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:

<!--[if !supportLists]-->·        <!--[endif]-->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:

<!--[if !supportLists]-->·        <!--[endif]-->-b: Remove all but the base ACL entries. The entries for user, group and others are retained for compatibility with permission bits.

<!--[if !supportLists]-->·        <!--[endif]-->-k: Remove the default ACL.

<!--[if !supportLists]-->·        <!--[endif]-->-R: Apply operations to all files and directories recursively.

<!--[if !supportLists]-->·        <!--[endif]-->-m: Modify ACL. New entries are added to the ACL, and existing entries are retained.

<!--[if !supportLists]-->·        <!--[endif]-->-x: Remove specified ACL entries. Other ACL entries are retained.

<!--[if !supportLists]-->·        <!--[endif]-->--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.

<!--[if !supportLists]-->·        <!--[endif]-->acl_spec: Comma separated list of ACL entries.

<!--[if !supportLists]-->·        <!--[endif]-->path: File or directory to modify.

Examples:

<!--[if !supportLists]-->·        <!--[endif]-->hdfs dfs -setfacl -m user:hadoop:rw- /file

<!--[if !supportLists]-->·        <!--[endif]-->hdfs dfs -setfacl -x user:hadoop /file

<!--[if !supportLists]-->·        <!--[endif]-->hdfs dfs -setfacl -b /file

<!--[if !supportLists]-->·        <!--[endif]-->hdfs dfs -setfacl -k /dir

<!--[if !supportLists]-->·        <!--[endif]-->hdfs dfs -setfacl --set user::rw-,user:hadoop:rw-,group::r--,other::r-- /file

<!--[if !supportLists]-->·        <!--[endif]-->hdfs dfs -setfacl -R -m user:hadoop:r-x /dir

<!--[if !supportLists]-->·        <!--[endif]-->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:

<!--[if !supportLists]-->·        <!--[endif]-->-b: Remove all but the base ACL entries. The entries for user, group and others are retained for compatibility with permission bits.

<!--[if !supportLists]-->·        <!--[endif]-->-n name: The extended attribute name.

<!--[if !supportLists]-->·        <!--[endif]-->-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.

<!--[if !supportLists]-->·        <!--[endif]-->-x name: Remove the extended attribute.

<!--[if !supportLists]-->·        <!--[endif]-->path: The file or directory.

Examples:

<!--[if !supportLists]-->·        <!--[endif]-->hdfs dfs -setfattr -n user.myAttr -v myValue /file

<!--[if !supportLists]-->·        <!--[endif]-->hdfs dfs -setfattr -n user.noValue /file

<!--[if !supportLists]-->·        <!--[endif]-->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:

<!--[if !supportLists]-->·        <!--[endif]-->The -w flag requests that the command wait for the replication to complete. This can potentially take a very long time.

<!--[if !supportLists]-->·        <!--[endif]-->The -R flag is accepted for backwards compatibility. It has no effect.

Example:

<!--[if !supportLists]-->·        <!--[endif]-->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:

<!--[if !supportLists]-->·        <!--[endif]-->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:

<!--[if !supportLists]-->·        <!--[endif]-->The -f option will output appended data as the file grows, as in Unix.

Example:

<!--[if !supportLists]-->·        <!--[endif]-->hdfs dfs -tail pathname

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

test

Usage: hdfs dfs -test -[ezd] URI

Options:

<!--[if !supportLists]-->·        <!--[endif]-->The -e option will check to see if the file exists, returning 0 if true.

<!--[if !supportLists]-->·        <!--[endif]-->The -z option will check to see if the file is zero length, returning 0 if true.

<!--[if !supportLists]-->·        <!--[endif]-->The -d option will check to see if the path is directory, returning 0 if true.

Example:

<!--[if !supportLists]-->·        <!--[endif]-->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:

<!--[if !supportLists]-->·        <!--[endif]-->hdfs dfs -touchz pathname

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

 

 

分享到:
评论

相关推荐

    Hadoop-HDFS常用命令

    Hadoop-HDFS常用命令

    大数据技术基础实验报告-HDFS常用操作命令.doc

    本实验报告主要关注HDFS的常用操作命令,这些命令是管理员和数据分析师日常工作中不可或缺的工具。 实验开始时,通过执行`start-dfs.sh`命令启动HDFS服务。这是在Hadoop集群中启动所有DataNode和NameNode节点的关键...

    HDFS_HBaseShell的常用命令

    HDFS常用命令: 1. 将磁盘上的文件放到HDFS上:Hadoop fs -put /local /hdfs 2. 将HDFS上的文件放到磁盘上:Hadoop dfs -get /hdfs /local 3. 列出HDFS上的目录内容:Hadoop dfs –ls /hdfsDir 4. 删除HDFS下的文档...

    HDFS常用Shell命令.md

    HDFS常用Shell命令,基础篇

    Hadoop HDFS分布式文件系统 常用命令汇总

    Hadoop HDFS分布式文件系统常用命令汇总 Hadoop HDFS分布式文件系统是大数据存储和处理的核心组件。作为一个分布式文件系统,HDFS提供了高可靠性、高可扩展性和高性能的存储解决方案。在使用HDFS时,经常需要执行...

    HDFS基本命令.docx

    在HDFS中,基本命令是最基础也是最常用的命令,掌握这些命令是使用HDFS的基础。本节我们将详细介绍HDFS中的基本命令。 -help命令 HDFS中的-help命令用于显示HDFS的帮助信息。该命令可以显示所有可用的命令和参数。...

    大数据教程-HDFS常用Shell命令.md.zip

    本教程将聚焦于HDFS的Shell命令,这些命令对于数据处理和管理至关重要。以下是HDFS Shell命令的一些基本知识和常见操作。 1. **查看当前目录(pwd)**: 使用`hadoop fs -pwd`命令可以显示当前工作目录,它类似于...

    数据存储实验2-熟悉常用的HDFS操作.doc(实验报告)

    通过本实验,我们学习了HDFS的基本概念和常用的操作命令,熟悉了HDFS在Hadoop体系结构中的角色,并且掌握了HDFS的Java API。这些知识将帮助我们更好地理解和使用HDFS在数据存储和处理中的应用。

    HDFS部署与Shell命令使用

    通过对HDFS的不同部署模式及常用Shell命令的学习,我们可以更好地理解和操作HDFS。其中,`fs`命令用于基本的文件操作,`dfsadmin`用于管理HDFS集群的状态,`fsck`用于检查和维护文件系统的健康状态,而`balancer`则...

    大数据实验二-HDFS编程实践

    2. **Shell命令的掌握**:熟练掌握了HDFS常用Shell命令后,可以在日常运维或数据处理过程中快速高效地执行任务。 3. **Java API的应用**:Java API提供了更高级的功能支持,如并发处理、错误恢复等,对于开发高性能...

    实验二:熟悉常用的HDFS操作

    实验二:“熟悉常用的HDFS操作”旨在帮助学习者深入理解Hadoop分布式文件系统(HDFS)在大数据处理中的核心地位,以及如何通过Shell命令和Java API进行高效操作。HDFS在Hadoop架构中扮演着存储大数据的核心角色,为...

    Hadoop HDFS_Shell命令详解.pdf

    #### 其他常用命令 ##### get **使用方法**: `hadoop fs -get URI &lt;localdst&gt;` 该命令用于从 HDFS 下载文件到本地文件系统。 ##### getmerge **使用方法**: `hadoop fs -getmerge &lt;src&gt; &lt;dst&gt;` 合并多个文件为一个...

    大数据分析技术:HDFS的常用命令.docx

    以下是HDFS的一些常用命令: 1. **基本语法**: 使用`hadoop fs`或`hdfs dfs`命令前缀执行具体操作,两者等价。 2. **命令大全**: - `-appendToFile`:将本地文件追加到HDFS文件末尾。 - `-cat`:查看文件内容...

    Hadoop中一些hdfs的命令

    下面详细介绍一些常用的HDFS命令及其用法: ##### 2.1 创建目录 - **语法**: `hdfs dfs -mkdir [-p] &lt;path&gt;` - `-mkdir`: 创建指定的目录。 - `-p`: 如果指定,则允许创建多级目录。 **示例**: ```shell # ...

    HDFS常用指令

    Hadoop是一个能够对大量数据进行分布式处理的软件框架,具有可靠、高效、可伸缩的,其核心是:HDFS(分布式文件系统)、Mapreduce(分布式计算框架)。HDFS分布式文件系统常用指令文档

    HDFS常用Shell命令

    本篇文章只是简单阐述一下HDFS中常用命令, 在实际开发中可使用 bin/hadoop fs查看命令详情 使用HDFS基本语法: bin/hadoop fs OR bin/hdfs dfs 注:为帮助快速理解并使用本文中使用T表示target 基本命令 1.启动...

    DaemonicCao#BigData-notes#HDFS常用Shell命令1

    1. 显示当前目录结构 2. 创建目录 3. 删除操作 4. 从本地加载文件到 HDFS 5. 从 HDFS 导出文件到本地 6. 查看文件内容 7. 显示文件

    精品课程推荐 大数据与云计算教程课件 优质大数据课程 07.HDFS Shell命令(共21页).pptx

    4. **常用HDFS Shell命令**: - `-help`:显示命令帮助信息。 - `-ls`:列出目录内容。 - `-du`:显示文件或目录大小。 - `-count`:计算文件数量。 - `-mv`:移动文件或目录。 - `-cp`:复制文件或目录。 - ...

    大数据平台实践 五.HDFS常用操作和增加节点

    【大数据HDFS常用操作】 Hadoop分布式文件系统(HDFS)是大数据处理中的核心组件,提供了高容错、高吞吐量的数据存储能力。本文将详细介绍HDFS的一些常见操作,帮助用户更好地理解和使用HDFS。 1. **列出文件列表*...

    厦门大学-林子雨-大数据技术基础-第3章 分布式文件系统HDFS-上机练习-熟悉常用的HDFS操作

    首先,学生需要理解HDFS在Hadoop体系结构中的角色,然后熟练使用HDFS操作常用的Shell命令,最后熟悉HDFS操作常用的Java API。 本次上机练习的实验平台是Linux操作系统,使用Hadoop 1.2.1或以上版本,JDK 1.6或以上...

Global site tag (gtag.js) - Google Analytics