Create a directory in HDFS - mkdir

The hadoop mkdir command is for creating directories in the hdfs. This is similar to the unix mkdir command. You can use the -p option for creating parent directories. Takes path uri’s as argument and creates directories.

Usage:
hadoop fs -mkdir
Examples:
hadoop fs -mkdir /user/hadoop/corejavaguru
hadoop fs -mkdir /user/hadoop/dir1 /user/hadoop/dir2
hadoop fs -mkdir -p /user/hadoop/corejavaguru/fscommands/demo

List the contents of a HDFS directory - ls

The ls command is used to list out the directories and files.

For a file ls 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
Usage:
hadoop fs -ls
Example:
hadoop fs -ls /user/hadoop/file1

Upload a file into HDFS - put

put command is used to copy single source, or multiple sources to the destination file system. Also reads input from stdin and writes to destination file system. The different ways for the put command are :

Usage:
hadoop fs -put ... <hdfs_dest_path>
Example:
hadoop fs -put /home/hadoop/Samplefile.txt /user/hadoop/dir3/
hadoop fs -put localfile1 localfile2 /user/hadoop/hadoopdir
hadoop fs -put localfile hdfs://nn.example.com/hadoop/hadoopfile

Download a file from HDFS - get

Hadoop get command copies the files from HDFS to the local file system. The syntax of the get command is shown below:

Usage:
hadoop fs -get [-ignorecrc] [-crc]
Example:
hadoop fs -get /user/hadoop/file localfile
hadoop fs -get hdfs://nn.example.com/user/hadoop/file localfile

See contents of a file in HDFS - cat

cat command is used to print the contents of the file on the stdout.

Usage:
hadoop fs -cat <path[filename]>
Example:
hadoop fs -cat /user/hadoop/dir1/xyz.txt

Copy a file from source to destination in HDFS - cp

cp command is for copying the source into the target. This command allows multiple sources as well in which case the destination must be a directory.

Usage:
hadoop fs -cp [-f] [-p | -p[topax]] URI [URI ...]
Example:
hadoop fs -cp /user/hadoop/file1 /user/hadoop/file2
hadoop fs -cp /user/hadoop/file1 /user/hadoop/file2 /user/hadoop/dir

Copy a file from Local file system to HDFS - copyFromLocal

The hadoop copyFromLocal command is used to copy a file from the local file system to the hadoop hdfs. Similar to put command, except that the source is restricted to a local file reference.

Usage:
hadoop fs -copyFromLocal URI
Example:
hadoop fs -copyFromLocal /home/hadoop/xyz.txt /user/hadoop/xyz.txt

Copy a file from HDFS to Local file system - copyToLocal

The hadoop copyToLocal command is used to copy a file from the hdfs to the local file system. Similar to get command, except that the destination is restricted to a local file reference.

Usage:
hadoop fs -copyToLocal [-ignorecrc] [-crc] URI
Example:
hadoop fs -copyToLocal /user/hadoop/xyz.txt /home/hadoop/xyz.txt

Move file from source to destination in HDFS - mv

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

Usage:
hadoop fs -mv URI [URI ...]
Example:
hadoop fs -mv /user/hadoop/file1 /user/hadoop/file2
hadoop fs -mv hdfs://nn.example.com/file1 hdfs://nn.example.com/file2 hdfs://nn.example.com/dir1

Remove a file or directory in HDFS - rm, rmdir

rm

Delete files specified as args. Deletes directory only when it is empty

Usage:
hadoop fs -rm [-f] [-r |-R] [-skipTrash] URI [URI ...]
Example:
hadoop fs -rm hdfs://nn.example.com/file /user/hadoop/emptydir

rmdir

Delete a directory specified as args.

Usage:
hadoop fs -rmdir [--ignore-fail-on-non-empty] URI [URI ...]
Example:
hadoop fs -rmdir /user/hadoop/emptydir

Options: --ignore-fail-on-non-empty: When using wildcards, do not fail if a directory still contains files.


Display last few lines of a file in HDFS - tail

Displays last kilobyte of the file to stdout.

Usage:
hadoop fs -tail [-f] URI
Example:
hafoop fs -tail /user/hadoop/demo.txt

Print statistics about the file or directory in HDFS - stat

Use stat to print statistics about the file/directory at in the specified format.

Usage:
hadoop fs -stat [format] ...
Example:
hadoop fs -stat /user/hadoop/

Display the size of files and directories in HDFS - du

The du command displays aggregate length of files contained in the directory or the length of a file in case its just a file.

Usage :
hadoop fs -du
Example:
hadoop fs -du /user/hadoop/dir1/xyz.txt

Change group of files in HDFS - chgrp

The hadoop chgrp shell command is used to change the group association of files. The user must be the owner of files, or else a super-user.

Usage:
hadoop fs -chgrp [-R] GROUP URI [URI ...]

Change the permissions of files in HDFS - chmod

The hadoop chmod command is used to change the permissions of files. The user must be the owner of the file, or else a super-user.

Usage:
hadoop fs -chmod [-R] <mode[,mode]... |="" octalmode=""> URI [URI ...]

Change the owner of files in HDFS - chown

The hadoop chown command is used to change the ownership of files. The user must be a super-user.

Usage:
hadoop fs -chown [-R] [OWNER][:[GROUP]] URI [URI ]

Help for an individual HDFS command - usage

Below command return the help for an individual command.

Usage:
hadoop fs -usage command

 

