Common shell commands for hadoop and hdfs

Common shell commands for hadoop and hdfs

 hdfs和hadoop命令在hdfs的使用上差不多,hadoop命令更全面一些,大体分为三类
 hadoop fs:适用于任何不同的文件系统,比如本地文件系统和HDFS文件系统
 hadoop dfs:只能适用于HDFS文件系统
 hdfs dfs:跟hadoop dfs的命令作用一样,也只能适用于HDFS文件系统 

1. File-related operations

1. Create a folder

hadoop  fs  -mkdir   [-p  (是否创建子目录,如果子目录未创建且没选择这个参数会报错)]

2. View the directory structure of the file

hdfs  dfs  -ls  -R /
hadoop  fs  -ls     /dir

3. Upload files from local to hdfs

hadoop  fs  -put  [-f (覆盖旧文件,不写则保留)]   /mydir  hdfs//:hdfs/dir

4. Download files from hdfs to local

hadoop fs -get hdfs//:hdfs/dir    /mydir
## 将hdfs的某个文件与本地的某个文件夹内容合并
hdfs dfs -getmerge hdfs//:hdfs/dir   /mydir  

5. Delete the hdfs file

hadoop fs -rm -r    hdfs//:hdfs/dir

6.hdfs file renaming

hdfs dfs -mv hdfs//:myfile   hdfs//:mydir

7. View the contents of the files in the folder

hadoop dfs -text hdfs//:mydir/f1.txt
hadoop dfs -cat  hdfs//:mydir/f1.txt

8. View the executable commands of hadoop

hadoop fs  
hadoop fs   -help

Guess you like

Origin blog.csdn.net/weixin_47387959/article/details/128519641