Saturday, 2 January 2016

Hadoop: count: count number of files, direcotories, content size in a folder

“count” command is used to count the number of directories, files and bytes under the paths that match the specified file pattern.

Usage:
hadoop fs [generic options] -count [-q] [-h] <path> ...
 


$hadoop fs -count -h -v /user/cloudera/demo2
   DIR_COUNT   FILE_COUNT       CONTENT_SIZE PATHNAME
           1            5              8.7 M /user/cloudera/demo2
 




Previous                                                 Next                                                 Home

Hadoop: copyToLocal: Copy file from hdfs to local system

“copyToLocal” command is used to copy data from HDFS to local system.

Usage
hadoop fs [generic options] -copyToLocal [-p] [-ignoreCrc] [-crc] <src> ... <localdst>
 
Example
hadoop fs -copyToLocal /user/cloudera/demo4/a.txt /home/cloudera/Desktop/dir1 
 
Above snippet copy the file '/user/cloudera/demo4/a.txt' from HDFS to your system folder '/home/cloudera/Desktop/dir1'.
 
$ls /home/cloudera/Desktop/dir1
$
$hadoop fs -ls /user/cloudera/demo4
Found 3 items
-rw-r--r--   1 cloudera cloudera          2 2022-03-23 09:03 /user/cloudera/demo4/a.txt
-rw-r--r--   1 cloudera cloudera         35 2022-03-23 09:03 /user/cloudera/demo4/b.txt
-rw-r--r--   1 cloudera cloudera         55 2022-03-23 09:03 /user/cloudera/demo4/c.txt
$
$
$hadoop fs -copyToLocal /user/cloudera/demo4/a.txt /home/cloudera/Desktop/dir1
$
$ls /home/cloudera/Desktop/dir1
a.txt
 


Referred Articles




Previous                                                 Next                                                 Home

Hadoop: checksum

“checksum” command returns the checksum of a file. Checksum is s simple error-detection scheme in which each transmitted message is accompanied by a numerical value based on the number of set bits in the message

Usage
hadoop fs [generic options] -checksum <src> ...

$ hadoop fs -checksum /user/harikrishna_gurram/dir1/append.txt
/user/harikrishna_gurram/dir1/append.txt MD5-of-0MD5-of-512CRC32C 0000020000000000000000005b648c18626e3d21349dd4673afbd370

Note
Create Home directory on HDFS for your current user (if not created already)
         hadoop fs -mkdir -p /user/[current login user]
        
For my system, I used command like following.
         hadoop fs -mkdir -p /user/harikrishna_gurram

Referred Articles





Previous                                                 Next                                                 Home

Hadoop : appendToFile

“appendToFile” command append multiple files data to a file located in Hadoop file system.

Usage
hadoop fs [generic options] -appendToFile <localsrc> ...

file1.txt
I am file1

file2.txt
I am file2


$ hadoop fs -appendToFile /Users/harikrishna_gurram/file1.txt /Users/harikrishna_gurram/file2.txt /user/harikrishna_gurram/dir1/append.txt
$ 
$ hadoop fs -cat /user/harikrishna_gurram/dir1/append.txt
I am file1I am file2


Previous                                                 Next                                                 Home

Hadoop : cat : display contents of a file

“cat” command is used to display contents of a file

Usage:

hadoop fs [generic options] -cat [-ignoreCrc] <src> ...

$hadoop fs -cat /user/cloudera/demo4/b.txt
aaaaaaaaaaaaaaaaa
bbbbbbbbbbbbbbbb
 
Previous                                                 Next                                                 Home