File System Shell

Source: Internet
Author: User
Tags hdfs dfs hadoop fs
  • Overview
  • Appendtofile
  • Cat
  • Chgrp
  • Chmod
  • Chown
  • Copyfromlocal
  • Copytolocal
  • Count
  • CP
  • Du
  • DUS
  • Expunge
  • Get
  • Getfacl
  • Getmerge
  • Ls
  • LSR
  • Mkdir
  • Movefromlocal
  • Movetolocal
  • MV
  • Put
  • Rm
  • RMR
  • Setfacl
  • Setrep
  • Stat
  • Tail
  • Test
  • Text
  • Touchz
Overview

The file system (FS) Shell has des varous shell-like commands that directly interact with the hadoop Distributed File System (HDFS) as well as other file systems that hadoop supports, such as local FS, hftp FS, S3 FS, and others. the FS shell is invoked:

bin/hadoop fs <args>

All FS shell commands take path Uris as arguments. The URI format isScheme: // authority/path. For HDFS the scheme isHDFS, And for the local FS 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 as/parent/child can 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 sent to stderr and the output is sent to stdout.

Appendtofile

Usage:Hdfs dfs-appendtofile <localsrc>... <DST>

Append single SRC, or multiple SRCS from local file system to the destination file system. Also reads input from stdin and appends to destination file system.

  • Hdfs dfs-appendtofile localfile/user/hadoop/hadoopfile
  • Hdfs dfs-appendtofile localfile1 localfile2/user/hadoop/hadoopfile
  • Hdfs dfs-appendtofile localfile HDFS: // nn.example.com/hadoop/hadoopfile
  • Hdfs dfs-appendtofile-HDFS: // nn.example.com/hadoop/hadoopfileReads the input from stdin.

Exit code:

Returns 0 on success and 1 on error.

Cat

Usage:Hdfs dfs-cat URI [uri...]

Copies source paths to stdout.

Example:

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

Exit code:

Returns 0 on success and-1 on error.

Chgrp

Usage:Hdfs dfs-chgrp [-R] group URI [uri...]

Change Group Association of files. The user must be the owner of files, or else a super-user. Additional information is in the permissions guide.

Options

  • The-r option will make the change recursively through the directory structure.
Chmod

Usage:Hdfs dfs-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 permissions guide.

Options

  • The-r option will make the change recursively through the directory structure.
Chown

