HDFS File System Shell guide from hadoop docs

Source: Internet
Author: User
Tags hadoop fs
Overview

The filesystem (FS) Shell is invoked by bin/hadoop FS <ARGs>. All FS shell commands take path Uris as arguments. The URI format isScheme: // autority/path. For HDFS the scheme isHDFS, And for the local filesystem the scheme isFile. The scheme and authority are optional. If not specified, the default scheme specified in the configuration is used. an HDFS file or directory such/Parent/childCan be specifiedHDFS: // namenodehost/parent/childOr simply/Parent/child(Given that your configuration is set to pointHDFS: // namenodehost). Most of the commands in FS shell behave like corresponding Unix commands. differences are described with each of the commands. error information is sentStderrAnd the output is sentStdout.

Cat

Usage: hadoop FS-cat URI [URI…]

Copies source pathsStdout.

Example:

  • Hadoop FS-cat HDFS: // nn1.example.com/file1 HDFS: // nn2.example.com/file2
  • Hadoop FS-cat file: // file3/user/hadoop/file4

Exit code:
Returns 0 on success and-1 on error.

Chgrp

Usage: hadoop FS-chgrp [-R] group URI [URI…]

Change Group Association of files. with-R, make the change recursively through the directory structure. the user must be the owner of files, or else a super-user. additional information is in the HDFS admin guide: permissions.

Chmod

Usage: hadoop FS-chmod [-R] <mode [, mode]... | octalmode> URI [URI…]

Change the permissions of files. with-R, make the change recursively through the directory structure. the user must be the owner of the file, or else a super-user. additional information is in the HDFS admin guide: permissions.

Chown

