1、hadoop fs
hadoop fs = hdfs dfs
2、ls命令
1.hadoop fs -ls / 显示hdfs根目录下目录和文件
[hadoop@hadoop000 ~]$ hadoop fs -ls /
Found 2 items
drwx—— – hadoop supergroup 0 2018-05-19 14:22 /tmp
drwxr-xr-x – hadoop supergroup 0 2018-05-19 14:22 /user
2.hadoop fs -lsr 相当于ls -R 显示 hdfs文件系统所有的目录和文件
[hadoop@hadoop000 ~]$ hadoop fs -lsr lsr: DEPRECATED: Please use ‘ls -R’ instead.
drwxr-xr-x – hadoop supergroup 0 2018-05-19 14:22 QuasiMonteCarlo_1526710955993_2062466309
drwxr-xr-x – hadoop supergroup 0 2018-05-19 14:22 QuasiMonteCarlo_1526710955993_2062466309/in
-rw-r–r– 1 hadoop supergroup 118 2018-05-19 14:22 QuasiMonteCarlo_1526710955993_2062466309/in/part0
-rw-r–r– 1 hadoop supergroup 118 2018-05-19 14:22 QuasiMonteCarlo_1526710955993_2062466309/in/part1
-rw-r–r– 1 hadoop supergroup 118 2018-05-19 14:22 QuasiMonteCarlo_1526710955993_2062466309/in/part2
-rw-r–r– 1 hadoop supergroup 118 2018-05-19 14:22 QuasiMonteCarlo_1526710955993_2062466309/in/part3
-rw-r–r– 1 hadoop supergroup 118 2018-05-19 14:22 QuasiMonteCarlo_1526710955993_2062466309/in/part4
drwxr-xr-x – hadoop supergroup 0 2018-05-19 14:22 QuasiMonteCarlo_1526710955993_2062466309/out
drwxr-xr-x – hadoop supergroup 0 2018-05-19 14:22 QuasiMonteCarlo_1526710955993_2062466309/out/_temporary
drwxr-xr-x – hadoop supergroup 0 2018-05-19 14:22 QuasiMonteCarlo_1526710955993_2062466309/out/_temporary/1
3、mkdir 创建文件夹
hadoop fs -mkdir -p /test/test01 -p同linux
[hadoop@hadoop000 ~]$ hadoop fs -mkdir -p /test/test01
[hadoop@hadoop000 ~]$ hadoop fs -ls /
Found 3 items
drwxr-xr-x – hadoop supergroup 0 2018-05-26 12:27 /test
drwx—— – hadoop supergroup 0 2018-05-19 14:22 /tmp
drwxr-xr-x – hadoop supergroup 0 2018-05-19 14:22 /user
创建空文件:touchz
[hadoop@hadoop000 ~]$ hadoop fs -touchz /test/1
[hadoop@hadoop000 ~]$ hadoop fs -ls /test/
Found 2 items
-rw-r–r– 1 hadoop supergroup 0 2018-05-26 13:11 /test/1
drwxr-xr-x – hadoop supergroup 0 2018-05-26 12:27 /test/test01
4、rm 删除文件或文件夹
删除文件:hadoop fs -rm xxx
删除文件夹:hadoop fs -rm -r xxx
[hadoop@hadoop000 ~]$ hadoop fs -rm -r /test
Deleted /test
[hadoop@hadoop000 ~]$ hadoop fs -ls /
Found 2 items
drwx—— – hadoop supergroup 0 2018-05-19 14:22 /tmp
drwxr-xr-x – hadoop supergroup 0 2018-05-19 14:22 /user
5、put 从本地系统拷贝文件到DFS
hadoop fs -put 本地目录 dfs目录
[hadoop@hadoop000 ~]$ hadoop fs -put today.log /test
[hadoop@hadoop000 ~]$ hadoop fs -ls /test
Found 1 items
-rw-r–r– 1 hadoop supergroup 28 2018-05-26 16:33 /test/today.log
6、get 将文件从dfs拷贝到本地
[hadoop@hadoop000 ~]$ hadoop fs -get /test/today.log /home/hadoop/
get: `/home/hadoop/today.log’: File exists
[hadoop@hadoop000 ~]$ ls
today.log
7、cp 、mv
同linux
8、text 通过文本格式输出
[hadoop@hadoop000 ~]$ hadoop fs -text /test/today.log
today is satday 20180526
9、copyFromLocal
hadoop fs -copyFromLocal 本地目录 源目录 与hadoopfs-put功能类似
10、moveFromLocal
hadoop fs -moveFromLocal 本地目录 源目录 将本地文件上传到hdfs,同时删除本地文件
11、hdfs dfsadmin -report
查看文件系统的基本信息和统计信息
[hadoop@hadoop000 ~]$ hdfs dfsadmin -report
Configured Capacity: 40028807168 (37.28 GB)
Present Capacity: 24105639936 (22.45 GB)
DFS Remaining: 24100990976 (22.45 GB)
DFS Used: 4648960 (4.43 MB)
DFS Used%: 0.02%
Under replicated blocks: 2
Blocks with corrupt replicas: 0
Missing blocks: 0
Missing blocks (with replication factor 1): 0
Pending deletion blocks: 0
————————————————-
Live datanodes (1):
Name: 192.168.137.130:50010 (hadoop000)
Hostname: hadoop000
Decommission Status : Normal
Configured Capacity: 40028807168 (37.28 GB)
DFS Used: 4648960 (4.43 MB)
Non DFS Used: 13889822720 (12.94 GB)
DFS Remaining: 24100990976 (22.45 GB)
DFS Used%: 0.01%
DFS Remaining%: 60.21%
Configured Cache Capacity: 0 (0 B)
Cache Used: 0 (0 B)
Cache Remaining: 0 (0 B)
Cache Used%: 100.00%
Cache Remaining%: 0.00%
Xceivers: 1
Last contact: Sat May 26 19:03:25 CST 2018
12、hdfs dfsadmin -safemode (enter | leave | get | wait)
安全模式。安全模式是NameNode的一种状态,在这种状态下,NameNode不接受对名字空间的更改(只读);不复制或删除块。NameNode在启动时自动进入安全模式,当配置块的最小百分数满足最小副本数的条件时,会自动离开安全模式。enter是进入,leave是离开,get是获取安全模式, wait是等待,一直到安全模式结束 。
13、hadoop fsck
hadoop fsck / 用这个命令可以检查整个文件系统的健康状况,但是要注意它不会主动恢复备份缺失的block,这个是由NameNode单独的线程异步处理的。
[hadoop@hadoop000 ~]$ hadoop fsck /
DEPRECATED: Use of this script to execute hdfs command is deprecated.
Instead use the hdfs command for it.
Connecting to namenode via http://hadoop000:50070/fsck?ugi=hadoop&path=%2F
FSCK started by hadoop (auth:SIMPLE) from /192.168.137.130 for path / at Sat May 26 19:11:32 CST 2018
..
/tmp/hadoop-yarn/staging/hadoop/.staging/job_1526708033902_0001/job.jar: Under replicated BP-1901544236-192.168.137.130-1526705500540:blk_1073741830_1006. Target Replicas is 10 but found 1 live replica(s), 0 decommissioned replica(s) and 0 decommissioning replica(s).
.
/tmp/hadoop-yarn/staging/hadoop/.staging/job_1526708033902_0001/job.split: Under replicated BP-1901544236-192.168.137.130-1526705500540:blk_1073741831_1007. Target Replicas is 10 but found 1 live replica(s), 0 decommissioned replica(s) and 0 decommissioning replica(s).
……………….Status: HEALTHY
Total size: 4390559 B
Total dirs: 18
Total files: 22
Total symlinks: 0
Total blocks (validated): 22 (avg. block size 199570 B)
Minimally replicated blocks: 22 (100.0 %)
Over-replicated blocks: 0 (0.0 %)
Under-replicated blocks: 2 (9.090909 %)
Mis-replicated blocks: 0 (0.0 %)
Default replication factor: 1
Average block replication: 1.0
Corrupt blocks: 0
Missing replicas: 18 (45.0 %)
Number of data-nodes: 1
Number of racks: 1
FSCK ended at Sat May 26 19:11:33 CST 2018 in 8 milliseconds