1. 程式人生 > 其它 >hadoop 常用命令

hadoop 常用命令

1,hadoop fs -cat /shining/temp.txt.gz | zcat | head -1
hadoop fs -text /shining/temp.txt.gz | head -1
檢視gz檔案的第一行資料
參考資料:https://blog.csdn.net/java___boy/article/details/103178672
2,hadoop fs -stat hdfs://xx/xx
返回(目錄或者檔案)檔案的修改時間
3,hadoop fs -ls 是有檔案的詳細的資訊的

4,隨機返回指定行數的樣本資料
hadoop fs -cat /test/gonganbu/scene_analysis_suggestion/* | shuf -n 5

5,返回前幾行的樣本資料
hadoop fs -cat /test/gonganbu/scene_analysis_suggestion/* | head -100

6,返回最後幾行的樣本資料
hadoop fs -cat /test/gonganbu/scene_analysis_suggestion/* | tail -5

7,檢視文字行數
hadoop fs -cat hdfs://172.16.0.226:8020/test/sys_dict/sysdict_case_type.csv |wc -l

4-7的參考資料:https://blog.csdn.net/github_38358734/article/details/79272521

8,假設在你的hdfs叢集上有一個/user/hadoop/output目錄

裡面有作業執行的結果(多個檔案組成)part-000000,part-000001,part-000002

然後你想把所有的檔案合攏來一起看 可以使用命令:hadoop fs -getmerge /user/hadoop/output local_file(.gz)
hadoop fs -getmerge ${data_path}/${yesterday}/ data_${yesterday}.gz
可以合併為壓縮檔案

9,gunzip data_${yesterday}.gz 解壓檔案 解壓以後 data_${yesterday}.gz消失 生成後feature_data_${yesterday}檔案

10,檢視資料夾下 各個目錄的總大小:hdfs dfs -du -h
檢視資料夾下 各個目錄的總大小:hdfs dfs -du -s -h 目錄的總大小

11 刪除檔案 bin/hdfs dfs -rm output2/*
刪除資料夾 bin/hdfs dfs -rm -r output2

12 hadoop fs -get /user/hadoop/file localfile 獲取Hdfs檔案 /user/hadoop/file 為hdfs檔案 localfile為自己命名