Usage:Hdfs dfs-chown [-R] [owner] [: [group] URI [URI]

Change the owner of files. The user must be a super-user. Additional information is in the permissions guide.

Options

  • The-r option will make the change recursively through the directory structure.
Copyfromlocal

Usage:Hdfs dfs-copyfromlocal <localsrc> URI

Similar to put command, doesn t that the source is restricted to a local file reference.

Options:

  • The-F option will overwrite the destination if it already exists.
Copytolocal

Usage:Hdfs dfs-copytolocal [-ignorecrc] [-CRC] URI <localdst>

Similar to get command, couldn't that the destination is restricted to a local file reference.

Count

Usage:Hdfs dfs-count [-q] <paths>

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

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

Example:

  • Hdfs dfs-count HDFS: // nn1.example.com/file1 HDFS: // nn2.example.com/file2
  • Hdfs dfs-count-q hdfs: // nn1.example.com/file1

Exit code:

Returns 0 on success and-1 on error.

CP

Usage:Hdfs dfs-CP [-F] 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.

Options:

  • The-F option will overwrite the destination if it already exists.

Example:

  • Hdfs dfs-CP/user/hadoop/file1/user/hadoop/file2
  • Hdfs dfs-CP/user/hadoop/file1/user/hadoop/file2/user/hadoop/Dir

Exit code:

Returns 0 on success and-1 on error.

Du

Usage:Hdfs dfs-Du [-S] [-H] URI [uri...]

Displays sizes of files and directories contained in the given directory or the length of a file in case its just a file.

Options:

  • The-s option will result in an aggregate summary of file lengths being displayed, rather than the individual files.
  • The-H option will format file sizes in a "human-readable" fashion (e. g 64.0 m instead of 67108864)

Example:

  • Hdfs dfs-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:Hdfs dfs-DUS <ARGs>

Displays a summary of file lengths. This is an alternate form of hdfs dfs-du-s.

Expunge

Usage:Hdfs dfs-expunge

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

Get

Usage:Hdfs dfs-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:

  • Hdfs dfs-Get/user/hadoop/file localfile
  • Hdfs dfs-Get HDFS: // nn.example.com/user/hadoop/file localfile

Exit code:

Returns 0 on success and-1 on error.

Getfacl

Usage:Hdfs dfs-getfacl [-R] <path>

Displays the access control lists (ACLs) of files and directories. If a directory has a default ACL, then getfacl also displays the default ACL.

Options:

  • -R: list the ACLs of all files and directories recursively.
  • Path: File or directory to list.

Examples:

  • Hdfs dfs-getfacl/File
  • Hdfs dfs-getfacl-r/Dir

Exit code:

Returns 0 on success and non-zero on error.

Getmerge

Usage:Hdfs dfs-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:Hdfs dfs-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:

  • Hdfs dfs-ls/user/hadoop/file1

Exit code:

Returns 0 on success and-1 on error.

LSR

Usage:Hdfs dfs-LSR <ARGs>

Recursive version of LS. Similar to Unix LS-R.

Mkdir

Usage:Hdfs dfs-mkdir [-p] <paths>

Takes path Uri's as argument and creates directories.

Options:

  • The-P option behavior is much like UNIX mkdir-P, creating parent directories along the path.

Example:

  • Hdfs dfs-mkdir/user/hadoop/dir1/user/hadoop/dir2
  • Hdfs dfs-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>

Similar to put command, couldn't that the source localsrc is deleted after it's copied.

Movetolocal

Usage:Hdfs dfs-movetolocal [-CRC] <SRC> <DST>

Displays a "not implemented yet" message.

MV

Usage:Hdfs dfs-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 file systems is not permitted.

Example:

  • Hdfs dfs-mV/user/hadoop/file1/user/hadoop/file2
  • Hdfs dfs-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:Hdfs dfs-put <localsrc>... <DST>

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

  • Hdfs dfs-put localfile/user/hadoop/hadoopfile
  • Hdfs dfs-put localfile1 localfile2/user/hadoop/hadoopdir
  • Hdfs dfs-put localfile HDFS: // nn.example.com/hadoop/hadoopfile
  • Hdfs dfs-put-HDFS: // nn.example.com/hadoop/hadoopfileReads the input from stdin.

Exit code:

Returns 0 on success and-1 on error.

Rm

Usage:Hdfs dfs-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:

  • Hdfs dfs-rm hdfs: // nn.example.com/file/user/hadoop/emptydir

Exit code:

Returns 0 on success and-1 on error.

RMR

Usage:Hdfs dfs-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:

  • Hdfs dfs-RMR/user/hadoop/Dir
  • Hdfs dfs-rmr hdfs: // nn.example.com/user/hadoop/dir

Exit code:

Returns 0 on success and-1 on error.

Setfacl

Usage:Hdfs dfs-setfacl [-R] [-B |-K-M |-x <acl_spec> <path>] | [-- set <acl_spec> <path>]

Sets access control lists (ACLs) of files and directories.

Options:

  • -B: Remove all but the base ACL entries. The entries for user, group and others are retained for compatibility with permission bits.
  • -K: remove the default ACL.
  • -R: Apply operations to all files and directories recursively.
  • -M: Modify ACL. New entries are added to the ACL, and existing entries are retained.
  • -X: Remove specified ACL entries. Other ACL entries are retained.
  • -- Set: fully replace the ACL, discarding all existing entries.Acl_specMust include entries for user, group, and others for compatibility with permission bits.
  • Acl_spec: Comma separated list of ACL entries.
  • Path: File or directory to modify.

Examples:

  • Hdfs dfs-setfacl-M User: hadoop: RW-/File
  • Hdfs dfs-setfacl-x User: hadoop/File
  • Hdfs dfs-setfacl-B/File
  • Hdfs dfs-setfacl-k/Dir
  • Hdfs dfs-setfacl -- Set User: RW-, user: hadoop: RW-, group: r --, other: r --/File
  • Hdfs dfs-setfacl-r-m User: hadoop: R-x/Dir
  • Hdfs dfs-setfacl-M default: User: hadoop: R-x/Dir

Exit code:

Returns 0 on success and non-zero on error.

Setrep

Usage:Hdfs dfs-setrep [-R] [-W] <numreplicas> <path>

Changes the replication factor of a file. IfPathIs a directory then the command recursively changes the replication factor of all files under the directory tree rootedPath.

Options:

  • The-W flag requests that the command wait for the replication to complete. This can potentially take a very long time.
  • The-r flag is accepted for backwards compatibility. It has no effect.

Example:

  • Hdfs dfs-setrep-W 3/user/hadoop/dir1

Exit code:

Returns 0 on success and-1 on error.

Stat

Usage:Hdfs dfs-stat URI [uri...]

Returns the stat information on the path.

Example:

  • Hdfs dfs-stat path

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

Tail

Usage:Hdfs dfs-tail [-F] URI

Displays last kilobyte of the file to stdout.

Options:

  • The-F option will output appended data as the file grows, as in UNIX.

Example:

  • Hdfs dfs-tail pathname

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

Test

Usage:Hdfs dfs-test-[ezd] URI

Options:

  • The-E Option will check to see if the file exists, returning 0 if true.
  • The-Z option will check to see if the file is zero length, returning 0 if true.
  • The-D option will check to see if the path is directory, returning 0 if true.

Example:

  • Hdfs dfs-test-e filename
Text

Usage:Hdfs dfs-text <SRC>

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

Touchz

Usage:Hdfs dfs-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.