HDFS fs命令

启动hadoop

[root@centos local]# start-all.sh
 查看进程
[root@centos local]# jps
3310 JobTracker
3008 NameNode
3120 DataNode
3471 TaskTracker
3230 SecondaryNameNode
3562 Jps
 hdfs命令都是以hadoop fs开头的,-ls表示查看hdfs目录,hdfs://centos:9000/是配置文件core-site.xml中所配置的地址,“/“表示根路径
[root@centos local]# hadoop fs -ls hdfs://centos:9000/
Warning: $HADOOP_HOME is deprecated.

Found 1 items
drwxr-xr-x   - root supergroup          0 2015-05-19 11:08 /usr
更简单的查询方式是省略路径,会通过core-site.xml自行查找hdfs路径
root@centos /]# hadoop fs -ls /
递归查看文件目录结构
[root@centos /]# hadoop fs -lsr hdfs://centos:9000/
arning: $HADOOP_HOME is deprecated.

drwxr-xr-x   - root supergroup          0 2015-05-19 11:08 /usr
drwxr-xr-x   - root supergroup          0 2015-05-19 11:08 /usr/local
drwxr-xr-x   - root supergroup          0 2015-05-19 11:08 /usr/local/hadoop
drwxr-xr-x   - root supergroup          0 2015-05-19 11:08 /usr/local/hadoop/tmp
drwxr-xr-x   - root supergroup          0 2015-05-20 04:18 /usr/local/hadoop/tmp/mapred
drwx------   - root supergroup          0 2015-05-20 04:18 /usr/local/hadoop/tmp/mapred/system
-rw-------   1 root supergroup          4 2015-05-20 04:18 /usr/local/hadoop/tmp/mapred/system/jobtracker.info
 创建一个文件夹,名称为file1
[root@centos /]# hadoop fs -mkdir /file1
Warning: $HADOOP_HOME is deprecated.

[root@centos /]# hadoop fs -ls /
Warning: $HADOOP_HOME is deprecated.
Found 2 items
drwxr-xr-x   - root supergroup          0 2015-05-20 04:48 /file1
drwxr-xr-x   - root supergroup          0 2015-05-19 11:08 /us
 上传文件,使用-put <源文件> <目标路径>
[root@centos /]# hadoop fs -put /usr/local/hadoop-1.1.2/conf/core-site.xml /file1
[root@centos /]# hadoop fs -ls /file1
Warning: $HADOOP_HOME is deprecated.
Found 1 items
-rw-r--r--   1 root supergroup        409 2015-05-20 04:54 /file1/core-site.xml
 下载文件,使用-get <源文件> <目标路径>
[root@centos /]# hadoop fs -get /file1/core-site.xml /root/Desktop
Warning: $HADOOP_HOME is deprecated.
 查看文件内容
[root@centos /]# hadoop fs -text /file1/core-site.xml
Warning: $HADOOP_HOME is deprecated.
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>

<!-- Put site-specific property overrides in this file. -->

<configuration>
    <property>
        <name>fs.default.name</name>
        <value>hdfs://192.168.56.101:9000</value>
    </property>
    <property>
        <name>hadoop.tmp.dir</name>
        <value>/usr/local/hadoop/tmp</value>
    </property>
</configuration>
 删除文件,-rm只能删文件,不能删目录,递归删除-rmr
[root@centos /]# hadoop fs -rm/file1/core-site.xml
[root@centos /]# hadoop fs -rmr/file1 
 命令帮助,查看ls命令
[root@centos /]# hadoop fs -help ls
Warning: $HADOOP_HOME is deprecated.

-ls <path>:     List the contents that match the specified file pattern. If
                path is not specified, the contents of /user/<currentUser>
                will be listed. Directory entries are of the form
                        dirName (full path) <dir>
                and file entries are of the form
                        fileName(full path) <r n> size
                where n is the number of replicas specified for the file
                and size is the size of the file, in bytes.
  总结
-help [cmd]	//显示命令的帮助信息
-ls(r) <path>	//显示当前目录下所有文件
-du(s) <path>	//显示目录中所有文件大小
-count[-q] <path>	//显示目录中文件数量
-mv <src> <dst>	//移动多个文件到目标目录
-cp <src> <dst>	//复制多个文件到目标目录
-rm(r)		//删除文件(夹)
-put <localsrc> <dst>	//本地文件复制到hdfs
-copyFromLocal	//同put
-moveFromLocal	//从本地文件移动到hdfs
-get [-ignoreCrc] <src> <localdst>	//复制文件到本地,可以忽略crc校验
-getmerge <src> <localdst>		//将源目录中的所有文件排序合并到一个文件中
-cat <src>	//在终端显示文件内容
-text <src>	//在终端显示文件内容
-copyToLocal [-ignoreCrc] <src> <localdst>	//复制到本地
-moveToLocal <src> <localdst>
-mkdir <path>	//创建文件夹
-touchz <path>	//创建一个空文件
         

猜你喜欢

转载自mvplee.iteye.com/blog/2212882
今日推荐