hdfs文件的操作常用命令

在hdfs目录中,创建/test目录
[root@Master current]# hadoop fs -mkdir /test
查看ls命令
[root@Master current]# hadoop fs -ls /test
在本地生成一个文件
[root@Master dfs]# ifconfig >> /1.txt
将本地文件复制到hdfs的/test(等价于copyFromLocal)
[root@Master dfs]# hadoop fs -put /1.txt /test  

查看hdfs下的/test下是否有1.txt文件
[root@Master dfs]# hadoop fs -ls /test
-rw-r--r--   3 root supergroup        961 2016-03-27 19:11 /test/1.txt

将hdfs下的/test目录下的文件复制到2.txt下(等价于copyToLocal)
[root@Master current]# hadoop fs -get /test/1.txt /2.txt

清空回收站
[root@Master current]# hadoop fs -expunge
16/03/27 19:32:51 INFO fs.TrashPolicyDefault: Namenode trash configuration: Deletion interval = 0 minutes, Emptier interval = 0 minutes.

查看hdfs下文件的大小
[root@Master current]# hadoop fs -dus /test/1.txt
961  /test/1.txt

将2.txt文件上传到/test下
[root@Master current]# hadoop fs -put /2.txt /test

查看是否上传成功
[root@Master current]# hadoop fs -ls /test
Found 2 items
-rw-r--r--   3 root supergroup        961 2016-03-27 19:11 /test/1.txt
-rw-r--r--   3 root supergroup        961 2016-03-27 19:38 /test/2.txt
[root@Master current]#

验证/test下的文件的大小
[root@Master current]# hadoop fs -du /test
961  /test/1.txt
961  /test/2.txt

复制文件
[root@Master current]# hadoop fs -cp /test/1.txt /test/3.txt
验证复制成功
[root@Master current]# hadoop fs -ls /test
Found 3 items
-rw-r--r--   3 root supergroup        961 2016-03-27 19:11 /test/1.txt
-rw-r--r--   3 root supergroup        961 2016-03-27 19:38 /test/2.txt
-rw-r--r--   3 root supergroup        961 2016-03-27 19:42 /test/3.txt
[root@Master current]#

查看文件的内容
[root@Master current]# hadoop fs -cat /test/1.txt
Java HotSpot(TM) Server VM warning: You have loaded library
eth0      Link encap:Ethernet  HWaddr 00:0C:29:D0:F1:C7  
          inet addr:10.114.51.132  Bcast:10.114.51.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fed0:f1c7/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1600321 errors:3 dropped:3 overruns:0 frame:0
          TX packets:1222043 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:799233372 (762.2 MiB)  TX bytes:1029831155 (982.1 MiB)
          Interrupt:19 Base address:0x2000

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:53162 errors:0 dropped:0 overruns:0 frame:0
          TX packets:53162 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:5155687 (4.9 MiB)  TX bytes:5155687 (4.9 MiB)

[root@Master current]#
创建一个二级目录
[root@Master current]# hadoop fs -mkdir /test/2016/
查看/test目录
[root@Master current]# hadoop fs -lsr /test
-rw-r--r--   3 root supergroup        961 2016-03-27 19:11 /test/1.txt
-rw-r--r--   3 root supergroup        961 2016-03-27 19:38 /test/2.txt
drwxr-xr-x   - root supergroup          0 2016-03-27 19:47 /test/2016
-rw-r--r--   3 root supergroup        961 2016-03-27 19:42 /test/3.txt
复制1.txt到/test/2016/目录下
[root@Master current]# hadoop fs -cp /test/1.txt /test/2016/
递归列举
[root@Master current]# hadoop fs -lsr /test                 
-rw-r--r--   3 root supergroup        961 2016-03-27 19:11 /test/1.txt
-rw-r--r--   3 root supergroup        961 2016-03-27 19:38 /test/2.txt
drwxr-xr-x   - root supergroup          0 2016-03-27 19:48 /test/2016
-rw-r--r--   3 root supergroup        961 2016-03-27 19:48 /test/2016/1.txt
-rw-r--r--   3 root supergroup        961 2016-03-27 19:42 /test/3.txt
[root@Master current]#


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值