In this post there is a compilation of some of the frequently used HDFS commands with examples which can be used as reference.
All HDFS commands are invoked by the bin/hdfs script. Running the hdfs script without any arguments prints the description for all commands.
1- HDFS command to create a directory
hdfs dfs -mkdirExample– To create a new directory input inside the /user directory
hdfs dfs -mkdir /user/input2- HDFS command to list all the files
hdfs dfs -lsExample- To list content of the root directory in HDFS
hdfs dfs -ls /HDFS command to recursively list all the sub directories
hdfs dfs -ls -R /3- HDFS command To copy file from local to HDFS
hfds dfs -copyFromLocalExample– Copy file test.txt from local directory /usr/test to /user/input directory in HDFS
hdfs dfs -copyFromLocal /usr/test/aa.txt /user/input/If you want overwrite existing file use -f option
hdfs dfs -copyFromLocal -f /usr/test/aa.txt /user/input/4- put command is also used to copy file from local to HDFS
hfds dfs -putExample– HDFS command to copy the entire directory /usr/test to HDFS directory /user/input
hdfs dfs -put /usr/test /user/input5- To copy files with in HDFS
hdfs dfs -cpExample- Copy file /user/input/test/aa.txt in HDFS to /user/output in HDFS
hdfs dfs -cp /user/input/test/aa.txt /user/output/6- HDFS command to display free space
hdfs dfs -dfExample– With -h option to show output in human readable format
hdfs dfs -df -h7- HDFS command to copy file to local file system from HDFS
hdfs dfs -copyToLocalExample– Copy file part-r-00000 in HDFS location /user/output/ to /usr/Test
hdfs dfs -copyToLocal /user/output/part-r-00000 /usr/test8- You can also use get command to copy file to local file system from HDFS
hdfs dfs -getExample– Copy file part-r-00000 in HDFS location /user/output/ to /usr/Test with -f option to overwrite if exists.
hdfs dfs -get -f /user/output/part-r-00000 /home/knpcode/Documents/test9- HDFS command to delete a file in HDFS
hdfs dfs -rmExample– Deleting all the .txt files in /user/input/test directory
hdfs dfs -rm /user/input/test/*.txtHDFS command to recursively delete directory /user/input/test using -R (recursive) option
hdfs dfs -rm -R /user/input/test10- HDFS command to delete a directory.
hdfs dfs -rmdirIt will delete a directory only if it is empty.
11- To view content of a file in HDFS.
Hdfs dfs -catExample– HDFS command to display content of aa.txt file in directory /user/input
hdfs dfs -cat /user/input/test/aa.txt12- To change group association of files.
hdfs dfs -chgrpExample– Change group of /user/input/test/aa.txt file to acp.
hdfs dfs -chgrp acp /user/input/test/aa.txt13- To Change the permissions of files in HDFS.
hdfs dfs -chmodPermissions are same as in Linux. Read, write and execute permissions for user, group and others. if you want to provide read, write and execute permissions for all then you can use 777 as argument.
hdfs dfs -chmod 777 /user/input/test/aa.txtYou can also do the same thing using the following command.
hdfs dfs -chmod a+rwx /user/input/test/aa.txt14- To Change the owner of files.
hadoop fs -chown15- HDFS command to permanently delete files.
hdfs dfs -expunge16- To display the access control lists for file and directory.
hdfs dfs -getfaclExample– Getting owner, group and permission information for /user/input/test/aa.txt file.
hdfs dfs -getfacl /user/input/test/aa.txt17– HDFS command to change replication factor of a file.
hdfs dfs -setrepExample– Change the replication factor to two.
hdfs dfs -setrep 2 /user/input/test/aa.txt18- Getting help about commands
hdfs dfs -help19– Command to run the HDFS filesystem checking utility.
hdfs fsckExample– Running fsck for path /user/input
hdfs fsck /user/input20- HDFS command to print the version.
hdfs versionThat's all for the topic Frequently Used HDFS Commands With Examples. If something is missing or you have something to share about the topic please write a comment.
You may also like
- What is Hadoop
- HDFS Replica Placement Policy
- Namenode in Safemode
- HDFS Data Flow – File Read And Write in HDFS
- Checked Vs Unchecked Exception in Java
- Main Thread in Java
- Java ListIterator With Examples
- Generate PDF From XML in Java Using Apache FOP
- Java Program to Find Maximum And Minimum Number in a Matrix
- Spring Dependency Injection With Examples
No comments:
Post a Comment