The following commands need to be executed in the bin directory under the hadoop installation directory. For example, if my installation path is /home/hduser/hadoop, then execute in the /home/hduser/hadoop/bin directory.
Script to execute the command: hadoop directory/bin/hadoop
Syntax: hadoop fs
1. -help: display help information
hadoop fs -help rm
2. -ls: Display directory information
hadoop fs -ls /
3. -mkdir: Create a directory on HDFS
hadoop fs -mkdir -p /user/ysir
4. -moveFromLocal: Cut and paste from local to HDFS
hadoop fs -moveFromLocal ~/test.txt /home/ysir/
5. -appendToFile: append a file to the end of an existing file
hadoop fs -appendToFile /a.txt /b.txt
6. -cat: display file content
hadoop fs -cat /user/ysir/a.txt
7. -chmod, -chown: modify file permissions, owner
hadoop fs -chmod 777 /a.txt
hadoop fs -chown admin:ysir /a.txt
8. -copyFromLocal: Copy files from the local file system to HDFS
hadoop fs -copyFromLocal a.txt /
9. copyToLocal: copy from HDFS to local
hadoop fs -copyToLocal /a.txt ~/
10. -cp: Copy files in HDFS
hadoop fs -cp /aaa/a.txt /bbb/
11. -mv: Move files in the HDFS directory
hadoop fs -mv /aaa/a.txt /bbb/
12. -get: copy from HDFS to local, equivalent to copyToLocal
hadoop fs -get /aaa/a.txt
13. -getmerge: merge and download multiple files
hadoop fs -getmerge /logs/* ~/logs.log #Merge
and download all files under the /logs/ path on HDFS to the local ~/logs.log file
14. -put: upload local files to HDFS, which is equivalent to copyFromLocal
hadoop fs -put ~/a.txt /
15. -tail: display the content at the end of the file
hadoop fs -tail /a.txt
16. -rm: delete a folder or file
hadoop fs -rm /user/ysir/a.txt
17. -rmdir: delete empty directories
hadoop fs -mkdir /temp
18. -du: Statistics folder size information
hadoop fs -du -s -h /temp
19. -setrep: Set the number of copies in the HDFS file
hadoop fs -setrep 5 /a.txt