| <?xml version="1.0"?> |
| <!-- |
| Copyright 2002-2004 The Apache Software Foundation |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
| --> |
| <!DOCTYPE document PUBLIC "-//APACHE//DTD Documentation V2.0//EN" "http://forrest.apache.org/dtd/document-v20.dtd"> |
| <document> |
| <header> |
| <title>Hadoop FS Shell Guide</title> |
| </header> |
| <body> |
| <section> |
| <title> FS Shell </title> |
| <p> |
| The FileSystem (FS) shell is invoked by |
| <code>bin/hadoop fs <args></code>. |
| All the FS shell commands take path URIs as arguments. The URI |
| format is <em>scheme://autority/path</em>. For HDFS the scheme |
| is <em>hdfs</em>, and for the local filesystem the scheme |
| is <em>file</em>. 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 <em>/parent/child</em> |
| can be specified as <em>hdfs://namenodehost/parent/child</em> or |
| simply as <em>/parent/child</em> (given that your configuration |
| is set to point to <em>hdfs://namenodehost</em>). 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 <em>stderr</em> and the |
| output is sent to <em>stdout</em>. |
| </p> |
| <section> |
| <title> cat </title> |
| <p> |
| <code>Usage: hadoop fs -cat URI [URI …]</code> |
| </p> |
| <p> |
| Copies source paths to <em>stdout</em>. |
| </p> |
| <p>Example:</p> |
| <ul> |
| <li> |
| <code> hadoop fs -cat hdfs://nn1.example.com/file1 hdfs://nn2.example.com/file2 |
| </code> |
| </li> |
| <li> |
| <code>hadoop fs -cat file:///file3 /user/hadoop/file4 </code> |
| </li> |
| </ul> |
| <p>Exit Code:<br/> |
| <code> Returns 0 on success and -1 on error. </code></p> |
| </section> |
| <section> |
| <title> chgrp </title> |
| <p> |
| <code>Usage: hadoop fs -chgrp [-R] GROUP URI [URI …]</code> |
| </p> |
| <p> |
| Change group association of files. With <code>-R</code>, 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 <a href="hdfs_permissions_guide.html">HDFS Admin Guide: Permissions</a>. |
| </p> |
| </section> |
| <section> |
| <title> chmod </title> |
| <p> |
| <code>Usage: hadoop fs -chmod [-R] <MODE[,MODE]... | OCTALMODE> URI [URI …]</code> |
| </p> |
| <p> |
| Change the permissions of files. With <code>-R</code>, 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 <a href="hdfs_permissions_guide.html">HDFS Admin Guide: Permissions</a>. |
| </p> |
| </section> |
| <section> |
| <title> chown </title> |
| <p> |
| <code>Usage: hadoop fs -chown [-R] [OWNER][:[GROUP]] URI [URI ]</code> |
| </p> |
| <p> |
| Change the owner of files. With <code>-R</code>, make the change recursively through the directory structure. The user must be a super-user. Additional information is in the <a href="hdfs_permissions_guide.html">HDFS Admin Guide: Permissions</a>. |
| </p> |
| </section> |
| <section> |
| <title>copyFromLocal</title> |
| <p> |
| <code>Usage: hadoop fs -copyFromLocal <localsrc> URI</code> |
| </p> |
| <p>Similar to <a href="#put"><strong>put</strong></a> command, except that the source is restricted to a local file reference. </p> |
| </section> |
| <section> |
| <title> copyToLocal</title> |
| <p> |
| <code>Usage: hadoop fs -copyToLocal [-ignorecrc] [-crc] URI <localdst></code> |
| </p> |
| <p> Similar to <a href="#get"><strong>get</strong></a> command, except that the destination is restricted to a local file reference.</p> |
| </section> |
| <section> |
| <title> count </title> |
| <p> |
| <code>Usage: hadoop fs -count [-q] <paths></code> |
| </p> |
| <p> |
| Count the number of directories, files and bytes under the paths that match the specified file pattern. The output columns are:<br/><code>DIR_COUNT, FILE_COUNT, CONTENT_SIZE FILE_NAME</code>. <br/><br/>The output columns with <code>-q</code> are:<br/><code>QUOTA, REMAINING_QUATA, SPACE_QUOTA, REMAINING_SPACE_QUOTA, DIR_COUNT, FILE_COUNT, CONTENT_SIZE, FILE_NAME</code>. |
| </p> |
| <p>Example:</p> |
| <ul> |
| <li> |
| <code> hadoop fs -count hdfs://nn1.example.com/file1 hdfs://nn2.example.com/file2 |
| </code> |
| </li> |
| <li> |
| <code> hadoop fs -count -q hdfs://nn1.example.com/file1 |
| </code> |
| </li> |
| </ul> |
| <p>Exit Code:</p> |
| <p> |
| <code> Returns 0 on success and -1 on error.</code> |
| </p> |
| </section> |
| <section> |
| <title> cp </title> |
| <p> |
| <code>Usage: hadoop fs -cp URI [URI …] <dest></code> |
| </p> |
| <p> |
| Copy files from source to destination. This command allows multiple sources as well in which case the destination must be a directory. |
| <br/> |
| Example:</p> |
| <ul> |
| <li> |
| <code> hadoop fs -cp /user/hadoop/file1 /user/hadoop/file2</code> |
| </li> |
| <li> |
| <code> hadoop fs -cp /user/hadoop/file1 /user/hadoop/file2 /user/hadoop/dir </code> |
| </li> |
| </ul> |
| <p>Exit Code:</p> |
| <p> |
| <code> Returns 0 on success and -1 on error.</code> |
| </p> |
| </section> |
| <section> |
| <title>du</title> |
| <p> |
| <code>Usage: hadoop fs -du URI [URI …]</code> |
| </p> |
| <p> |
| Displays aggregate length of files contained in the directory or the length of a file in case its just a file.<br/> |
| Example:<br/><code>hadoop fs -du /user/hadoop/dir1 /user/hadoop/file1 hdfs://nn.example.com/user/hadoop/dir1</code><br/> |
| Exit Code:<br/><code> Returns 0 on success and -1 on error. </code><br/></p> |
| </section> |
| <section> |
| <title> dus </title> |
| <p> |
| <code>Usage: hadoop fs -dus <args></code> |
| </p> |
| <p> |
| Displays a summary of file lengths. |
| </p> |
| </section> |
| <section> |
| <title> expunge </title> |
| <p> |
| <code>Usage: hadoop fs -expunge</code> |
| </p> |
| <p>Empty the Trash. Refer to <a href="hdfs_design.html">HDFS Architecture</a> for more information on Trash feature. |
| </p> |
| </section> |
| <section> |
| <title> get </title> |
| <p> |
| <code>Usage: hadoop fs -get [-ignorecrc] [-crc] <src> <localdst></code> |
| <br/> |
| </p> |
| <p> |
| Copy files to the local file system. Files that fail the CRC check may be copied with the |
| <code>-ignorecrc</code> option. Files and CRCs may be copied using the |
| <code>-crc</code> option. |
| </p> |
| <p>Example:</p> |
| <ul> |
| <li> |
| <code> hadoop fs -get /user/hadoop/file localfile </code> |
| </li> |
| <li> |
| <code> hadoop fs -get hdfs://nn.example.com/user/hadoop/file localfile</code> |
| </li> |
| </ul> |
| <p>Exit Code:</p> |
| <p> |
| <code> Returns 0 on success and -1 on error. </code> |
| </p> |
| </section> |
| <section> |
| <title> getmerge </title> |
| <p> |
| <code>Usage: hadoop fs -getmerge <src> <localdst> [addnl]</code> |
| </p> |
| <p> |
| Takes a source directory and a destination file as input and concatenates files in src into the destination local file. Optionally <code>addnl</code> can be set to enable adding a newline character at the end of each file. |
| </p> |
| </section> |
| <section> |
| <title> ls </title> |
| <p> |
| <code>Usage: hadoop fs -ls <args></code> |
| </p> |
| <p> |
| For a file returns stat on the file with the following format:<br/><code>filename <number of replicas> filesize modification_date modification_time permissions userid groupid</code><br/> |
| For a directory it returns list of its direct children as in unix. |
| A directory is listed as: <br/><code>dirname <dir> modification_time modification_time permissions userid groupid</code><br/> |
| Example:<br/><code>hadoop fs -ls /user/hadoop/file1 /user/hadoop/file2 hdfs://nn.example.com/user/hadoop/dir1 /nonexistentfile</code><br/> |
| Exit Code:<br/><code> Returns 0 on success and -1 on error. </code><br/></p> |
| </section> |
| <section> |
| <title>lsr</title> |
| <p><code>Usage: hadoop fs -lsr <args></code><br/> |
| Recursive version of <code>ls</code>. Similar to Unix <code>ls -R</code>. |
| </p> |
| </section> |
| <section> |
| <title> mkdir </title> |
| <p> |
| <code>Usage: hadoop fs -mkdir <paths></code> |
| <br/> |
| </p> |
| <p> |
| Takes path uri's as argument and creates directories. The behavior is much like unix mkdir -p creating parent directories along the path. |
| </p> |
| <p>Example:</p> |
| <ul> |
| <li> |
| <code>hadoop fs -mkdir /user/hadoop/dir1 /user/hadoop/dir2 </code> |
| </li> |
| <li> |
| <code>hadoop fs -mkdir hdfs://nn1.example.com/user/hadoop/dir hdfs://nn2.example.com/user/hadoop/dir |
| </code> |
| </li> |
| </ul> |
| <p>Exit Code:</p> |
| <p> |
| <code>Returns 0 on success and -1 on error.</code> |
| </p> |
| </section> |
| <section> |
| <title> moveFromLocal </title> |
| <p> |
| <code>Usage: dfs -moveFromLocal <localsrc> <dst></code> |
| </p> |
| <p>Similar to <a href="#put"><strong>put</strong></a> command, except that the source <code>localsrc</code> is deleted after it's copied. </p> |
| </section> |
| <section> |
| <title> moveToLocal</title> |
| <p> |
| <code>Usage: hadoop fs -moveToLocal [-crc] <src> <dst></code> |
| </p> |
| <p>Displays a "Not implemented yet" message.</p> |
| </section> |
| <section> |
| <title> mv </title> |
| <p> |
| <code>Usage: hadoop fs -mv URI [URI …] <dest></code> |
| </p> |
| <p> |
| 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 across filesystems is not permitted. |
| <br/> |
| Example: |
| </p> |
| <ul> |
| <li> |
| <code> hadoop fs -mv /user/hadoop/file1 /user/hadoop/file2</code> |
| </li> |
| <li> |
| <code> hadoop fs -mv hdfs://nn.example.com/file1 hdfs://nn.example.com/file2 hdfs://nn.example.com/file3 hdfs://nn.example.com/dir1</code> |
| </li> |
| </ul> |
| <p>Exit Code:</p> |
| <p> |
| <code> Returns 0 on success and -1 on error.</code> |
| </p> |
| </section> |
| <section> |
| <title> put </title> |
| <p> |
| <code>Usage: hadoop fs -put <localsrc> ... <dst></code> |
| </p> |
| <p>Copy single src, or multiple srcs from local file system to the destination filesystem. Also reads input from stdin and writes to destination filesystem.<br/> |
| </p> |
| <ul> |
| <li> |
| <code> hadoop fs -put localfile /user/hadoop/hadoopfile</code> |
| </li> |
| <li> |
| <code> hadoop fs -put localfile1 localfile2 /user/hadoop/hadoopdir</code> |
| </li> |
| <li> |
| <code> hadoop fs -put localfile hdfs://nn.example.com/hadoop/hadoopfile</code> |
| </li> |
| <li><code>hadoop fs -put - hdfs://nn.example.com/hadoop/hadoopfile</code><br/>Reads the input from stdin.</li> |
| </ul> |
| <p>Exit Code:</p> |
| <p> |
| <code> Returns 0 on success and -1 on error. </code> |
| </p> |
| </section> |
| <section> |
| <title> rm </title> |
| <p> |
| <code>Usage: hadoop fs -rm URI [URI …] </code> |
| </p> |
| <p> |
| Delete files specified as args. Only deletes non empty directory and files. Refer to rmr for recursive deletes.<br/> |
| Example: |
| </p> |
| <ul> |
| <li> |
| <code> hadoop fs -rm hdfs://nn.example.com/file /user/hadoop/emptydir </code> |
| </li> |
| </ul> |
| <p>Exit Code:</p> |
| <p> |
| <code> Returns 0 on success and -1 on error.</code> |
| </p> |
| </section> |
| <section> |
| <title> rmr </title> |
| <p> |
| <code>Usage: hadoop fs -rmr URI [URI …]</code> |
| </p> |
| <p>Recursive version of delete.<br/> |
| Example: |
| </p> |
| <ul> |
| <li> |
| <code> hadoop fs -rmr /user/hadoop/dir </code> |
| </li> |
| <li> |
| <code> hadoop fs -rmr hdfs://nn.example.com/user/hadoop/dir </code> |
| </li> |
| </ul> |
| <p>Exit Code:</p> |
| <p> |
| <code> Returns 0 on success and -1 on error. </code> |
| </p> |
| </section> |
| <section> |
| <title> setrep </title> |
| <p> |
| <code>Usage: hadoop fs -setrep [-R] <path></code> |
| </p> |
| <p> |
| Changes the replication factor of a file. -R option is for recursively increasing the replication factor of files within a directory. |
| </p> |
| <p>Example:</p> |
| <ul> |
| <li> |
| <code> hadoop fs -setrep -w 3 -R /user/hadoop/dir1 </code> |
| </li> |
| </ul> |
| <p>Exit Code:</p> |
| <p> |
| <code>Returns 0 on success and -1 on error. </code> |
| </p> |
| </section> |
| <section> |
| <title> stat </title> |
| <p> |
| <code>Usage: hadoop fs -stat URI [URI …]</code> |
| </p> |
| <p> |
| Returns the stat information on the path. |
| </p> |
| <p>Example:</p> |
| <ul> |
| <li> |
| <code> hadoop fs -stat path </code> |
| </li> |
| </ul> |
| <p>Exit Code:<br/> |
| <code> Returns 0 on success and -1 on error.</code></p> |
| </section> |
| <section> |
| <title> tail </title> |
| <p> |
| <code>Usage: hadoop fs -tail [-f] URI </code> |
| </p> |
| <p> |
| Displays last kilobyte of the file to stdout. -f option can be used as in Unix. |
| </p> |
| <p>Example:</p> |
| <ul> |
| <li> |
| <code> hadoop fs -tail pathname </code> |
| </li> |
| </ul> |
| <p>Exit Code: <br/> |
| <code> Returns 0 on success and -1 on error.</code></p> |
| </section> |
| <section> |
| <title> test </title> |
| <p> |
| <code>Usage: hadoop fs -test -[ezd] URI</code> |
| </p> |
| <p> |
| Options: <br/> |
| -e check to see if the file exists. Return 0 if true. <br/> |
| -z check to see if the file is zero length. Return 0 if true <br/> |
| -d check return 1 if the path is directory else return 0. <br/></p> |
| <p>Example:</p> |
| <ul> |
| <li> |
| <code> hadoop fs -test -e filename </code> |
| </li> |
| </ul> |
| </section> |
| <section> |
| <title> text </title> |
| <p> |
| <code>Usage: hadoop fs -text <src></code> |
| <br/> |
| </p> |
| <p> |
| Takes a source file and outputs the file in text format. The allowed formats are zip and TextRecordInputStream. |
| </p> |
| </section> |
| <section> |
| <title> touchz </title> |
| <p> |
| <code>Usage: hadoop fs -touchz URI [URI …]</code> |
| <br/> |
| </p> |
| <p> |
| Create a file of zero length. |
| </p> |
| <p>Example:</p> |
| <ul> |
| <li> |
| <code> hadoop -touchz pathname </code> |
| </li> |
| </ul> |
| <p>Exit Code:<br/> |
| <code> Returns 0 on success and -1 on error.</code></p> |
| </section> |
| </section> |
| </body> |
| </document> |