hadoop fs -mkdir -p /wordcount/input 和 hdfs dfs -mkdir -p /wordcount/input 是什么区别
时间: 2024-04-09 08:29:46 浏览: 35
`hadoop fs -mkdir -p /wordcount/input` 和 `hdfs dfs -mkdir -p /wordcount/input` 都是用于在 Hadoop 分布式文件系统(HDFS)中创建目录的命令,但稍有不同。
`hadoop fs -mkdir -p /wordcount/input` 是旧版本的 Hadoop 命令,用于创建 HDFS 目录。它在较新版本的 Hadoop 中仍然可用,但已被推荐使用 `hdfs dfs` 命令替代。
`hdfs dfs -mkdir -p /wordcount/input` 是新版本的 Hadoop 命令,用于创建 HDFS 目录。它是 Hadoop 2.x 版本以及更高版本中推荐使用的命令。
两个命令的功能是相同的,都会递归创建 `/wordcount/input` 目录(如果不存在的话)。其中 `-p` 参数表示递归创建目录,如果父目录不存在也会被创建。
总结起来,`hadoop fs -mkdir -p` 和 `hdfs dfs -mkdir -p` 的区别仅在于命令的语法和推荐使用版本的不同。在较新的 Hadoop 版本中,建议使用 `hdfs dfs` 命令。
相关问题
(2)在spark-shell中读取HDFS系统文件“/user/hadoop/20230516.txt”(如果该文件不存在,请先创建),然后,统计出文件的行数;
首先需要在HDFS上创建一个文件,可以使用以下命令:
```
hdfs dfs -mkdir /user/hadoop/
hdfs dfs -put local_file_path /user/hadoop/20230516.txt
```
其中,`local_file_path`是本地文件路径。
然后,在`spark-shell`中,可以使用以下命令读取文件并统计行数:
```
val fileRDD = sc.textFile("/user/hadoop/20230516.txt")
val count = fileRDD.count()
println("文件行数:" + count)
```
其中,`sc`是SparkContext对象,如果没有创建可以使用以下命令:
```
val conf = new SparkConf().setAppName("WordCount").setMaster("local")
val sc = new SparkContext(conf)
```
这里假设使用本地模式,如果要在集群上运行,需要将`setMaster`参数设置为对应的值。
46、 按要求写出以下操作命令(10分) (1)获取shell命令的帮助信息 (2)在HDFS上查看目录 (3)在HDFS上创建新目录/mydata/wordexample (4)将本地文件word.txt上传到HDFS的目录/mydata/wordexample中。 (5)将HDFS的目录/mydata/wordexample中的文件复制上HDFS的目录/example中 (6)将HDFS上的文件拷贝到hadoop用户家目录中 (7)查看HDFS上的word.txt文件内容 (8)在HDFS上删除目录/mydata/wordexample (9)对HDFS上的/example目录中的文件进行词频统计。 (10)查看步骤(9)词频统计结果。
(1)获取shell命令的帮助信息:
```
man [command]
```
(2)在HDFS上查看目录:
```
hadoop fs -ls [directory]
```
(3)在HDFS上创建新目录/mydata/wordexample:
```
hadoop fs -mkdir /mydata/wordexample
```
(4)将本地文件word.txt上传到HDFS的目录/mydata/wordexample中:
```
hadoop fs -put word.txt /mydata/wordexample/
```
(5)将HDFS的目录/mydata/wordexample中的文件复制上HDFS的目录/example中:
```
hadoop fs -cp /mydata/wordexample/* /example/
```
(6)将HDFS上的文件拷贝到hadoop用户家目录中:
```
hadoop fs -get /mydata/wordexample/word.txt ~/
```
(7)查看HDFS上的word.txt文件内容:
```
hadoop fs -cat /mydata/wordexample/word.txt
```
(8)在HDFS上删除目录/mydata/wordexample:
```
hadoop fs -rm -r /mydata/wordexample
```
(9)对HDFS上的/example目录中的文件进行词频统计:
```
hadoop jar /path/to/hadoop-streaming.jar -input /example/* -output /example/output -mapper "cat" -reducer "python /path/to/wordcount.py"
```
(10)查看步骤(9)词频统计结果:
```
hadoop fs -cat /example/output/part-00000
```