<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          大數(shù)據(jù) | HDFS 常用操作命令

          共 7021字,需瀏覽 15分鐘

           ·

          2021-11-08 10:04


          早期文章



          ? ? ? ? HDFS 是 Hadoop Distributed File System 的簡(jiǎn)寫,即 Hadoop 分布式文件系統(tǒng)。它是 Hadoop 項(xiàng)目的核心子項(xiàng)目,它為大數(shù)據(jù)分布式計(jì)算提供了海量數(shù)據(jù)的存儲(chǔ)與管理。


          ? ? ? ? 既然 HDFS 是文件系統(tǒng),那么它必然有一套對(duì)文件管理的命令,這里介紹一下 HDFS 常用的文件管理命令。


          一、HDFS 命令前綴

          ? ? ? ? 所有操作 HDFS 的命令都需要前綴,它的前綴有兩種,分別是 hadoop fs 或 hdfs dfs 兩種。可以通過 hadoop fs -help 或 hdfs dfs -help 來查看其幫助文件。比如:

          $ hadoop fs -help ls-ls [-C] [-d] [-h] [-q] [-R] [-t] [-S] [-r] [-u] [ ...] :  List the contents that match the specified file pattern. If path is not  specified, the contents of /user/ will be listed. For a directory a  list of its direct children is returned (unless -d option is specified).
          Directory entries are of the form: permissions - userId groupId sizeOfDirectory(in bytes) modificationDate(yyyy-MM-dd HH:mm) directoryName
          and file entries are of the form: permissions numberOfReplicas userId groupId sizeOfFile(in bytes) modificationDate(yyyy-MM-dd HH:mm) fileName
          -C Display the paths of files and directories only. -d Directories are listed as plain files. -h Formats the sizes of files in a human-readable fashion rather than a number of bytes. -q Print ? instead of non-printable characters. -R Recursively list the contents of directories. -t Sort files by modification time (most recent first). -S Sort files by size. -r Reverse the order of the sort. -u Use time of last access instead of modification for display and sorting.

          ? ? ? ? 或者使用 hdfs dfs 來查看幫助,命令如下:

          $ hdfs dfs -help ls-ls [-C] [-d] [-h] [-q] [-R] [-t] [-S] [-r] [-u] [ ...] :  List the contents that match the specified file pattern. If path is not  specified, the contents of /user/ will be listed. For a directory a  list of its direct children is returned (unless -d option is specified).
          Directory entries are of the form: permissions - userId groupId sizeOfDirectory(in bytes) modificationDate(yyyy-MM-dd HH:mm) directoryName
          and file entries are of the form: permissions numberOfReplicas userId groupId sizeOfFile(in bytes) modificationDate(yyyy-MM-dd HH:mm) fileName
          -C Display the paths of files and directories only. -d Directories are listed as plain files. -h Formats the sizes of files in a human-readable fashion rather than a number of bytes. -q Print ? instead of non-printable characters. -R Recursively list the contents of directories. -t Sort files by modification time (most recent first). -S Sort files by size. -r Reverse the order of the sort. -u Use time of last access instead of modification for display and sorting.


          二、ls 命令

          ? ? ? ? ls 命令用來查看 HDFS 系統(tǒng)中的目錄和文件,命令如下:

          $ hadoop fs -ls /

          ? ? ? ? 也可以通過給 ls 添加 -R 參數(shù)來遞歸列出要查看目錄下的所有目錄和文件,命令如下:

          $ hadoop fs -ls -R /

          ? ? ? ? 由于目前在 HDFS 中并沒有任何文件和目錄,因此這里沒有顯示任何的結(jié)果。


          三、put 命令

          ? ? ? ? put 命令用于將本地文件上傳到 HDFS 系統(tǒng)中,命令如下:

          $ hadoop fs -put test.txt /$ hadoop fs -ls /Found 1 items-rw-r--r--   2 hadoop supergroup          5 2021-11-07 13:22 /test.txt

          ? ? ? ? 通過?-put 命令將本地當(dāng)前目錄下的 test.txt 文件上傳到了 HDFS 的 / 目錄下,通過?-ls 命令可以看到文件已經(jīng)上傳到 HDFS 系統(tǒng)中了。


          四、moveFromLocal 命令

          ? ? ? ? 將本地文件移動(dòng)到 HDFS 文件系統(tǒng)中,并將本地的文件進(jìn)行刪除,命令如下:

          $ ll總用量 84804-rw-rw-r--. 1 hadoop hadoop        5 11月  7 13:27 abc.txt$ hadoop fs -moveFromLocal abc.txt /$ hadoop fs -ls /Found 2 items-rw-r--r--   2 hadoop supergroup          5 2021-11-07 13:27 /abc.txt-rw-r--r--???2?hadoop?supergroup??????????5?2021-11-07?13:22?/test.txt

          ? ? ? ??將本地的 abc.txt 文件上傳到 HDFS 的 / 目錄下,通過 -ls 命令查看?/ 目錄下已經(jīng)有了 abc.txt 文件,再來查看本地文件,本地的 abc.txt 文件已經(jīng)被移除。


          五、get 命令

          ? ? ? ? get 命令用來將 HDFS 文件系統(tǒng)中的文件下載到本地,下載時(shí)的文件名不能與本地文件相同,否則會(huì)提示文件已存在。命令如下:

          $ hadoop fs -get /abc.txt /home/hadoop/$ ll總用量 84804-rw-r--r--. 1 hadoop hadoop        5 117 13:42 abc.txt

          ? ? ? ? 下載文件時(shí)確保文件不重名,否則提示文件已存在,命令如下:

          $ hadoop fs -get / /home/hadoop/get: `/home/hadoop/abc.txt': File existsget:?`/home/hadoop/test.txt':?File?exists


          六、rm 命令

          ? ? ? ? rm 命令用來刪除 HDFS 系統(tǒng)中的文件或文件夾,每次可以刪除多個(gè)文件或目錄,命令如下:

          $ hadoop fs -rm /test.txtDeleted /test.txt$ hadoop fs -ls /Found 1 items-rw-r--r--???2?hadoop?supergroup??????????5?2021-11-07?13:27?/abc.txt

          七、mkdir 命令

          ? ? ? ? mkdir 命令用來在 HDFS 系統(tǒng)中創(chuàng)建目錄,可以使用 -p 參數(shù)創(chuàng)建多級(jí)目錄,即當(dāng)父目錄不存在時(shí),則自動(dòng)創(chuàng)建,若不使用 -p 參數(shù),當(dāng)父目錄不存在時(shí)則會(huì)提示文件或目錄不存在。命令如下:

          $ hadoop fs -mkdir /test$ hadoop fs -mkdir /abc/abcmkdir: `/abc/abc': No such file or directory$?hadoop?fs?-mkdir?-p?/abc/abc


          八、cp 命令

          ? ? ? ? cp 命令在 HDFS 文件系統(tǒng)中用于文件的復(fù)制,命令如下:

          $ hadoop fs -ls /Found 3 itemsdrwxr-xr-x   - hadoop supergroup          0 2021-11-07 13:47 /abc-rw-r--r--   2 hadoop supergroup          5 2021-11-07 13:27 /abc.txtdrwxr-xr-x   - hadoop supergroup          0 2021-11-07 13:47 /test$ hadoop fs -cp /abc.txt /abc/$ hadoop fs -ls -R /drwxr-xr-x   - hadoop supergroup          0 2021-11-07 13:49 /abcdrwxr-xr-x   - hadoop supergroup          0 2021-11-07 13:47 /abc/abc-rw-r--r--   2 hadoop supergroup          5 2021-11-07 13:49 /abc/abc.txt-rw-r--r--   2 hadoop supergroup          5 2021-11-07 13:27 /abc.txtdrwxr-xr-x???-?hadoop?supergroup??????????0?2021-11-07?13:47?/test

          ? ? ? ? 通過 cp 命令將 /abc.txt 文件復(fù)制到了 /abc/ 目錄下,然后使用 ls -R 來遞歸查看目錄。


          九、mv 命令

          ? ? ? ? mv 命令用來在 HDFS 文件系統(tǒng)下完成移動(dòng)的功能,也可以用來進(jìn)行重命名。命令如下:

          hadoop fs -mv /abc/abc.txt /test/[hadoop@centos01 ~]$ hadoop fs -ls -R /drwxr-xr-x   - hadoop supergroup          0 2021-11-07 13:52 /abcdrwxr-xr-x   - hadoop supergroup          0 2021-11-07 13:47 /abc/abc-rw-r--r--   2 hadoop supergroup          5 2021-11-07 13:27 /abc.txtdrwxr-xr-x   - hadoop supergroup          0 2021-11-07 13:52 /test-rw-r--r--???2?hadoop?supergroup??????????5?2021-11-07?13:49?/test/abc.txt

          ? ? ? ??從上面的命令中可以看出,/abc/abc.txt 文件被移動(dòng)到了 /test/ 目錄下。再來看下它的重命名功能:

          $ hadoop fs -mv /test/abc.txt /test/abcabc.txt$ hadoop fs -ls /test/Found 1 items-rw-r--r--???2?hadoop?supergroup??????????5?2021-11-07?13:49?/test/abcabc.txt

          ? ? ? ? 通過 ls 命令可以看到,abc.txt 已經(jīng)被重命名為了 abcabc.txt。


          十、cat 命令

          ? ? ? ? cat 命令用來輸出 HDFS 文件系統(tǒng)中某個(gè)文件的所有內(nèi)容,命令如下:

          $ hadoop fs -cat /test/abcabc.txt1234$ hadoop fs -cat /abc.txt1234

          十一、appendToFile 命令

          ? ? ? ??將單個(gè)或多個(gè)文件的內(nèi)容從本地系統(tǒng)追加到 HDFS 系統(tǒng)的文件中,命令如下:

          $ hadoop fs -appendToFile abc.txt /abc.txt$ hadoop fs -cat /abc.txt12341234

          ? ? ? ??可以看到,/abc.txt 的內(nèi)容已經(jīng)發(fā)生了改變。


          十二、總結(jié)

          ? ? ? ? HDFS 關(guān)于文件的基本操作與 Linux 系統(tǒng)命令的基本是一樣的,只是 HDFS 命令增加了 hadoop fs 這樣的前綴。如果對(duì) Linux 系統(tǒng)命令有些了解,那么 HDFS 的基本操作命令也會(huì)非常容易的上手。



          公眾號(hào)內(nèi)回復(fù)?【mongo】 下載 SpringBoot 整合操作 MongoDB 的文檔。


          ? ? ? ? 之前整理的關(guān)于 Redis 的文章:

          Redis | Redis 的安裝

          Redis | Redis 的幫助命令

          Redis | Redis 命令分類

          Redis | Redis 通用命令

          Redis | Redis 字符串相關(guān)命令

          Redis | Redis 列表相關(guān)命令

          Redis | Redis 集合相關(guān)命令

          Redis | Redis 有序集合相關(guān)命令

          Redis | Redis 哈希相關(guān)命令

          Redis | 源碼閱讀 —— 字符串

          Redis | 源碼閱讀 —— 鏈表

          Redis | Redis Pub/Sub相關(guān)命令

          Redis | 管道 —— PipeLine

          Redis | SpringBoot整合Redis

          Redis | Redis 的事務(wù)一

          Redis | Redis 的事務(wù)二

          Redis | 基礎(chǔ)數(shù)據(jù)類型應(yīng)用場(chǎng)景

          Redis | 事務(wù)源碼閱讀

          Redis | 事物源碼閱讀 —— watch

          Redis | 慢查詢

          Redis | 給接口添加緩存

          Redis | Redis 也會(huì)算距離


          瀏覽 77
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          分享
          舉報(bào)
          評(píng)論
          圖片
          表情
          推薦
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          分享
          舉報(bào)
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  亚洲护士无码 | 欧美成人综合一区 | 特黄色一级片 | 美女操逼网址 | 亚洲人成色77777在线播放 |