root@master:~# hadoop fs -ls /
hadoop: command not found //如果出现这种情况说明环境变量没有配置,执行一下操作
root@master:~# gedit .bashrc //会弹出编辑框,然后添加如下文字
export HADOOP_HOME=/opt/hadoop-2.9.2
export PATH=${JAVA_HOME}/bin:$PATH
export PATH=${HADOOP_HOME}/bin:/opt/hadoop-2.9.2/sbin:$PATH
//save保存
root@master:~# source .bashrc //重新加载文件(这一步必不可少)
root@master:~# hadoop fs -mkdir /test1 /test2 //同时创建两个文件,test1,test2
root@master:~# hadoop fs -ls / //查看HDFS当前路径
Found 2 items
drwxr-xr-x - root supergroup 0 2021-11-20 20:31 /test1
drwxr-xr-x - root supergroup 0 2021-11-20 20:31 /test2
root@master:~# hadoop fs -mkdir -p /x/y/x //创建目录/x/y/x
root@master:~# hadoop fs -lsr /x //查看x下面的目录
lsr: DEPRECATED: Please use 'ls -R' instead.
drwxr-xr-x - root supergroup 0 2021-11-20 20:32 /x/y
drwxr-xr-x - root supergroup 0 2021-11-20 20:32 /x/y/x
root@master:~# hadoop fs -mkdir file:/home/hadoop/x //hdfs下创建本地路径/home/hadoop/x
root@master:~# hadoop fs -lsr /x // 查看x下的路径
lsr: DEPRECATED: Please use 'ls -R' instead.
drwxr-xr-x - root supergroup 0 2021-11-20 20:32 /x/y
drwxr-xr-x - root supergroup 0 2021-11-20 20:32 /x/y/x
root@master:~# hadoop fs -ls /
Found 3 items
drwxr-xr-x - root supergroup 0 2021-11-20 20:31 /test1
drwxr-xr-x - root supergroup 0 2021-11-20 20:31 /test2
drwxr-xr-x - root supergroup 0 2021-11-20 20:32 /x
root@master:~# ls
Desktop Documents Downloads Music Pictures Public Templates Videos
root@master:~# cd
root@master:~# ls
Desktop Documents Downloads Music Pictures Public Templates Videos
root@master:~# cd
root@master:~# cd ..
root@master:/# ls
bin dev initrd.img lib64 mnt root snap tmp vmlinuz
boot etc initrd.img.old lost+found opt run srv usr vmlinuz.old
cdrom home lib media proc sbin sys var
root@master:/# cd home
root@master:/home# ls
hadoop
root@master:/home# hadoop fs -touchz /test1/abc.txt
root@master:/home# hadoop fs -ls /test1
Found 1 items
-rw-r--r-- 3 root supergroup 0 2021-11-20 20:38 /test1/abc.txt
root@master:/home# echo "hello world" >> file1
root@master:/home# echo "hello old luo" >> file2
root@master:/home# ls
file1 file2 hadoop
root@master:/home# hadoop fs -appendToFile file1 file2 /test1/abc.txt
root@master:/home# hadoop fs -ls /test1/abc.txt
-rw-r--r-- 3 root supergroup 26 2021-11-20 20:42 /test1/abc.txt
root@master:/home# hadoop fs -cat /test1/abc.txt
hello world
hello old luo
root@master:/home# hadoop fs -cp file:/home/hadoop/file1 /x
cp: `file:/home/hadoop/file1': No such file or directory
root@master:/home# cp file1 /home/hadoop
root@master:/home# ls
file1 file2 hadoop
root@master:/home# cd hadoop
root@master:/home/hadoop# ls
Desktop Downloads file1 Pictures Templates x
Documents examples.desktop Music Public Videos
root@master:/home/hadoop# hadoop fs -cp file:/home/hadoop/file1 /x
root@master:/home/hadoop# hadoop fs -lsr /x
lsr: DEPRECATED: Please use 'ls -R' instead.
-rw-r--r-- 3 root supergroup 12 2021-11-20 20:50 /x/file1
drwxr-xr-x - root supergroup 0 2021-11-20 20:32 /x/y
drwxr-xr-x - root supergroup 0 2021-11-20 20:32 /x/y/x
root@master:/home/hadoop# hadoop fs -cp -p -f file:/home/hadoop/file1 /x
root@master:/home/hadoop# hadoop fs -mv /x/file1 /x/file1.txt
root@master:/home/hadoop# hadoop fs -lsr /x
lsr: DEPRECATED: Please use 'ls -R' instead.
-rw-r--r-- 3 root root 12 2021-11-20 20:49 /x/file1.txt
drwxr-xr-x - root supergroup 0 2021-11-20 20:32 /x/y
drwxr-xr-x - root supergroup 0 2021-11-20 20:32 /x/y/x
root@master:/home/hadoop# hadoop fs -lsr /text
lsr: DEPRECATED: Please use 'ls -R' instead.
lsr: `/text': No such file or directory
root@master:/home/hadoop# hadoop fs -lsr /text1
lsr: DEPRECATED: Please use 'ls -R' instead.
lsr: `/text1': No such file or directory
root@master:/home/hadoop# cd ..
root@master:/home# ls
file1 file2 hadoop
root@master:/home# cd ..
root@master:/# ls
bin dev initrd.img lib64 mnt root snap tmp vmlinuz
boot etc initrd.img.old lost+found opt run srv usr vmlinuz.old
cdrom home lib media proc sbin sys var
root@master:/# hadoop fs -ls /
Found 3 items
drwxr-xr-x - root supergroup 0 2021-11-20 20:38 /test1
drwxr-xr-x - root supergroup 0 2021-11-20 20:31 /test2
drwxr-xr-x - root supergroup 0 2021-11-20 20:54 /x
root@master:/# hadoop fs -ls /test1
Found 1 items
-rw-r--r-- 3 root supergroup 26 2021-11-20 20:42 /test1/abc.txt
root@master:/# hadoop fs -mv /test1 /x/y
root@master:/# hadoop fs -ls /x
Found 2 items
-rw-r--r-- 3 root root 12 2021-11-20 20:49 /x/file1.txt
drwxr-xr-x - root supergroup 0 2021-11-20 20:58 /x/y
root@master:/# cd /x
bash: cd: /x: No such file or directory
root@master:/# cd x
bash: cd: x: No such file or directory
root@master:/# hadoop fs -ls x
ls: `x': No such file or directory
root@master:/# hadoop fs -ls /x
Found 2 items
-rw-r--r-- 3 root root 12 2021-11-20 20:49 /x/file1.txt
drwxr-xr-x - root supergroup 0 2021-11-20 20:58 /x/y
root@master:/# hadoop fs -ls /x/y
Found 2 items