Shell operation of HDFS
1. Grammar introduction
1.1 General syntax
hdfs dfs [选项]
1.2 Create a folder
hdfs dfs -mkdir [-p]<paths>
1.3 List files and directories
[-d] Return to path
[-h] Human-readble display size (human-readble)
[-R] Cascading display of directories under path
hdfs dfs -ls [-d][-h][-R]<paths>
Show cascading directory
hdfs dfs -ls -R <paths>
1.4 New file
hdfs dfs -touchz<paths>
1.5 Upload files to HDFS
hdfs dfs -put [-f][-p]<localsrc> <dst>
hdfs dfs -copyFromLocal [-f][-p][-l]<localsrc> <dst>
1.6 Move local files to HDFS
This command copies the file to HDFS, and the local file is deleted
hdfs dfs -moveFromLocal <localsrc> <dst>
1.7 Download files
hdfs dfs -get [-p]<src> <localdst>
hdfs dfs -copyToLocal [-p]<src> <localdst>
1.8 View files
[-ignoreCrc] Ignore the files that failed the loop check
[-f] Dynamically update the display data
hdfs dfs -cat/text[-ignoreCrc] <src>
hdfs dfs -tail [-f]<file>
1.9 Chase files
hdfs dfs -appendToFile <localsrc> <dst>
1.10 Delete directory or file
hdfs dfs -rm [-f][-r/R] <src>
1.11 Display the amount of disk space occupied
[-s] Display the total size of files in the specified directory
[-h] Human-readble display (human-readble)
hdfs dfs -du [-s][-h] <path>
1.12 HDFS file copy
hdfs dfs -cp [-f][-p] <src> <dst>
1.23 HDFS file movement (renaming)
hdfs dfs -mv [src] [dst]
1.24 HDFS file merge download
hdfs dfs -getmerge [src] [dst]
1.25 HDFS statistics
Count the number of subdirectories, the number of files and the file size under the directory. The
first number indicates the directory (when the directory is empty, count the directory'.'), the second number indicates the number of files, and the third number indicates the file size.
hdfs dfs -count
1.26 Extended commands
hdfs dfs -setfattr {-n name [-v value]}
hdfs dfs -getfattr {-n name | -d}
1.27 Management commands
hdfs dfsadmin [参数]
Report basic information and statistics of the file system
hdfs dfsadmin -report
View topology
hdfs dfsadmin -printTopology
2.HDFS advanced features
2.1 Safe Mode
View current status
hdfs dfsadmin -safemode get
Enter safe mode
hdfs dfsadmin -safemode enter
Leave safe mode
hdfs dfsadmin -safemode leave
Wait for the end of safe mode
hdfs dfsadmin -safemode wait