You are on page 1of 7

Cách truy cập vào HDFS file system

Chạy cloudera bằng VirtualBox


Ở tab Cloudera Live: Welcome!: Chọn Hadoop  HDFS NameNode

Chọn Utilities  Browse the file system


Đường dẫn mặc định trên HDFS: /user/cloudera

Cách lấy đường dẫn thư mục ở Local file system


Ở màn hình desktop của cloudera chọn Cloudera’s Home
Để lấy đường dẫn của một thư mục bất kỳ: Chọn File  Open Location
Một số câu lệnh HDFS
Cú pháp chung cho các câu lệnh HDFS:
hadoop fs -<câu lệnh>

1/ help
$ hadoop fs –help
Liệt kê các câu lệnh trong HDFS

2/ Usage
$ hadoop fs –usage <command>
Liệt kê các tuỳ chọn của một câu lệnh cụ thể
Vd: Liệt kê các tuỳ chọn của câu lệnh ls (-d, -h, -R)
3/ ls
$ hadoop fs –ls
This command will list all the available files and subdirectories under default directory.
For instance, in our example the default directory for Cloudera VM is /user/cloudera
Liệt kê tất cả các thư mục và đường dẫn có sẵn ở đường dẫn mặc định (trên HDFS)

4/ mkdir- Used to create a new directory in HDFS at a given location.


$ hadoop fs –mkdir /path/directory_name
Tạo đường dẫn trên HDFS
Vd tạo đường dẫn test trên HDFS

5/ CopyFromLocal
Copy a file from local filesytem to HDFS location. Copy thư mục từ local qua HDFS.
hadoop fs -copyFromLocal <localsrc> <hdfs destination>
VD:
Tạo 1 file văn bản ở Desktop.
Thêm nội dung để chút nữa đọc nội dung bằng câu lệnh cat

Copy file VD từ local qua đường dẫn test bên HDFS

6/ Put
hadoop fs -put <localsrc> <desti>
- The Hadoop fs shell command put is similar to the copyFromLocal, which copies files
or directory from the local filesystem to the destination in the Hadoop filesystem.
Tương tự câu lệnh copyFromLocal

7/ Get
hadoop fs -get <src> <localdest>
The Hadoop fs shell command get copies the file or directory from the Hadoop file
system to the local file system.
Copy thư mục hoặc đường dẫn từ HDFS về local
VD copy file VD từ bên HDFS về Cloudera’s Home (thư mục nằm ở màn hình cloudera
desktop)
8/ copyToLocal
hadoop fs -copyToLocal <hdfs source> <localdst>
copyToLocal command copies the file from HDFS to the local file system.
Tương tự câu lệnh get phía trên
9/ cat
hadoop fs –cat /path_to_file_in_hdfs
The cat command reads the file in HDFS and displays the content of the file on console
or stdout.
Câu lệnh dùng để dọc nội dung thư mục ở HDFS
VD đọc file văn bản VD vừa tạo lúc nãy

You might also like