3/5/17

HADOOP FILE SYSTEM (HDFS) COMMANDS

Ls: List your directories/files on HDFS
[root@quickstart cloudera]# hdfs dfs -ls /
Found 9 items
drwxrwxrwx   - hdfs     supergroup          0 2016-08-10 14:35 /benchmarks
drwxr-xr-x   - hbase    supergroup          0 2016-12-30 22:17 /hbase
drwxr-xr-x   - cloudera supergroup          0 2016-12-29 04:31 /pavantest
drwxr-xr-x   - cloudera supergroup          0 2016-12-29 04:32 /pavantest1
drwxr-xr-x   - cloudera supergroup          0 2016-12-29 04:32 /pavantest2
drwxr-xr-x   - solr     solr                0 2016-08-10 14:37 /solr
drwxrwxrwt   - hdfs     supergroup          0 2016-12-19 22:39 /tmp
drwxr-xr-x   - hdfs     supergroup          0 2016-12-30 23:06 /user
drwxr-xr-x   - hdfs     supergroup          0 2016-08-10 14:37 /var


mkdir : Create directory on HDFS
[root@quickstart cloudera]# hdfs dfs -mkdir /sampledir
[root@quickstart cloudera]# hdfs dfs -mkdir /user/sampledir1
[root@quickstart cloudera]# hdfs dfs -ls /
Found 10 items
drwxrwxrwx   - hdfs     supergroup          0 2016-08-10 14:35 /benchmarks
drwxr-xr-x   - hbase    supergroup          0 2016-12-30 22:17 /hbase
drwxr-xr-x   - cloudera supergroup          0 2016-12-29 04:31 /pavantest
drwxr-xr-x   - cloudera supergroup          0 2016-12-29 04:32 /pavantest1
drwxr-xr-x   - cloudera supergroup          0 2016-12-29 04:32 /pavantest2
drwxr-xr-x   - root     supergroup          0 2016-12-30 23:18 /sampledir
drwxr-xr-x   - solr     solr                0 2016-08-10 14:37 /solr
drwxrwxrwt   - hdfs     supergroup          0 2016-12-19 22:39 /tmp
drwxr-xr-x   - hdfs     supergroup          0 2016-12-30 23:19 /user
drwxr-xr-x   - hdfs     supergroup          0 2016-08-10 14:37 /var

put:  Copy data from local FS to HDFS
[root@quickstart cloudera]# hdfs dfs -put sample.txt /sampledir
[root@quickstart cloudera]# hdfs dfs -ls /sampledir
Found 1 items
-rw-r--r--   1 root supergroup         75 2016-12-30 23:35 /sampledir/sample.txt

get: Copy data from HDFS to local FS
[root@quickstart cloudera]# pwd
/home/cloudera
[root@quickstart cloudera]# hdfs dfs -get /sampledir/sample.txt /home/cloudera
[root@quickstart cloudera]# ls
cloudera-manager  Documents  enterprise-deployment.json  file2.txt  longmsg.txt  Pictures    Templates
cm_api.py         Downloads  express-deployment.json     kerberos   Music        Public      Videos
Desktop           eclipse    file1.txt                   lib        parcels      sample.txt  workspace

cat:  View content of a file on HDFS.
[root@quickstart cloudera]# hdfs dfs -cat /sampledir/sample.txt
this is the file i wanto put in hsdfs
saaaaadasdsadsad
asdsadsadsadsadasda

cp:  Copy data from HDFS to HDFS
 [root@quickstart cloudera]# hdfs dfs -cp /sampledir/sample.txt /pavantest/
[root@quickstart cloudera]# hdfs dfs -ls /pavantest/
Found 1 items
-rw-r--r--   1 root supergroup         75 2016-12-31 00:06 /pavantest/sample.txt

mv:  similar to Unix mv command, it is used for moving a file from one directory to another within HDFS.
[root@quickstart cloudera]# hdfs dfs -ls /pavantest/
Found 1 items
-rw-r--r--   1 root supergroup         75 2016-12-31 00:06 /pavantest/sample.txt
[root@quickstart cloudera]# hdfs dfs -mv /pavantest/sample.txt /pavantest1/
[root@quickstart cloudera]# hdfs dfs -ls /pavantest/
[root@quickstart cloudera]# hdfs dfs -ls /pavantest1/
Found 1 items
-rw-r--r--   1 root supergroup         75 2016-12-31 00:06 /pavantest1/sample.txt

rm: Delete data from HDFS
[root@quickstart cloudera]# hdfs dfs -ls /pavantest1/
Found 1 items
-rw-r--r--   1 root supergroup         75 2016-12-31 00:06 /pavantest1/sample.txt
[root@quickstart cloudera]# hdfs dfs -rm /pavantest1/sample.txt
Deleted /pavantest1/sample.txt

[root@quickstart cloudera]# hdfs dfs -ls /pavantest1/

Google Q&A Forum