Hadoop Series (6)-- HDFS Common Shell commands
1. Show the current directory structure
# display the current directory structure hadoop fs-ls # Recursively display the current directory structure hadoop fs-ls-R # display the contents of the root directory hadoop fs-ls /
two。 Create a directory
# create directory hadoop fs-mkdir # Recursive create directory hadoop fs-mkdir-p
3. Delete operation
# delete file hadoop fs-rm # Recursive delete directory and file hadoop fs-rm-R
4. Load files locally to HDFS
# choose one of the two to execute hadoop fs-put [localsrc] [dst] hadoop fs-copyFromLocal [localsrc] [dst]
5. Export files from HDFS to local
# choose one of the two to execute hadoop fs-get [dst] [localsrc] hadoop fs-copyToLocal [dst] [localsrc]
6. View the contents of the file
# just choose one of the two to execute hadoop fs-text hadoop fs-cat
7. Show the last thousand bytes of the file
Hadoop fs-tail #, as under Linux, continuously listens for changes in the contents of the file and displays the last kilobyte of the file hadoop fs-tail-f
8. Copy a file
Hadoop fs-cp [src] [dst]
9. Move Fil
Hadoop fs-mv [src] [dst]
10. Count the file size under the current directory
Default unit byte-s: displays the sum of all file sizes,-h: will display the file size in a more friendly way (for example, 64.0m instead of 67108864) hadoop fs-du
11. Merge and download multiple files
-nl adds a newline character (LF) at the end of each file-skip-empty-file skips the empty file hadoop fs-getmerge# example the hbase-policy.xml and hbase-site.xml files on HDFS are merged and downloaded to the local / usr/test.xmlhadoop fs-getmerge-nl / test/hbase-policy.xml / test/hbase-site.xml / usr/test.xml
twelve。 Statistics of the free space information of the file system
Hadoop fs-df-h /
13. Change the file replication factor
Hadoop fs-setrep [- R] [- w] changes the replication factor of the file. If path is a directory, change the replication factor of all files under it-w: request command whether to wait for replication to complete # example hadoop fs-setrep-w 3 / user/hadoop/dir1
14. Authority control
# permission control is the same as on Linux. # change the group to which the file or directory belongs. The user must be the owner or superuser of the file. Hadoop fs-chgrp [- R] GROUP URI [URI.] # the access user to modify a file or directory must be the owner or superuser of the file. Hadoop fs-chmod [- R] URI [URI.] # the owner of the modification file must be a superuser. Hadoop fs-chown [- R] [OWNER] [: [GROUP]] URI [URI]
15. File detection
Hadoop fs-test-[defsz] URI
Optional options:
-d: returns 0 if the path is a directory. -e: returns 0 if the path exists. -f: returns 0 if the path is a file. -s: returns 0 if the path is not empty. -r: returns 0 if the path exists and read permission is granted. -w: returns 0 if the path exists and write permission is granted. -z: returns 0 if the file length is zero. # example hadoop fs-test-e filename
For more articles in big data's series, please see the GitHub Open Source Project: big data's getting started Guide.