hadoop 文件操作的更多相关文章

  1. 马士兵hadoop第二课:hdfs集群集中管理和hadoop文件操作

    马士兵hadoop第一课:虚拟机搭建和安装hadoop及启动 马士兵hadoop第二课:hdfs集群集中管理和hadoop文件操作 马士兵hadoop第三课:java开发hdfs 马士兵hadoop第 ...

  2. 马士兵hadoop第二课:hdfs集群集中管理和hadoop文件操作(转)

    马士兵hadoop第一课:虚拟机搭建和安装hadoop及启动 马士兵hadoop第二课:hdfs集群集中管理和hadoop文件操作 马士兵hadoop第三课:java开发hdfs 马士兵hadoop第 ...

  3. 二、hadoop文件操作

    1.使用hadoop命令查看hdfs下文件 [root@localhost hadoop-2.7.2]# hadoop fs -ls hdfs://192.168.211.129:9000/  (最后 ...

  4. Hadoop文件操作常用命令

    1.创建目录 #hdfs dfs -mkidr /test 2.查询目录结构 #hdfs dfs -ls / 子命令 -R递归查看//查看具体的某个目录:例如#hdfs dfs -ls /test 3 ...

  5. Hadoop之HDFS文件操作常有两种方式(转载)

    摘要:Hadoop之HDFS文件操作常有两种方式,命令行方式和JavaAPI方式.本文介绍如何利用这两种方式对HDFS文件进行操作. 关键词:HDFS文件    命令行     Java API HD ...

  6. Hadoop第4周练习—HDFS读写文件操作

    1    运行环境说明... 3 :编译并运行<权威指南>中的例3.2. 3 内容... 3 2.3.1   创建代码目录... 4 2.3.2   建立例子文件上传到hdfs中... 4 ...

  7. hadoop的hdfs文件操作实现上传文件到hdfs

    这篇文章主要介绍了使用hadoop的API对HDFS上的文件访问,其中包括上传文件到HDFS上.从HDFS上下载文件和删除HDFS上的文件,需要的朋友可以参考下hdfs文件操作操作示例,包括上传文件到 ...

  8. Hadoop之HDFS文件操作

    摘要:Hadoop之HDFS文件操作常有两种方式.命令行方式和JavaAPI方式.本文介绍怎样利用这两种方式对HDFS文件进行操作. 关键词:HDFS文件    命令行     Java API HD ...

  9. Hadoop学习笔记之二 文件操作

    HDFS分布式文件系统:优点:支持超大文件存储.流式访问.一次写入多次读取.缺点:不适应大量小文件.不适应低时延的数据访问.不适应多用户访问任意修改文件. 1.hadoop用于大数据处理,在数据量较小 ...

随机推荐

  1. IOS 面试题系列

    随着iOS平台开发的职位的增加,笔试.面试也越来越有“套路”,这里我总结了一些面试题,多数是Objective-C的基础知识,适合于面试新人,答案是我自己答的,不准确的地方,欢迎指出. 1.   Ob ...

  2. 计算机网络、OSI模型、TCP/IP族

    一.计算机网络分类 1.按通信距离分类: 局域网:LAN,10m-1000m,房间.校园: 城域网:MAN,10km,城市: 广域网:WAN,100km以上,国家.全球. 二.OSI(Open Sys ...

  3. ARM开发板如何选型-I.MX6Q开发板

    拥有丰富扩展能力,供货周期长的开发平台,省事安心   处理器:迅为-i.MX6开发板恩智浦Cortex-A9 四核i.MX6Q处理器,主频1GHz,内存2G,存储16GB. 系统支持:i.MX6开发板 ...

  4. formSelects-v4.js 基于Layui的多选解决方案

    https://hnzzmsf.github.io/example/example_v4.html

  5. 安装钩子 SetWindowsHookE

    SetWindowsHookEx 函数将应用程序定义的钩子安装到一个钩链.要将安装一个钩子来监测系统的某些类型的事件.这些事件是与特定的线程或所有线程中调用线程作为同一桌面相关联. Syntax HH ...

  6. Perl字符集就是方括号(或称中括号)里一连串可能的字符,只匹配单一字符,该单一字符可以是字符集里的任何一个,“-”在字符集里有特殊含义:表示某个范围的字符。而字符集意外的连字符不具有特殊意义。

    Perl字符集就是方括号(或称中括号)里一连串可能的字符,只匹配单一字符,该单一字符可以是字符集里的任何一个,“-”在字符集里有特殊含义:表示某个范围的字符.而字符集意外的连字符不具有特殊意义.

  7. react之webpack

    1. 下载相关模块包 * 创建package.json ``` npm init ``` * react相关库 package-lock.json ``` npm install react reac ...

  8. C++ 指针形参和指针引用形参的原理分析

    C++ 函数的参数传递可以分为:值传递和引用传递. 两者的最大区别也很简单,如果该函数的参数只是读的话,值传递就可以满足.如果该函数的参数需要进行修改并返回的时候,就应该进行引用传递. C++指针作为 ...

  9. 零基础入门学习Python(19)--函数:我的地盘听我的

    知识点 函数与过程 在许多编程语言中,函数(function)是有返回值的,过程(procedure)是简单.特殊并且没有返回值的.而在Python中,严格来说只有函数没有过程. 例如: >&g ...

  10. Python之Pycharm安装及介绍

    在学习Python之前,先安装好编程所需的编译环境也就是IDE,在安装PycharPm之前先安装最新版本的anaconda根据不同的系统选择不同的版本,安装好anaconda以后再安装Pycharm, ...