"Hadoop" HDFs basic command

Source: Internet
Author: User
Tags create directory mkdir hadoop fs
1.Create directory
[grid @ master ~] $ hadoop fs -mkdir / test
2. View the file list
[grid @ master ~] $ hadoop fs -ls /
Found 3 items
drwxr-xr-x-grid supergroup 0 2018-01-08 04:37 / test
drwx -------grid supergroup 0 2018-01-07 11:57 / tmp
drwxr-xr-x-grid supergroup 0 2018-01-07 11:46 / user
3. Upload files to HDFS
#New upload directory
[grid @ master ~] $ hadoop fs -mkdir / test / input
#Upload files to the new directory, two commands can upload
(1) hadoop fs -put

[grid @ master ~] $ hadoop fs -put /home/grid/grid.txt /test/input/grid.txt
[grid @ master ~] $ hadoop fs -ls / test / input
Found 1 items
-rw-r--r-- 2 grid supergroup 0 2018-01-08 04:43 /test/input/grid.txt
(2) hadoop fs -copyFromLocal

[grid @ master ~] $ hadoop fs -copyFromLocal -f /home/grid/grid.txt /test/input/grid1.txt

[grid @ master ~] $ hadoop fs -ls / test / input
Found 2 items
-rw-r--r-- 2 grid supergroup 0 2018-01-08 04:43 /test/input/grid.txt
-rw-r--r-- 2 grid supergroup 0 2018-01-08 04:46 /test/input/grid1.txt
4. Download the file locally, two commands
(1) hadoop fs -get

[grid @ master ~] $ hadoop fs -get /test/input/grid.txt /home/grid/grid_local.txt
(2) hadoop fs -copyToLocal

[grid @ master ~] $ hadoop fs -copyToLocal /test/input/grid.txt /home/grid/grid_local_1.txt
5. View HDFS file contents, three commands
(1) hadoop fs -cat

[grid @ master ~] $ hadoop fs -cat /test/input/grid.txt
Welcome to my blog!
I'm NextAction!
(2) hadoop fs -tail

[grid @ master ~] $ hadoop fs -tail /test/input/grid.txt
Welcome to my blog!
I'm NextAction!
(3) hadoop fs -text

[grid @ master ~] $ hadoop fs -text /test/input/grid.txt
Welcome to my blog!
I'm NextAction!
6. Delete HDFS files
[grid @ master ~] $ hadoop fs -rm /test/input/grid.txt
18/01/08 04:58:13 INFO fs.TrashPolicyDefault: Namenode trash configuration: Deletion interval = 0 minutes, Emptier interval = 0 minutes.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.