FileSystem for file operations in Hadoop

Source: Internet
Author: User
Tags hdfs dfs hadoop fs

File Path Problems:

The path of the local file (linux) must start with file: //, and then add the actual file path. Example: file: // home/myHadoop/test

The file path in the cluster starts. Example:/temp/test

Command line operation. For example, to delete a hadoop cluster, operate on any node:

1. delete files in the Cluster

Hdfs dfs-rmr/temp/test hadoop 2.2.0

Hadoop fs-rmr/temp/test earlier version

2. commands for deleting Local Machine nodes

Hdfs dfs-rmr file: // home/myhadoop/test

Hadoop fs-rmr/temp/test

View hadoop Filesystem shell command: http://hadoop.apache.org/docs/r2.2.0/hadoop-project-dist/hadoop-common/FileSystemShell.html

Java operation file org. apache. hadoop. fs. FileSystem class

Fileystem is an abstract class that can be used to obtain a local file system or a cluster file system.

Configuration conf = new Configuration ();

Fileystem fs = FileSystem. get (URI. create (path), conf );

Here, path is the file path mentioned above. If it is a cluster file path, the cluster file system is obtained. If it is a local file path, the local file system is obtained.

Example: implement the shell command of copyFromLocal

Package com. alm. main;

Import java. io. IOException;
Import java.net. URI;

Import org. apache. hadoop. conf. Configuration;
Import org. apache. hadoop. fs. FileSystem;
Import org. apache. hadoop. fs. Path;


Public class FileSystemTest {
Public static void main (String args []) throws IOException {
FileSystem fs;
Configuration conf = new Configuration ();
Fs = FileSystem. get (URI. create ("hdfs: // 192.168.1.85: 9000"), conf );

Fs. copyFromLocalFile (false, true, new Path ("file: // home/myhadoop2/Desktop/testcp1"), new Path ("hdfs: // 192.168.1.85: 9000/testforcp/testcp1 "));


}
}

Build a Hadoop environment on Ubuntu 13.04

Cluster configuration for Ubuntu 12.10 + Hadoop 1.2.1

Build a Hadoop environment on Ubuntu (standalone mode + pseudo Distribution Mode)

Configuration of Hadoop environment in Ubuntu

Detailed tutorial on creating a Hadoop environment for standalone Edition

Build a Hadoop environment (using virtual machines to build two Ubuntu systems in a Winodws environment)

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.