Usage: hadoop FS-chown [-R] [owner] [: [group] URI [URI]

Change the owner of files. With-R, make the change recursively through the directory structure. The user must be a super-user. Additional information is in the HDFS admin guide: permissions.

Copyfromlocal

Usage: hadoop FS-copyfromlocal <localsrc> URI

SimilarPutCommand, doesn t that the source is restricted to a local file reference.

Copytolocal

Usage: hadoop FS-copytolocal [-ignorecrc] [-CRC] URI <localdst>

SimilarGetCommand, cannot that the destination is restricted to a local file reference.

Count

Usage: hadoop FS-count [-q] <paths>

Count the number of directories, files and bytes under the paths that match the specified file pattern. The output columns are:
Dir_count, file_count, content_size file_name.

The output columns with-q are:
Quota, remaining_quata, space_quota, remaining_space_quota, dir_count, file_count, content_size, file_name.

Example:

  • Hadoop FS-count HDFS: // nn1.example.com/file1 HDFS: // nn2.example.com/file2
  • Hadoop FS-count-q hdfs: // nn1.example.com/file1

Exit code:

Returns 0 on success and-1 on error.

CP

Usage: hadoop FS-cp uri [URI…] <DEST>

Copy files from source to destination. This command allows multiple sources as well in which case the destination must be a directory.
Example:

  • Hadoop FS-CP/user/hadoop/file1/user/hadoop/file2
  • Hadoop FS-CP/user/hadoop/file1/user/hadoop/file2/user/hadoop/Dir

Exit code:

Returns 0 on success and-1 on error.

Du

Usage: hadoop FS-du URI [URI…]

Displays aggregate length of files contained in the directory or the length of a file in case its just a file.
Example:
Hadoop FS-du/user/hadoop/dir1/user/hadoop/file1 HDFS: // nn.example.com/user/hadoop/dir1
Exit code:
Returns 0 on success and-1 on error.

DUS

Usage: hadoop FS-DUS <ARGs>

Displays a summary of file lengths.

Expunge

Usage: hadoop FS-expunge

Empty the trash. Refer to HDFS architecture for more information on trash feature.

Get

Usage: hadoop FS-Get [-ignorecrc] [-CRC] <SRC> <localdst>

Copy files to the local file system. files that fail the CRC check may be copied with the-ignorecrc option. Files and CRCs may be copied using the-CRC option.

Example:

  • Hadoop FS-Get/user/hadoop/file localfile
  • Hadoop FS-Get HDFS: // nn.example.com/user/hadoop/file localfile

Exit code:

Returns 0 on success and-1 on error.

Getmerge

Usage: hadoop FS-getmerge <SRC> <localdst> [addnl]

Takes a source directory and a destination file as input and concatenates files in SRC into the destination local file. Optionally addnl can be set to enable adding a newline character at the end of each file.

Ls

Usage: hadoop FS-ls <ARGs>

For a file returns stat on the file with the following format:

Permissions number_of_replicas userid groupid filesize modification_date modification_time filename

For a directory it returns list of its direct children as in Unix. A directory is listed:

Permissions userid groupid modification_date modification_time dirname

Example:

Hadoop FS-ls/user/hadoop/file1

Exit code:

Returns 0 on success and-1 on error.

LSR

Usage: hadoop FS-LSR <ARGs>
Recursive version of LS. Similar to Unix LS-R.

Mkdir

Usage: hadoop FS-mkdir <paths>

Takes path Uri's as argument and creates directories. The behavior is much like UNIX mkdir-P creating parent directories along the path.

Example:

  • Hadoop FS-mkdir/user/hadoop/dir1/user/hadoop/dir2
  • Hadoop FS-mkdir HDFS: // nn1.example.com/user/hadoop/dir HDFS: // nn2.example.com/user/hadoop/dir

Exit code:

Returns 0 on success and-1 on error.

Movefromlocal

Usage: DFS-movefromlocal <localsrc> <DST>

SimilarPutCommand, couldn't that the source localsrc is deleted after it's copied.

Movetolocal

Usage: hadoop FS-movetolocal [-CRC] <SRC> <DST>

Displays a "not implemented yet" message.

MV

Usage: hadoop FS-mv uri [URI…] <DEST>

Moves files from source to destination. This command allows multiple sources as well in which case the destination needs to be a directory. Moving Files Within SS filesystems is not permitted.
Example:

  • Hadoop FS-mV/user/hadoop/file1/user/hadoop/file2
  • Hadoop FS-mv hdfs: // nn.example.com/file1 HDFS: // nn.example.com/file2 HDFS: // nn.example.com/file3 HDFS: // nn.example.com/dir1

Exit code:

Returns 0 on success and-1 on error.

Put

Usage: hadoop FS-put <localsrc>... <DST>

Copy single SRC, or multiple SRCS from local file system to the destination filesystem. Also reads input from stdin and writes to destination filesystem.

  • Hadoop FS-put localfile/user/hadoop/hadoopfile
  • Hadoop FS-put localfile1 localfile2/user/hadoop/hadoopdir
  • Hadoop FS-put localfile HDFS: // nn.example.com/hadoop/hadoopfile
  • Hadoop FS-put-HDFS: // nn.example.com/hadoop/hadoopfile
    Reads the input from stdin.

Exit code:

Returns 0 on success and-1 on error.

Rm

Usage: hadoop FS-RM [-skiptrash] URI [URI…]

Delete Files specified as args. only deletes non empty directory and files. if the-skiptrash option is specified, the trash, if enabled, will be bypassed and the specified file (s) deleted immediately. this can be useful when it is necessary to delete files from an over-quota directory. refer to RMR for Recursive deletes.
Example:

  • Hadoop FS-rm hdfs: // nn.example.com/file/user/hadoop/emptydir

Exit code:

Returns 0 on success and-1 on error.

RMR

Usage: hadoop FS-RMR [-skiptrash] URI [URI…]

Recursive version of Delete. if the-skiptrash option is specified, the trash, if enabled, will be bypassed and the specified file (s) deleted immediately. this can be useful when it is necessary to delete files from an over-quota directory.
Example:

  • Hadoop FS-RMR/user/hadoop/Dir
  • Hadoop FS-rmr hdfs: // nn.example.com/user/hadoop/dir

Exit code:

Returns 0 on success and-1 on error.

Setrep

Usage: hadoop FS-setrep [-R] <path>

Changes the replication factor of a file.-R option is for recursively increasing the replication factor of files within a directory.

Example:

  • Hadoop FS-setrep-W 3-r/user/hadoop/dir1

Exit code:

Returns 0 on success and-1 on error.

Stat

Usage: hadoop FS-stat URI [URI…]

Returns the stat information on the path.

Example:

  • Hadoop FS-stat path

Exit code:
Returns 0 on success and-1 on error.

Tail

Usage: hadoop FS-tail [-F] URI

Displays last kilobyte of the file to stdout.-F option can be used as in UNIX.

Example:

  • Hadoop FS-tail pathname

Exit code:
Returns 0 on success and-1 on error.

Test

Usage: hadoop FS-test-[ezd] URI

Options:
-E check to see if the file exists. Return 0 if true.
-Z check to see if the file is zero length. Return 0 if true.
-D check to see if the path is directory. Return 0 if true.

Example:

  • Hadoop FS-test-e filename

Text

Usage: hadoop FS-text <SRC>

Takes a source file and outputs the file in text format. The allowed formats are zip and textrecordinputstream.

Touchz

Usage: hadoop FS-touchz URI [URI…]

Create a file of zero length.

Example:

  • Hadoop-touchz pathname

Exit code:
Returns 0 on success and-1 on error.

Related Article

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.