操作hadoop的基本命令同操作Linux相同,前面加hadoop fs廷没,后面加cmd+參數(shù)即可糙麦。
hadoop hdfs 操作
hadoop fs -cmd <args>
#添加目錄和文件
hadoop fs -mkdir /test
hadoop fs -put example.txt .
hdfs dfs -mkdir /test
hdfs dfs -copyFromLocal ./NOTICE.txt /test
#hdfs為hadoop 2.X版本上的命令
#獲取/查看文件內(nèi)容
hadoop fs -get example.txt .
hadoop fs -cat example.txt
#刪除文件
hadoop fs -rm example.txt
#顯示目錄下有哪些文件
hadoop fs -ls /tmp/output
#查看hdfs狀態(tài)
hadoop dfs admin -report
#比如有哪些datanode歇攻,每個(gè)datanode的情況
#離開和進(jìn)入安全模式
hadoop dfsadmin -safemode leave
hadoop dfsadmin -safemode enter
hive 操作
將test1.txt文件中內(nèi)容存入hive中
1 shandong
2 changchun
3 shanghai
4 beijing
5 shenzhen
6 guangzhou
#建表
create table qingqian (id int,name string) ROW FORMAT DELIMITED FIELDS TERMINATED BY ' ' STORED AS TEXTFILE;
#導(dǎo)入數(shù)據(jù)
load data local inpath '/home/hadoop/test/01/test1.txt' into table qingqian;
#查數(shù)據(jù)
select * from qingqian;
#刪除數(shù)據(jù)
drop table qingqian;
#將數(shù)據(jù)導(dǎo)出
hive -e "select * from qingqian" >> local/qingqian.txt
#查建表語句
show create table qingqian;
#修改表中字段名
alter table qingqian CHANGE name new_name string;
hbase 操作
#建表
create 'qingqian','info';
#查表
describe 'qingqian';
#往表中寫數(shù)據(jù)
put 'qingqian','qingqian2','info:birthday','1987-6-17';
put 'qingqian','qingqian2','info:age','24';
#獲取表中數(shù)據(jù)某個(gè)數(shù)據(jù)
get 'qingqian','qingqian2';
#查表所有數(shù)據(jù)
scan 'qingqian'
#讓表失效
disable 'qingqian'
#查所有的表
list