HDFS命令行客户端使用,命令行客户端支持的命令参数,常用命令参数介绍
3.HDFS的shell(命令行客户端)操作
3.1 HDFS命令行客户端使用
[toto@hadoop hadoop-2.8.0]$ hdfs dfs -ls / (推荐使用这种方式,hdfs现在这种是最新的一种方式) Found 4 items drwxr-xr-x - toto supergroup 0 2017-05-29 14:01 /findbugs-1.3.9 drwxr-xr-x - toto supergroup 0 2017-05-29 03:23 /hive drwx------ - toto supergroup 0 2017-05-29 14:47 /tmp drwxr-xr-x - toto supergroup 0 2017-05-29 14:47 /user [toto@hadoop hadoop-2.8.0]$ 或者使用: [toto@hadoop hadoop-2.8.0]$ hadoop fs -ls / Found 4 items drwxr-xr-x - toto supergroup 0 2017-05-29 14:01 /findbugs-1.3.9 drwxr-xr-x - toto supergroup 0 2017-05-29 03:23 /hive drwx------ - toto supergroup 0 2017-05-29 14:47 /tmp drwxr-xr-x - toto supergroup 0 2017-05-29 14:47 /user [toto@hadoop hadoop-2.8.0]$ |
3.2 命令行客户端支持的命令参数
[toto@hadoop learn]$ hadoop fs help 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] [-d] <localsrc> ... <dst>] [-copyToLocal [-f] [-p] [-ignoreCrc] [-crc] <src> ... <localdst>] [-count [-q] [-h] [-v] [-t [<storage type>]] [-u] [-x] <path> ...] [-cp [-f] [-p | -p[topax]] [-d] <src> ... <dst>] [-createSnapshot <snapshotDir> [<snapshotName>]] [-deleteSnapshot <snapshotDir> <snapshotName>] [-df [-h] [<path> ...]] [-du [-s] [-h] [-x] <path> ...] [-expunge] [-find <path> ... <expression> ...] [-get [-f] [-p] [-ignoreCrc] [-crc] <src> ... <localdst>] [-getfacl [-R] <path>] [-getfattr [-R] {-n name | -d} [-e en] <path>] [-getmerge [-nl] [-skip-empty-file] <src> <localdst>] [-help [cmd ...]] [-ls [-C] [-d] [-h] [-q] [-R] [-t] [-S] [-r] [-u] [<path> ...]] [-mkdir [-p] <path> ...] [-moveFromLocal <localsrc> ... <dst>] [-moveToLocal <src> <localdst>] [-mv <src> ... <dst>] [-put [-f] [-p] [-l] [-d] <localsrc> ... <dst>] [-renameSnapshot <snapshotDir> <oldName> <newName>] [-rm [-f] [-r|-R] [-skipTrash] [-safely] <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 ...]] [toto@hadoop learn]$ |
3.2 常用命令参数介绍
关于hdfs的命令,可以查看http://hadoop.apache.org/docs/r1.0.4/cn/hdfs_shell.html
-help 功能:输出这个命令参数手册 |
-ls 功能:显示目录信息 示例: hadoop fs -ls hdfs://hadoop:9000/ 备注:这些参数中,所有的hdfs路径都可以简写 -->hadoop fs -ls / 等同于上一条命令的效果 [toto@hadoop learn]$ hadoop fs -ls hdfs://hadoop:9000/ Found 4 items drwxr-xr-x - toto supergroup 0 2017-05-29 14:01 hdfs://hadoop:9000/findbugs-1.3.9 drwxr-xr-x - toto supergroup 0 2017-05-29 03:23 hdfs://hadoop:9000/hive drwx------ - toto supergroup 0 2017-05-29 14:47 hdfs://hadoop:9000/tmp drwxr-xr-x - toto supergroup 0 2017-05-29 14:47 hdfs://hadoop:9000/user [toto@hadoop learn]$ 上面的命令等同:hadoop fs -ls / [toto@hadoop learn]$ hadoop fs -ls hdfs://hadoop:9000/findbugs-1.3.9 下面的命令表示同时列出hdfs://hadoop:9000/findbugs-1.3.9和hive下面的内容 [toto@hadoop learn]$ hadoop fs -ls hdfs://hadoop:9000/findbugs-1.3.9 /hive |
-mkdir
mkdir使用方法:hadoop fs -mkdir <paths> 功能:在hdfs上创建目录,接受路径指定的uri作为参数,创建这些目录。其行为类似于Unix的mkdir -p,它会创建路径中的各级父目录。 示例:hadoop fs -mkdir -p /aaa/bbb/cc/dd
再如示例: [toto@hadoop learn]$hadoop fs –mkdir -p /user/hadoop/dir1 /user/hadoop/dir2 [toto@hadoop learn]$ hadoop fs -mkdir -p hdfs://hadoop:9000/toto hdfs://hadoop:9000/toto2 [toto@hadoop learn]$ hadoop fs -ls / Found 6 items drwxr-xr-x - toto supergroup 0 2017-05-29 14:01 /findbugs-1.3.9 drwxr-xr-x - toto supergroup 0 2017-05-29 03:23 /hive drwx------ - toto supergroup 0 2017-05-29 14:47 /tmp drwxr-xr-x - toto supergroup 0 2017-05-29 23:40 /toto drwxr-xr-x - toto supergroup 0 2017-05-29 23:41 /toto2 drwxr-xr-x - toto supergroup 0 2017-05-29 23:36 /user 对应浏览器上的访问效果如下:http://hadoop:50070/explorer.html#/ 显示效果一致 |
-moveFromLocal 使用方法:dfs -moveFromLocal <src> <dst> 功能:从本地剪切粘贴到hdfs [toto@hadoop learn]$ ls hadoop LICENSE-ASM.txt [toto@hadoop learn]$ hdfs dfs -moveFromLocal LICENSE-ASM.txt /toto [toto@hadoop learn]$ hdfs dfs -ls /toto Found 1 items -rw-r--r-- 3 toto supergroup 1511 2017-05-29 23:50 /toto/LICENSE-ASM.txt [toto@hadoop learn]$
再如: [toto@hadoop learn]$ hadoop fs -moveFromLocal hadoop /toto [toto@hadoop learn]$ hadoop fs -ls /toto Found 2 items -rw-r--r-- 3 toto supergroup 1511 2017-05-29 23:50 /toto/LICENSE-ASM.txt drwxr-xr-x - toto supergroup 0 2017-05-29 23:53 /toto/hadoop [toto@hadoop learn]$
-moveToLocal 功能:从hdfs剪切粘贴到本地 示例:hadoop fs - moveToLocal /aaa/bbb/cc/dd /home/hadoop/a.txt |
--appendToFile 功能:追加一个文件到已经存在的文件末尾 示例:hadoop fs -appendToFile ./hello.txt hdfs://hadoop:9000/hello.txt 可以简写为: Hadoop fs -appendToFile ./hello.txt /hello.txt 实际案例: [toto@hadoop learn]$ hadoop fs -put text.txt /toto [toto@hadoop learn]$ hadoop fs -ls /toto Found 3 items -rw-r--r-- 3 toto supergroup 1511 2017-05-29 23:50 /toto/LICENSE-ASM.txt drwxr-xr-x - toto supergroup 0 2017-05-29 23:53 /toto/hadoop -rw-r--r-- 3 toto supergroup 0 2017-05-29 23:59 /toto/text.txt [toto@hadoop learn]$ cat hello.txt 示例:hadoop fs -appendToFile ./hello.txt hdfs://hadoop:9000/hello.txt 可以简写为: Hadoop fs -appendToFile ./hello.txt /hello.txt 将文件上传到hdfs [toto@hadoop learn]$ hadoop fs -appendToFile ./hello.txt hdfs://hadoop:9000/toto/text.txt 查看拼接到text.txt中的内容 [toto@hadoop learn]$ hadoop fs -cat /toto/text.txt 示例:hadoop fs -appendToFile ./hello.txt hdfs://hadoop:9000/hello.txt 可以简写为: Hadoop fs -appendToFile ./hello.txt /hello.txt [toto@hadoop learn]$ |
-cat 功能:显示文件内容 示例:hadoop fs -cat /hello.txt -tail 功能:显示一个文件的末尾 示例:hadoop fs -tail /weblog/access_log.1 实际案例: [toto@hadoop learn]$ hadoop fs -tail /toto/text.txt 示例:hadoop fs -appendToFile ./hello.txt hdfs://hadoop:9000/hello.txt 可以简写为: Hadoop fs -appendToFile ./hello.txt /hello.txt
[toto@hadoop learn]$
-text 功能:以字符形式打印一个文件的内容 示例:hadoop fs -text /weblog/access_log.1 实际案例: [toto@hadoop learn]$ hadoop fs -text /toto/text.txt 示例:hadoop fs -appendToFile ./hello.txt hdfs://hadoop:9000/hello.txt 可以简写为: Hadoop fs -appendToFile ./hello.txt /hello.txt [toto@hadoop learn]$ |
-chgrp -chmod -chown 功能:linux文件系统中的用法一样,对文件所属权限 示例: hadoop fs -chmod 666 /hello.txt hadoop fs -chown someuser:somegrp /hello.txt
实际案例: [toto@hadoop learn]$ hadoop fs -chmod 777 /toto/text.txt [toto@hadoop learn]$ hadoop fs -ls /toto/text.txt -rwxrwxrwx 3 toto supergroup 149 2017-05-30 00:01 /toto/text.txt [toto@hadoop learn]$ hadoop fs -chmod 666 /toto/text.txt [toto@hadoop learn]$ hadoop fs -ls /toto/text.txt -rw-rw-rw- 3 toto supergroup 149 2017-05-30 00:01 /toto/text.txt [toto@hadoop learn]$ |
-copyFromLocal 功能:从本地文件系统中拷贝文件到hdfs路径去 示例:hadoop fs -copyFromLocal ./jdk.tar.gz /aaa/
实际案例: [toto@hadoop learn]$ cat hello.txt 示例:hadoop fs -appendToFile ./hello.txt hdfs://hadoop:9000/hello.txt 可以简写为: Hadoop fs -appendToFile ./hello.txt /hello.txt
[toto@hadoop learn]$ hadoop fs -copyFromLocal ./hello.txt /toto2 [toto@hadoop learn]$ ls hello.txt text.txt [toto@hadoop learn]$ hadoop fs -ls /toto2 Found 1 items -rw-r--r-- 3 toto supergroup 149 2017-05-30 00:09 /toto2/hello.txt [toto@hadoop learn]$ -copyToLocal 功能:从hdfs拷贝到本地 示例:hadoop fs -copyToLocal /aaa/jdk.tar.gz 实际案例: [toto@hadoop learn]$ hadoop fs -ls / Found 6 items drwxr-xr-x - toto supergroup 0 2017-05-29 14:01 /findbugs-1.3.9 drwxr-xr-x - toto supergroup 0 2017-05-29 03:23 /hive drwx------ - toto supergroup 0 2017-05-29 14:47 /tmp drwxr-xr-x - toto supergroup 0 2017-05-29 23:59 /toto drwxr-xr-x - toto supergroup 0 2017-05-30 00:09 /toto2 drwxr-xr-x - toto supergroup 0 2017-05-29 23:36 /user [toto@hadoop learn]$ hadoop fs -copyToLocal /findbugs-1.3.9 ./ [toto@hadoop learn]$ ls findbugs-1.3.9 hello.txt text.txt [toto@hadoop learn]$ hadoop fs -ls / Found 6 items drwxr-xr-x - toto supergroup 0 2017-05-29 14:01 /findbugs-1.3.9 drwxr-xr-x - toto supergroup 0 2017-05-29 03:23 /hive drwx------ - toto supergroup 0 2017-05-29 14:47 /tmp drwxr-xr-x - toto supergroup 0 2017-05-29 23:59 /toto drwxr-xr-x - toto supergroup 0 2017-05-30 00:09 /toto2 drwxr-xr-x - toto supergroup 0 2017-05-29 23:36 /user [toto@hadoop learn]$ |
-cp 功能:从hdfs的一个路径拷贝hdfs的另一个路径 示例: hadoop fs -cp /aaa/jdk.tar.gz /bbb/jdk.tar.gz.2 Usage: hadoop fs [generic options] -cp [-f] [-p | -p[topax]] [-d] <src> ... <dst> [toto@hadoop learn]$ hadoop fs -cp -p /findbugs-1.3.9 /toto2 [toto@hadoop learn]$ hadoop fs -ls /toto2 Found 2 items drwxr-xr-x - toto supergroup 0 2017-05-29 14:01 /toto2/findbugs-1.3.9 -rw-r--r-- 3 toto supergroup 149 2017-05-30 00:09 /toto2/hello.txt [toto@hadoop learn]$ -mv 功能:在hdfs目录中移动文件 示例: hadoop fs -mv /aaa/jdk.tar.gz / 实际案例: [toto@hadoop learn]$ hadoop fs -ls /toto2 Found 2 items drwxr-xr-x - toto supergroup 0 2017-05-29 14:01 /toto2/findbugs-1.3.9 -rw-r--r-- 3 toto supergroup 149 2017-05-30 00:09 /toto2/hello.txt [toto@hadoop learn]$ hadoop fs -mv /toto/hello.txt /user mv: `/toto/hello.txt': No such file or directory [toto@hadoop learn]$ hadoop fs -mv /toto2/hello.txt /user [toto@hadoop learn]$ hadoop fs -ls /user Found 3 items drwxr-xr-x - toto supergroup 0 2017-05-29 23:36 /user/hadoop -rw-r--r-- 3 toto supergroup 149 2017-05-30 00:09 /user/hello.txt drwxr-xr-x - toto supergroup 0 2017-05-29 14:51 /user/toto [toto@hadoop learn]$ |
-get 功能:等同于copyToLocal,就是从hdfs下载文件到本地 示例:hadoop fs -get /aaa/jdk.tar.gz
功能:合并下载多个文件 示例:比getmerge 如hdfs的目录 /aaa/下有多个文件:log.1, log.2,log.3,... hadoop fs -getmerge /aaa/log.* ./log.sum |
-put 功能:等同于copyFromLocal 示例:hadoop fs -put /aaa/jdk.tar.gz /bbb/jdk.tar.gz.2 |
-rm 功能:删除文件或文件夹 示例:hadoop fs -rm -r /aaa/bbb/ 实际案例: -rmdir 功能:删除空目录 示例:hadoop fs -rmdir /aaa/bbb/ccc
删除非空文件夹时不让报错的命令: hadoop fs -rmdir --ignore-fail-on-non-empty /toto2/findbugs-1.3.9/lib |
-df 功能:统计文件系统的可用空间信息 示例:hadoop fs -df -h / [toto@hadoop learn]$ hdfs dfs -df -h / Filesystem Size Used Available Use% hdfs://hadoop:9000 134.4 G 472.4 M 97.8 G 0% -du 功能:统计文件夹的大小信息 示例: hadoop fs -du -s -h /aaa/* [toto@hadoop learn]$ hadoop fs -du -s -h /toto2 2.3 M /toto2 [toto@hadoop learn]$ |
-count 功能:统计一个指定目录下的文件节点数量 示例:hadoop fs -count /aaa/ |
-setrep 功能:设置hdfs中文件的副本数量 示例:hadoop fs -setrep 3 /aaa/jdk.tar.gz (这里的3) 实际命令: [toto@hadoop learn]$ hadoop fs -setrep 3 /toto2/findbugs-1.3.9 Replication 3 set: /toto2/findbugs-1.3.9/LICENSE-ASM.txt Replication 3 set: /toto2/findbugs-1.3.9/LICENSE-bcel.txt Replication 3 set: /toto2/findbugs-1.3.9/LICENSE-commons-lang.txt Replication 3 set: /toto2/findbugs-1.3.9/LICENSE-docbook.txt Replication 3 set: /toto2/findbugs-1.3.9/LICENSE-dom4j.txt Replication 3 set: /toto2/findbugs-1.3.9/LICENSE-jFormatString.txt Replication 3 set: /toto2/findbugs-1.3.9/LICENSE-jaxen.txt Replication 3 set: /toto2/findbugs-1.3.9/LICENSE-jcip.txt Replication 3 set: /toto2/findbugs-1.3.9/LICENSE-jdepend.txt Replication 3 set: /toto2/findbugs-1.3.9/LICENSE-jsr305.txt Replication 3 set: /toto2/findbugs-1.3.9/LICENSE-mysql-connector.txt Replication 3 set: /toto2/findbugs-1.3.9/LICENSE.txt |
HDFS命令行客户端使用,命令行客户端支持的命令参数,常用命令参数介绍相关推荐
- linux 查看权限命令行,【linux】与 用户、权限 有关的常用命令
查看信息 查看文件.文件夹的filesystem metadata # 查看**单个**文件.文件夹的权限信息 stat filename # 或者使用以下命令来查看当前目录下**所有**文件.文件夹 ...
- 《现代命令行工具指南》8. 备忘清单:让常用命令能够信手拈来 - navi
好工具就是生产力,这是专栏<现代命令行工具指南>精讲的第 8 个命令行工具,欢迎品鉴. 命令用完就忘怎么办?命令太复杂记不住怎么办? 用备忘录啊,把常用的.复杂的.记不住的命令记下来,以 ...
- JAVAWEB开发之——Linux命令实战、虚拟机和centos的安装以及联网、常用命令、vi编辑以及软件的安装、sftp的使用
Linux简介 Linux是一种自由和开放源码的操作系统,存放着许多不同的Linux版本,但他们都使用了Linux内核.Linux可安装在各种计算机硬件中 比如.手机.平板电脑.路由器.台式计算机中. ...
- Linux常用命令详解教程大全,Linux教程手册详解常用命令
一.基本命令 1.1 关机和重启 关机 shutdown -h now 立刻关机 shutdown -h 5 5分钟后关机 poweroff ...
- linux kvm虚拟化命令,Linux系统下kvm虚拟化(三)日常管理常用命令和配置说明
根据我们之前创建和一些操作可以知道,KVM虚拟机的管理主要是通过virsh命令对环境下kvm虚拟机进行管理,下边这里整理一些常用的配置说明以及如何进行日常管理维护. 1,查看KVM虚拟机配置文件 KV ...
- mysql命令4类_【Mysql】mysql数据库的一些常用命令
一.启动与退出 1.进入MySQL: 输入命令:mysql -u root -p 直接输入安装时的密码即可. 此时的提示符是:mysql> 2.退出MySQL:quit或exit 3.数据库清屏 ...
- linux命令grep和find怎么用,Linux下find和grep常用命令及区别介绍
在使用linux时,经常需要进行文件查找.其中查找的命令主要有find和grep.两个命令是有区别的. 区别: (1)find命令是根据文件的属性进行查找,如文件名,文件大小,所有者,所属组,是否为空 ...
- centos7杀掉进程_Centos常用命令,查看进程、杀死进程、启动进程等常用命令
1.查进程 ps命令查找与进程相关的PID号: ps a 显示现行终端机下的所有程序,包括其他用户的程序. ps -A 显示所有程序. ps c 列出程序时,显示每个程序真正的指令名称,而不包含路径, ...
- mysql root命令_设置更改root密码、连接mysql、mysql常用命令
目录 一.设置更改root密码 二.连接mysql 三.mysql常用命令 一.设置更改root密码 检查mysql服务是否启动 [root@minglinux-01 ~] ps aux |grep ...
最新文章
- web安全攻防演练网站 靶机 测试环境 收集
- hdu 2196(树的最长链)
- VUE v-bind绑定class和style
- ssm数据库异常问题
- Cheese 游戏编程:第 4 部分 (转自MSDN)
- 浅谈搜狗下拉词框优化推广的优势有哪些
- JavaScript 是如何工作的:WebRTC和对等网络的机制!
- Atitit 《摩奴法典》overivew 读后感 不是由国王 颁布的,而是 僧侣编制
- Java从入门到进阶书单推荐|必收藏
- 新唐N76E003AT20PIN对PIN完美替代STM8S003F3P6
- 几何画板椭圆九种画法_椭圆的画法几何画板的动画演示
- c语言一个数平方表示,C语言 - 利用 汇编思想 写一个数的平方
- 如何进行邮件营销,邮件营销群发是否有效?
- Elasticsearch辅助插件安装
- Asp.NET Core+ABP框架+IdentityServer4+MySQL+Ext JS之部署到Linux
- linux 系统业务迁移,记录一次linux系统迁移过程
- 2022年湖南省高职单招(综合素质)考试冲刺试题及答案
- java高并发程序设计1-线程停下来(stop,wait,suspend,await,interrupt,join,yield,sleep)的操作
- 数据库系统基础教程第三版 部分实验命令
- 百度Apollo简介
热门文章
- 史上最全 Python Re 模块讲解(三)
- Flask框架(flask-script扩展命令行和flask中数据库migrate扩展的使用)
- 粒子群算法求解旅行商问题
- MATLAB机器学习系列-3:BP神经网络算例实现
- python 实现文本自动翻译功能
- opengl加载显示3D模型gltf类型文件
- boost::phoenix模块使用 istreambuf_iterator 测试 lambda 函数对象
- boost::geometry::point_on_surface用法的测试程序
- boost::fibers::shared_future的用法实例
- GDCM:gdcm::CompositeNetworkFunctions的测试程序