分布式文件系统,是为了解决文件过多的情况,通过多台机器来存储,然后通过网络访问,就像访问自己本地主机一样,分布式系统具有容错性和通透性,hdfs分布式文件系统,适合大文件,对于小文件不合适,在Hadoop中,核心是HDFS和MapReduce,Hdfs的命令和linux的文件命令有些类似
HDFS的Shell操作
对hdfs操作的命令格式是
hadoop fs [generic options]
[-appendToFile <localsrc> ... <dst>]
[-cat [-ignoreCrc] <src> ...]
[-checksum <src> ...]
[-chgrp [-R] GROUP PATH...]
[-chmod [-R] <MODE[,MODE]... | OCTALMODE> PATH...]
[-chown [-R] [OWNER][:[GROUP]] PATH...]
[-copyFromLocal [-f] [-p] [-l] [-d] <localsrc> ... <dst>]
[-copyToLocal [-f] [-p] [-ignoreCrc] [-crc] <src> ... <localdst>]
[-count [-q] [-h] [-v] [-t [<storage type>]] [-u] [-x] <path> ...]
[-cp [-f] [-p | -p[topax]] [-d] <src> ... <dst>]
[-createSnapshot <snapshotDir> [<snapshotName>]]
[-deleteSnapshot <snapshotDir> <snapshotName>]
[-df [-h] [<path> ...]]
[-du [-s] [-h] [-x] <path> ...]
[-expunge]
[-find <path> ... <expression> ...]
[-get [-f] [-p] [-ignoreCrc] [-crc] <src> ... <localdst>]
[-getfacl [-R] <path>]
[-getfattr [-R] {-n name | -d} [-e en] <path>]
[-getmerge [-nl] [-skip-empty-file] <src> <localdst>]
[-help [cmd ...]]
[-ls [-C] [-d] [-h] [-q] [-R] [-t] [-S] [-r] [-u] [<path> ...]]
[-mkdir [-p] <path> ...]
[-moveFromLocal <localsrc> ... <dst>]
[-moveToLocal <src> <localdst>]
[-mv <src> ... <dst>]
[-put [-f] [-p] [-l] [-d] <localsrc> ... <dst>]
[-renameSnapshot <snapshotDir> <oldName> <newName>]
[-rm [-f] [-r|-R] [-skipTrash] [-safely] <src> ...]
[-rmdir [--ignore-fail-on-non-empty] <dir> ...]
[-setfacl [-R] [{-b|-k} {-m|-x <acl_spec>} <path>]|[--set <acl_spec> <path>]]
[-setfattr {-n name [-v value] | -x name} <path>]
[-setrep [-R] [-w] <rep> <path> ...]
[-stat [format] <path> ...]
[-tail [-f] <file>]
[-test -[defsz] <path>]
[-text [-ignoreCrc] <src> ...]
[-touchz <path> ...]
[-truncate [-w] <length> <path> ...]
[-usage [cmd ...]]
文件查看
#查看文件路径
hadoop fs -ls / #简写,直接查看当前的主机的/
hadoop fs -ls hdfs://localhost:9000/
文件复制
#复制文件
hadoop fs -cp /doubi/demo.txt /doubi/demo2.txt
删除文件
hadoop fs -rm /doubi/demo2.txt
创建文件夹
创建文件夹的操作,带
#创建文件夹,不带递归的
hadoop fs -mkdir /doubi/yellowcong
#创建文件,父类目录也创建
hadoop fs -mkdir -p /test/demo
文件上传
#将当前文件目录下的demo.txt 上传到hdfs服务器上的目录
hadoop fs -put demo.txt /doubi
#查看文件类容
hadoop fs -cat /doubi/demo.txt
#-text也是查看文件内容的命令,同cat一样
hadoop fs -text /doubi/demo.txt
文件下载
#将hdfs的文件下载到当前目录下
hadoop fs -get /doubi/demo.txt ./dou.txt