BigData-1 HDFS Command

Part1

步骤3

ssh连接hadoop服务器

1
2
3
4
ssh master
ssh slave1
ssh slave2
ssh slave3

建议开启五个tab,最后一个是主机,不执行任何ssh命令

terminal开启更多tab

左上角file->open tab

步骤4

在master的tab中执行:

1
bash /scripts/hadoop/start-hadoop.sh

在主机tab中执行:

1
2
mkdir -p ~/Desktop/workspace/hdfs_op
cd ~/Desktop/workspace/hdfs_op

步骤5

如果需要创建多层目录,可以使用参数“-p”

主机tab:

查看目录列表

1
hadoop fs -ls /

创建目录

1
hadoop fs -mkdir /newDir

删除目录

1
hadoop fs -rm -r /newDir

步骤6

查看当前目录位置

1
pwd

创建hello.txt

1
echo "hello" > hello.txt

将文件放入数据库

1
hadoop fs -put hello.txt /newDir

查看数据库文件

1
hadoop fs -cat /newDir/hello.txt

从数据库下载文件hello_get.txt

1
hadoop fs -get /newDir/hello.txt hello_get.txt

本地查看文件

1
cat hello_get.txt

查看文件大小

上面这个是本地
下面这个是数据库

1
2
ls -l hello.txt
hadoop fs -du /newDir

复制文件

1
hadoop fs -cp /newDir/hello.txt /newDir/hello_cp.txt

移动文件

也可以用来重命名

1
hadoop fs -mv /newDir/hello.txt /newDir/hello_mv.txt

权限管理

1
hadoop fs -chmod 777 /newDir/hello_mv.txt

删除文件

1
hadoop fs -rm /newDir/hello_mv.txt

步骤7

查看文件系统信息

1
hadoop fs -df -h

步骤8 习题

均在master tab完成

1
2
3
4
5
6
7
8
9
hadoop fs -mkdir /mydir
echo "hello" > number.txt
hadoop fs -put number.txt /mydir
hadoop fs -ls /mydir
hadoop fs -cat /mydir/number.txt
hadoop fs -mv /mydir/number.txt /mydir/homework.txt
hadoop fs -ls /mydir
hadoop fs -chmod 600 /mydir/homework.txt
hadoop fs -ls /mydir

作业

Recommend References:
HDFS 07 - HDFS 性能调优之 合并小文件
Hadoop - getmerge Command
Merging small files into single file in hdfs

Part2

已实测希冀平台上所有程序均可运行。直接参考即可。

之后可能会更新HShell和作业提示。