Thursday, May 2, 2019

Hadoop HDFS Commands

Hadoop HDFS Commands

ls
Returns all the available files and subdirectories present under the root directory.
hadoop fs –ls /

cd  C:\hadoop-2.8.0\data\namenode
hadoop fs -mkdir  test1
hadoop fs -ls \
hadoop fs -mkdir -p /test1/Hadoop
hadoop fs -mkdir  /test1/Hadoop/tweeter_data

copyFromLocal
Copy a file from local filesytem to HDFS location.
hadoop fs –copyFromLocal Sample1.txt /test1/Hadoop/tweeter_data

put –
This hadoop command uploads a single file or multiple source files from local file system to hadoop distributed file system (HDFS).
hadoop fs –put Sample2.txt /test1/Hadoop/tweeter_data

moveFromLocal
This hadoop command functions similar to the put command but the source file will be deleted after copying.
hadoop fs –put Sample3.txt /test1/Hadoop/tweeter_data

du
Displays the disk usage for all the files available under a given directory.
hadoop fs –du /test1/Hadoop/

df
 Displas disk usage of current hadoop distributed file system.
hadoop fs –df

Expunge
This HDFS command empties the trash by deleting all the files and directories.
hadoop fs –expunge

Cat
This is similar to the cat command in Unix and displays the contents of a file.
hadoop fs –cat /test1/Hadoop/tweeter_data/Sample3.txt

cp
Copy files from one HDFS location to another HDFS location.
hadoop fs –cp /test1/Hadoop/tweeter_data/  /test2/

mv
Move files from one HDFS location to another HDFS location.
hadoop fs –mv /test2/  /test12/

rm
Removes the file or directory from the mentioned HDFS location.
hadoop fs –rm -r /test12/

tail
This hadoop command will show the last kilobyte of the file to stdout.
hadoop fs -tail /test1/Hadoop/tweeter_data/Sample3.txt

touchz
This command can be used to create a file of zero bytes size in HDFS filesystem.
hadoop fs -touchz /test1/URI.txt

tail
This command is used to show the last 1KB of the file.
hadoop fs -tail /test1/Hadoop/tweeter_data/Sample3.txt

count
This command is used to count the number of directories, files and bytes
hadoop fs -count /test1/Hadoop/