Using the command line to manage files on HDFS--转载
原文地址:http://zh.hortonworks.com/hadoop-tutorial/using-commandline-manage-files-hdfs/
In this tutorial we will walk through some of the basic HDFS commands you will need to manage files on HDFS. To complete this tutorial you will need a working HDP cluster. The easiest way to have a Hadoop cluster is to download the Hortonworks Sandbox.
Let’s get started.
Step 1: Let’s create a directory in HDFS, upload a file and list.
Let’s look at the syntax first:
hadoop fs -mkdir:
- It will take path uri’s as argument and creates directory or directories.
Usage:
hadoop fs -mkdir <paths>
Example:
hadoop fs -mkdir /user/hadoop/dir1 /user/hadoop/dir2
hadoop fs -mkdir hdfs://nn1.example.com/user/hadoop/dir
hadoop fs -ls:
- Lists the contents of a directory
- For a file returns stats of a file
Usage:
hadoop fs -ls <args>
Example:
hadoop fs -ls /user/hadoop/dir1 /user/hadoop/dir2
hadoop fs -ls /user/hadoop/dir1/filename.txt
hadoop fs -ls hdfs://<hostname>:9000/user/hadoop/dir1/
Let’s use the following commands as follows and execute. You can ssh to the sandbox using Tools like Putty. You could download putty.exe from the internet.
Let’s touch a file locally.
$ touch filename.txt
Step 2: Now, let’s check how to find out space utilization in a HDFS dir.
hadoop fs -du:
- Displays sizes of files and directories contained in the given directory or the size of a file if its just a file.
Usage:
hadoop fs -du URI
Example:
hadoop fs -du /user/hadoop/ /user/hadoop/dir1/Sample.txt
Step 4:
Now let’s see how to upload and download files from and to Hadoop Data File System(HDFS)
Upload: ( we have already tried this earlier)
hadoop fs -put:
- Copy single src file, or multiple src files from local file system to the Hadoop data file system
Usage:
hadoop fs -put <localsrc> ... <HDFS_dest_Path>
Example:
hadoop fs -put /home/ec2-user/Samplefile.txt ./ambari.repo /user/hadoop/dir3/
Download:
hadoop fs -get:
- Copies/Downloads files to the local file system
Usage:
hadoop fs -get <hdfs_src> <localdst>
Example:
hadoop fs -get /user/hadoop/dir3/Samplefile.txt /home/
Step 5: Let’s look at quickly two advanced features.
hadoop fs -getmerge
- Takes a source directory files as input and concatenates files in src into the destination local file.
Usage:
hadoop fs -getmerge <src> <localdst> [addnl]
Example:
hadoop fs -getmerge /user/hadoop/dir1/ ./Samplefile2.txt
Option:
addnl: can be set to enable adding a newline on end of each file
hadoop distcp:
- Copy file or directories recursively
- It is a tool used for large inter/intra-cluster copying
- It uses MapReduce to effect its distribution copy, error handling and recovery, and reporting
Usage:
hadoop distcp <srcurl> <desturl>
Example:
hadoop distcp hdfs://<NameNode1>:8020/user/hadoop/dir1/ \
hdfs://<NameNode2>:8020/user/hadoop/dir2/
You could use the following steps to perform getmerge and discp.
Let’s upload two files for this exercise first:
# touch txt1 txt2
# hadoop fs -put txt1 txt2 /user/hadoop/dir2/
# hadoop fs -ls /user/hadoop/dir2/
Step 6:Getting help
You can use Help command to get list of commands supported by Hadoop Data File System(HDFS)
Example:
hadoop fs -help
Hope this short tutorial was useful to get the basics of file management.
Using the command line to manage files on HDFS--转载的更多相关文章
- How to Use Android ADB Command Line Tool
Android Debug Bridge (adb) is a tool that lets you manage the state of an emulator instance or Andro ...
- 18 Command Line Tools to Monitor Linux Performance
By Ravi Saive Under: Linux Commands, Monitoring Tools On: December 26, 2013 http://www.tecmint.com/c ...
- How to build .apk file from command line(转)
How to build .apk file from command line Created on Wednesday, 29 June 2011 14:32 If you don’t want ...
- Can't use Subversion command line client: svn Probably the path to Subversion executable is wrong. Fix it.
1.最近使用SVN工具时,Checkout出项目到本地后后,然后将其导入到Intellij idea中开发,在提交svn代码的时候,出现这样的错误:Can't use Subversion comma ...
- 使用intellij的svn时提示出错: Can't use Subversion command line client: svn.Errors found while svn working copies detection.
使用Intellij的svn时提示出错:Can't use Subversion command line client: svn. Errors found while svn working co ...
- MySQL 5.7 Command Line Client输入密码后闪退和windows下mysql忘记root密码的解决办法
MySQL 5.7 Command Line Client输入密码后闪退的问题: 问题分析: 1.查看mysql command line client默认执行的一些参数.方法:开始->所有程序 ...
- 《The Linux Command Line》 读书笔记01 基本命令介绍
<The Linux Command Line> 读书笔记01 基本命令介绍 1. What is the Shell? The Shell is a program that takes ...
- Linux Command Line Basics
Most of this note comes from the Beginning the Linux Command Line, Second Edition by Sander van Vugt ...
- python click module for command line interface
Click Module(一) ----xiaojikuaipao The following mat ...
随机推荐
- 20155305《信息安全系统设计基础》10月18日课堂 fork,exic,wait
20155305<信息安全系统设计基础>10月18日课堂 fork,exic,wait fork()函数 1.fork函数作用 一般来讲, 我们编写1个普通的c程序, 运行这个程序直到程序 ...
- 20155330 2016-2017-2 《Java程序设计》第四周学习总结
20155330 2016-2017-2 <Java程序设计>第四周学习总结 教材学习内容总结 学习目标 理解封装.继承.多态的关系 理解抽象类与接口的区别 掌握S.O.L.I.D原则 了 ...
- 20155338 2016-2017-2 《Java程序设计》第3周学习总结
20155338 2016-2017-2 <Java程序设计>第3周学习总结 教材学习内容总结 本周学习量比较多,但是知识点并不是特别难,学习了书本的第四五章,其中个人重点学习了数组对象. ...
- python append extend区别
1. 列表可包含任何数据类型的元素,单个列表中的元素无须全为同一类型. 2. append() 方法向列表的尾部添加一个新的元素. 3. 列表是以类的形式实现的.“创建”列表实际上是将一个类实例化.因 ...
- Karma与TSLint
TSLint TSLint是一个可扩展的静态分析工具,用于检查TypeScript代码的可读性,可维护性和功能性错误.收到现代编辑和构建系统的广泛支持,并且可以使用您自己的路由,配置和格式化. 安装 ...
- 「日常训练」 Fire!(UVA-11624)
与其说是训练不如说是重温.重新写了Java版本的代码. import java.util.*; import java.math.*; import java.io.BufferedInputStre ...
- 书写可维护的javascript
内容介绍 编写可维护的代码很重要,因为大部分开发人员都花费大量时间维护他人代码. 1.什么是可维护的代码? 一般来说可维护的代码都有以下一些特征: 可理解性---------其他人可以接手代码并理解它 ...
- dubbo 微服务
# spring-dubbo-service 微服务 项目地址:https://github.com/windwant/spring-dubbo-service spring dubbo servic ...
- 技本功丨用短平快的方式告诉你:Flink-SQL的扩展实现
2019年1月28日,阿里云宣布开源“计算王牌”实时计算平台Blink回馈给ApacheFlink社区.官方称,计算延迟已经降到毫秒级,也就是你在浏览网页的时候,眨了一下眼睛,淘宝.天猫处理的信息已经 ...
- C++进阶训练——停车收费系统设计
一.简介 经过一段时间的c++基础学习,是时候做一个较为全面的.运用c++功能的较复杂的项目练练手了. 运用软件:Visual Studio (VS). 题目:c++停车收费系统设计(某本编程书进 ...