SlideShare a Scribd company logo
1
2
www.beinghadoop.com
hadoopframework@gmail.com
www.facebook.com/hadoopinfo
Hadoop File system Commands:
The File system(FS) shell includes various shell like commands that directly interact
With the Hadoop Distributed File system, as well with other file system
That hadoop Supports such as Local Fs,Hftp Fs, S3 Fs and others.
3
4
The File or Directory which created in HDFS can be represented using two ways.
We can access using Local uri and HDFS uri representation.
The command….
hadoop fs –mkdir /user/cloudera/Ajay
Creates Ajay directory in Hdfs and can be represented as
/user/hadoop/Ajay.
We use this type of representation if you using hadoop is local mode installation.
(check ppt hadoop installation Types)
we can represent same directory with Hdfs URI
hdfs://localhost:8020/user/cloudera/Ajay
We use this type of representation if you are using Hadoop in
Psuedo Distributed Mode installation
We can also represent the Same Directory
Hdfs://128..0.0.1:8020/user/cloudera/Ajay
We use this type of representation if you are using Fully Distributed mode
Installation.
5
To copy a File sample.txt which is in your system
Drive or Folder to Hdfs..
Hadoop fs –put sample.txt /user/root/Ajay
Hadoop fs –put sample.txt hdfs://localhost:8020/user/root/Ajay
Localhost is we have configured all the nodes in one machine
Which is like single node Cluster.
Hadoop fs –put sample.txt hdfs://128.0.0.1:8020/user/root/Ajay
128.0.0.1 is the Node IP address, in which you want to copy the file.
We use this type in Multinode Hadoop Cluster
6
1. Hadoop fs ls:
Hadoop fs –ls used to list files and directories in HDFS.
-d Directories are listed as plain files.
-h Formats the sizes of files in kilo bytes format.
-R Recursively list the contents of directories.
Hadoop fs –ls
Hadoop fs –ls hdfs://localhost:8020/user/cloudera/Ajay
Hadoop fs –ls –R displays directories and its contents recursively.
Hadoop fs –ls –R
Hadoop fs –ls –R /user/cloudera/Ajay
2. Hadoop fs cat
Hadoop fs –cat used to displays the content of a file.
Hadoop fs –put hdfs://localhost:8020/user/cloudera/Ajay/test
7
3. Hadoop fs du:
Hadoop fs –du displays disk usage of file or directory in HDFs
Show s the amount of space in Bytes occupied by each file or directory in HDFS.
[cloudera@localhost ~]$ hadoop fs -du hdfs://localhost:8020/user/cloudera/Ajay
1333 hdfs://localhost:8020/user/cloudera/Ajay/pig_1403050574637.log
2341 hdfs://localhost:8020/user/cloudera/Ajay/pig_1407465524489.log
22 hdfs://localhost:8020/user/cloudera/Ajay/test
0 hdfs://localhost:8020/user/cloudera/Ajay/test3
114 hdfs://localhost:8020/user/cloudera/Ajay/wctest1
–s to display total no of bytes used by the directory in HDFS
[cloudera@localhost ~]$ hadoop fs -du -s hdfs://localhost:8020/user/cloudera/Ajay
3810 hdfs://localhost:8020/user/cloudera/Ajay
-h shows the amount of space in kilo bytes occupied by each file or directory in HDFS
[cloudera@localhost ~]$ hadoop fs -du -h hdfs://localhost:8020/user/cloudera/Ajay
1.3 K hdfs://localhost:8020/user/cloudera/Ajay/pig_1403050574637.log
2.3 K hdfs://localhost:8020/user/cloudera/Ajay/pig_1407465524489.log
22 hdfs://localhost:8020/user/cloudera/Ajay/test
0 hdfs://localhost:8020/user/cloudera/Ajay/test3
114 hdfs://localhost:8020/user/cloudera/Ajay/wctest1
8
4. Hadoop fs -put
Used to copy a file from your systems Folder to Hdfs.
In this Example I am copying the files from my Documents.
pig_1403050574637.log,
pig_1407465524489.log,
wctest1
Hdfs Directory Ajay.
You can use any type of URI to represent a directory in HDFS.
[cloudera@localhost ~]hadoop fs -put pig_1403050574637.log
hdfs://localhost:8020/user/cloudera/Ajay
[cloudera@localhost ~]$ hadoop fs -put pig_1407465524489.log
/user/cloudera/Ajay
[cloudera@localhost ~]$ hadoop fs -put wctest1
hdfs://127.0.0.1:8020/user/cloudera/Ajay
9
10
5. hadoop fs chgrp:
hadoop fs -chgrp used to change the group association of files. Optionally you can use the
-R option to change recursively through the directory structure.
hadoop fs -chgrp [-R] <NewGroupName> <file or directory name>
hadoop fs -chgrp -R Hadoopusr hdfs://localhost:8020/user/cloudera/prem
6. hadoop fs chmod:
hadoop fs -chmod is used to change the permissions of files. The -R option can be used to
recursively change the permissions of a directory structure.
hadoop fs -chmod [-R] <mode | octal mode> <file or directory name>
hadoop fs -chmod -R 777 hdfs://localhost:8020/user/cloudera/prem
7. hadoop fs chown:
hadoop fs -chown used to change the ownership of files. The -R option can be used to
recursively change the owner of a directory structure.
hadoop fs -chown [-R] <NewOwnerName>[:NewGroupName] <file or directory name>
11
8. Hadoop fs copyFromLocal:
This command only copies a file from Local file system to Hdfs File system.
Is case Sensitive.
I am copying a file test from my Documents.
hadoop fs -copyFromLocal test hdfs://localhost:8020/user/cloudera/Ajay
9 . Hadoop fs moveFromLocal:
This command only Moves a file from Local file system to Hdfs File System.
I am copying a file test3 from my Documetnts Folder.
hadoop fs -moveFromLocal test3 hdfs://localhost:8020/user/cloudera/Ajay
10. Hadoop fs –copyToLocal:
This command only copies a file from Hdfs to Local File system.
I am copying a file in Hdfs /user/cloudera/Ajay/test3 to my Documents.
hadoop fs -copyToLocal hdfs://localhost:8020/user/cloudera/Ajay/test3
/home/cloudera/Documents
12
13
11. Hadoop fs get:
Hadoop fs –get is command which copies a file to Local File system from HDFS.
Hadoo fs –get hdfs://localhost:8020/user/cloudera/Ajay/test3 /home/Documents/
12. Hadoop fs getmerge
-getmerge [-nl] <src> <localdst>
Get all the files in the directories that
match the source file pattern and merge and sort them to only
one file on local fs. <src> is kept.
-nl Adds a newline character at the end of each file.
[cloudera@localhost Documents]$ touch test4
[cloudera@localhost Documents]$ hadoop fs -getmerge hdfs://localhost:8020
/user/cloudera/Ajay/test /home/cloudera/Documents/test4
14
13. Hadoop setrep:
Hadoop fs –setrep to specify the replication factor for a file.
The default replication factor is 3, which is specified in core-site.xml
With the property dfs.replication=3.
It means all the blocks in Hdfs replicated 3 times.
The file test with replication factor 3, can be changed to replication factor 2
With the command setrep:
Hadoop fs –setrep -w 2 –R hdfs://localhost:8020/user/cloudera/Ajay/test
15
14. Hadoop fs test:
Hadoop fs –test [edz] tests whether the file or directory exists in Hdfs or not.
--e to check file exists or not
-d to check directory exists or not
-z to check the file is Zero size or not.
[cloudera@localhost ~]$ hadoop fs -test -e hdfs://localhost:8020/user/cloudera/Ajay/test
[cloudera@localhost ~]$ hadoop fs -test -d hdfs://localhost:8020/user/cloudera/Ajay
[cloudera@localhost ~]$ hadoop fs -test -z hdfs://localhost:8020/user/cloudera/Ajay/test3
[cloudera@localhost ~]$
It returns 0 if exists
16
15. Hadoop fs stat:
Print statistics information about the file/directory .
We can check the information
Blocks with %b
Groupname or owner with %g
Filename with %n
Replication with %r
User name of owner %u
Modification date with %y
%u), modification date (%y, %Y)
Hadoop fs -stat %r hdfs://localhost:8020/user/cloudera/Ajay/test
specifies the replication factor of a file test---2
hadoop fs -stat %u hdfs://localhost:8020/user/cloudera/Ajay/test
Output the user name—Ajay
hadoop fs -stat hdfs://localhost:8020/user/cloudera/Ajay
Outputs date and time when the directory Ajay is created
17
18
16 .Hadoop fs count:
Hadoop fs –count used to count the number of directories, files and bytes for
specified directory.
it displays
DIR_COUNT ,FILE_COUNT, CONTENT_SIZE FILE_NAME
Hadoop fs –count hdfs://localhost:8020/user/cloudera/Ajay
Hadoop fs –count -q
Displays the Quota information about directory,
(Refer dfsadmin PPT to assign quota to a directory)
It displays
QUOTA REMAINING_QUATA SPACE_QUOTA REMAINING_SPACE_QUOTA
DIR_COUNT FILE_COUNT CONTENT_SIZE FILE_NAME
Hadoop fs –count –q hdfs://localhost:8020/user/cloudera/Ajay
19
17.Hadoop fs rm
hadoop fs -rm used to delete files in HDFS
Hadoop fs –rm –r to delete directories in HDFS
Hadoop fs -rm [-f] [-r|-R] [-skipTrash] filepath
Hadoop fs -rm
-skipTrash The file can not be moved to trash
-f If the file does not exist, do not display a diagnostic
message or modify the exit status to reflect an error.
-[rR] Recursively deletes
[cloudera@localhost ~]$ hadoop fs -mkdir /user/cloudera/trashdemo
[cloudera@localhost ~]$ hadoop fs -touchz /user/cloudera/trashdemo/temp
[cloudera@localhost ~]$ hadoop fs -rm -r -skipTrash
hdfs://localhost:8020/user/cloudera/trashdemo
Deleted hdfs://localhost:8020/user/cloudera/trashdemo
20
18.Hadoop fs expunge:
Hadoop uses trash to store deleted files in HDFS
core-site.xml contains property fs.trash.interval
If you set Fs.trash.interval=0, means trash is disabled.
To enable trash specify amount of time file resides in Trash
Fs.trash.interval=100
I am creating a directory trashdemo and creating a file trashing in that directory.
And I deleted it with hadoop fs –rmr.
Trashdemo with the filele trashing moved to Trash.
To clear the trash Use hadoop fs –expunge.
hadoop fs -mkdir trashdemo
hadoop fs -touchz hdfs://localhost:8020/user/cloudera/trashdemo/trashing
hadoop fs -rm -r hdfs://localhost:8020/user/cloudera/trashdemo/trashing
Moved: 'hdfs://localhost:8020/user/cloudera/trashdemo/trashing‘
to trash at: hdfs://localhost:8020/user/cloudera/.Trash/Current
hadoop fs -expunge
14/08/17 22:52:24 INFO fs.TrashPolicyDefault: Created trash
checkpoint: /user/cloudera/.Trash/140817225224
hadoop fs –expunge
21
22
19.Hadoop fs touchz
Hadoop fs –touchz creates a zero length file in a specified directory.
Hadoop fs –touchz hdfs://locahost:8020/user/cloudera/ajay/zerosize
a file with the name zerosize with length zero bytes is create in the Directory ajay
20. Hadoop fs text
Hadoop fs –text takes a source file and outputs the file in text format.
The allowed formats are zip and TextRecordInputStream.
hadoop fs -text hdfs://localhost:8020/user/cloudera/Ajay/pig_1403050574637.log
23
21. Hadoop fs usage
Hadoop fs –usage
Displays the usage for given command or all commands if none is specified.
Hadoop fs –usage copyFromLocal
Displays how to use copyFromLocal command.
22. Hadoop fs tail:
Hadoop fs –tail Show the last 1KB of the file.
hadoop fs -tail
hdfs://localhost:8020/user/cloudera/Ajay/pig_1403050574637.l
og

More Related Content

What's hot (20)

PPTX
Understanding Hadoop
Mahendran Ponnusamy
 
PPTX
Basic command of hadoop
Ahmad Kabeer
 
PPTX
Hadoop introduction seminar presentation
puneet yadav
 
PPTX
Hadoop 20111215
exsuns
 
PDF
HDFS User Reference
Biju Nair
 
PPTX
12 linux archiving tools
Shay Cohen
 
PPTX
Hadoop 20111117
exsuns
 
PPTX
Hadoop HDFS Concepts
tutorialvillage
 
PPT
Hadoop file
HR Krutika Meheta
 
PDF
Interacting with hdfs
Pradeep Kumbhar
 
PDF
Introduction to Flume
Rupak Roy
 
PDF
Hadoop file
HR Krutika Meheta
 
PDF
Hdfs architecture
Aisha Siddiqa
 
PPT
Hadoop Architecture
Delhi/NCR HUG
 
PPTX
Hadoop HDFS Concepts
ProTechSkills Training
 
PPTX
Hadoop HDFS Detailed Introduction
Hanborq Inc.
 
ODP
Hadoop HDFS by rohitkapa
kapa rohit
 
PDF
Design and Research of Hadoop Distributed Cluster Based on Raspberry
IJRESJOURNAL
 
PPT
101 3.3 perform basic file management
Acácio Oliveira
 
DOCX
Hadoop installation
habeebulla g
 
Understanding Hadoop
Mahendran Ponnusamy
 
Basic command of hadoop
Ahmad Kabeer
 
Hadoop introduction seminar presentation
puneet yadav
 
Hadoop 20111215
exsuns
 
HDFS User Reference
Biju Nair
 
12 linux archiving tools
Shay Cohen
 
Hadoop 20111117
exsuns
 
Hadoop HDFS Concepts
tutorialvillage
 
Hadoop file
HR Krutika Meheta
 
Interacting with hdfs
Pradeep Kumbhar
 
Introduction to Flume
Rupak Roy
 
Hadoop file
HR Krutika Meheta
 
Hdfs architecture
Aisha Siddiqa
 
Hadoop Architecture
Delhi/NCR HUG
 
Hadoop HDFS Concepts
ProTechSkills Training
 
Hadoop HDFS Detailed Introduction
Hanborq Inc.
 
Hadoop HDFS by rohitkapa
kapa rohit
 
Design and Research of Hadoop Distributed Cluster Based on Raspberry
IJRESJOURNAL
 
101 3.3 perform basic file management
Acácio Oliveira
 
Hadoop installation
habeebulla g
 

Viewers also liked (20)

PPT
Римский корсаков снегурочка
Ninel Kek
 
PPT
Цветочные легенды
Ninel Kek
 
PPTX
High Performance Distributed Systems with CQRS
Jonathan Oliver
 
PPTX
Building Your First Apache Apex (Next Gen Big Data/Hadoop) Application
Apache Apex
 
PPTX
Intro to YARN (Hadoop 2.0) & Apex as YARN App (Next Gen Big Data)
Apache Apex
 
PPTX
бсп (обоб. урок)
HomichAlla
 
PPTX
правописание приставок урок№4
HomichAlla
 
PDF
Troubleshooting mysql-tutorial
james tong
 
PDF
Windowing in Apache Apex
Apache Apex
 
PDF
Towards True Elasticity of Spark-(Michael Le and Min Li, IBM)
Spark Summit
 
PDF
The 5 People in your Organization that grow Legacy Code
Roberto Cortez
 
PPTX
Introduction to Apache Apex and writing a big data streaming application
Apache Apex
 
PDF
Build your shiny new pc, with Pangoly
Pangoly
 
PPTX
HDFS Internals
Apache Apex
 
PDF
Hadoop Internals (2.3.0 or later)
Emilio Coppa
 
PDF
Introduction to UNIX Command-Lines with examples
Noé Fernández-Pozo
 
PPTX
Introduction to Real-Time Data Processing
Apache Apex
 
PDF
Apache Big Data EU 2016: Building Streaming Applications with Apache Apex
Apache Apex
 
PDF
Apache Spark in Depth: Core Concepts, Architecture & Internals
Anton Kirillov
 
PPTX
Intro to Apache Apex (next gen Hadoop) & comparison to Spark Streaming
Apache Apex
 
Римский корсаков снегурочка
Ninel Kek
 
Цветочные легенды
Ninel Kek
 
High Performance Distributed Systems with CQRS
Jonathan Oliver
 
Building Your First Apache Apex (Next Gen Big Data/Hadoop) Application
Apache Apex
 
Intro to YARN (Hadoop 2.0) & Apex as YARN App (Next Gen Big Data)
Apache Apex
 
бсп (обоб. урок)
HomichAlla
 
правописание приставок урок№4
HomichAlla
 
Troubleshooting mysql-tutorial
james tong
 
Windowing in Apache Apex
Apache Apex
 
Towards True Elasticity of Spark-(Michael Le and Min Li, IBM)
Spark Summit
 
The 5 People in your Organization that grow Legacy Code
Roberto Cortez
 
Introduction to Apache Apex and writing a big data streaming application
Apache Apex
 
Build your shiny new pc, with Pangoly
Pangoly
 
HDFS Internals
Apache Apex
 
Hadoop Internals (2.3.0 or later)
Emilio Coppa
 
Introduction to UNIX Command-Lines with examples
Noé Fernández-Pozo
 
Introduction to Real-Time Data Processing
Apache Apex
 
Apache Big Data EU 2016: Building Streaming Applications with Apache Apex
Apache Apex
 
Apache Spark in Depth: Core Concepts, Architecture & Internals
Anton Kirillov
 
Intro to Apache Apex (next gen Hadoop) & comparison to Spark Streaming
Apache Apex
 
Ad

Similar to Hadoop File System Shell Commands, (20)

PDF
an detailed notes on Hadoop_Shell_Commands.pdf
YASWANTHP717822I163
 
PDF
Hadoop-HDFS-commands.pdf hadoop commands
zirrakrupa123
 
PDF
394753714-hdfc-command-biga data tecnology
SupriyaGhosh51
 
PPTX
5c_BigData_Hadoop_HDFS.PPTX
Miguel720844
 
PPTX
Hadoop & HDFS for Beginners
Rahul Jain
 
PDF
General apache command for hadoop
Saum
 
PDF
BIGDATA ANALYTICS LAB MANUAL final.pdf
ANJALAI AMMAL MAHALINGAM ENGINEERING COLLEGE
 
PDF
Apache Hadoop Shell Rewrite
Allen Wittenauer
 
PDF
Intro to Hadoop Presentation at Carnegie Mellon - Silicon Valley
markgrover
 
PPTX
Hadoop HDFS
Madhur Nawandar
 
PPT
Hadoop ecosystem
tfmailru
 
PPTX
Bd class 2 complete
JigsawAcademy2014
 
PDF
Big data-cheat-sheet
masoodkhh
 
PDF
RHive tutorial - HDFS functions
Aiden Seonghak Hong
 
PDF
IOD 2013 - Crunch Big Data in the Cloud with IBM BigInsights and Hadoop lab s...
Leons Petražickis
 
PDF
hadoop architecture -Big data hadoop
jasikadogra
 
PDF
Hdfs java api
Trieu Dao Minh
 
PDF
Apache HDFS - Lab Assignment
Farzad Nozarian
 
PPT
Hadoop Tutorial
awesomesos
 
PPTX
Hadoop File System.pptx
AakashBerlia1
 
an detailed notes on Hadoop_Shell_Commands.pdf
YASWANTHP717822I163
 
Hadoop-HDFS-commands.pdf hadoop commands
zirrakrupa123
 
394753714-hdfc-command-biga data tecnology
SupriyaGhosh51
 
5c_BigData_Hadoop_HDFS.PPTX
Miguel720844
 
Hadoop & HDFS for Beginners
Rahul Jain
 
General apache command for hadoop
Saum
 
BIGDATA ANALYTICS LAB MANUAL final.pdf
ANJALAI AMMAL MAHALINGAM ENGINEERING COLLEGE
 
Apache Hadoop Shell Rewrite
Allen Wittenauer
 
Intro to Hadoop Presentation at Carnegie Mellon - Silicon Valley
markgrover
 
Hadoop HDFS
Madhur Nawandar
 
Hadoop ecosystem
tfmailru
 
Bd class 2 complete
JigsawAcademy2014
 
Big data-cheat-sheet
masoodkhh
 
RHive tutorial - HDFS functions
Aiden Seonghak Hong
 
IOD 2013 - Crunch Big Data in the Cloud with IBM BigInsights and Hadoop lab s...
Leons Petražickis
 
hadoop architecture -Big data hadoop
jasikadogra
 
Hdfs java api
Trieu Dao Minh
 
Apache HDFS - Lab Assignment
Farzad Nozarian
 
Hadoop Tutorial
awesomesos
 
Hadoop File System.pptx
AakashBerlia1
 
Ad

Recently uploaded (20)

PDF
The dynastic history of the Chahmana.pdf
PrachiSontakke5
 
PPTX
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
PDF
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
PDF
The-Ever-Evolving-World-of-Science (1).pdf/7TH CLASS CURIOSITY /1ST CHAPTER/B...
Sandeep Swamy
 
PPTX
Unit 2 COMMERCIAL BANKING, Corporate banking.pptx
AnubalaSuresh1
 
PPTX
Growth and development and milestones, factors
BHUVANESHWARI BADIGER
 
PDF
Lesson 2 - WATER,pH, BUFFERS, AND ACID-BASE.pdf
marvinnbustamante1
 
PPTX
CATEGORIES OF NURSING PERSONNEL: HOSPITAL & COLLEGE
PRADEEP ABOTHU
 
PDF
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
PPTX
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
PPTX
How to Create a PDF Report in Odoo 18 - Odoo Slides
Celine George
 
PPTX
2025 Winter SWAYAM NPTEL & A Student.pptx
Utsav Yagnik
 
PDF
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
PPTX
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
PPTX
How to Set Maximum Difference Odoo 18 POS
Celine George
 
PPTX
How to Set Up Tags in Odoo 18 - Odoo Slides
Celine George
 
PPTX
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 
PDF
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
PDF
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
PDF
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
The dynastic history of the Chahmana.pdf
PrachiSontakke5
 
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
The-Ever-Evolving-World-of-Science (1).pdf/7TH CLASS CURIOSITY /1ST CHAPTER/B...
Sandeep Swamy
 
Unit 2 COMMERCIAL BANKING, Corporate banking.pptx
AnubalaSuresh1
 
Growth and development and milestones, factors
BHUVANESHWARI BADIGER
 
Lesson 2 - WATER,pH, BUFFERS, AND ACID-BASE.pdf
marvinnbustamante1
 
CATEGORIES OF NURSING PERSONNEL: HOSPITAL & COLLEGE
PRADEEP ABOTHU
 
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
How to Create a PDF Report in Odoo 18 - Odoo Slides
Celine George
 
2025 Winter SWAYAM NPTEL & A Student.pptx
Utsav Yagnik
 
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
How to Set Maximum Difference Odoo 18 POS
Celine George
 
How to Set Up Tags in Odoo 18 - Odoo Slides
Celine George
 
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 

Hadoop File System Shell Commands,

  • 1. 1
  • 3. Hadoop File system Commands: The File system(FS) shell includes various shell like commands that directly interact With the Hadoop Distributed File system, as well with other file system That hadoop Supports such as Local Fs,Hftp Fs, S3 Fs and others. 3
  • 4. 4
  • 5. The File or Directory which created in HDFS can be represented using two ways. We can access using Local uri and HDFS uri representation. The command…. hadoop fs –mkdir /user/cloudera/Ajay Creates Ajay directory in Hdfs and can be represented as /user/hadoop/Ajay. We use this type of representation if you using hadoop is local mode installation. (check ppt hadoop installation Types) we can represent same directory with Hdfs URI hdfs://localhost:8020/user/cloudera/Ajay We use this type of representation if you are using Hadoop in Psuedo Distributed Mode installation We can also represent the Same Directory Hdfs://128..0.0.1:8020/user/cloudera/Ajay We use this type of representation if you are using Fully Distributed mode Installation. 5
  • 6. To copy a File sample.txt which is in your system Drive or Folder to Hdfs.. Hadoop fs –put sample.txt /user/root/Ajay Hadoop fs –put sample.txt hdfs://localhost:8020/user/root/Ajay Localhost is we have configured all the nodes in one machine Which is like single node Cluster. Hadoop fs –put sample.txt hdfs://128.0.0.1:8020/user/root/Ajay 128.0.0.1 is the Node IP address, in which you want to copy the file. We use this type in Multinode Hadoop Cluster 6
  • 7. 1. Hadoop fs ls: Hadoop fs –ls used to list files and directories in HDFS. -d Directories are listed as plain files. -h Formats the sizes of files in kilo bytes format. -R Recursively list the contents of directories. Hadoop fs –ls Hadoop fs –ls hdfs://localhost:8020/user/cloudera/Ajay Hadoop fs –ls –R displays directories and its contents recursively. Hadoop fs –ls –R Hadoop fs –ls –R /user/cloudera/Ajay 2. Hadoop fs cat Hadoop fs –cat used to displays the content of a file. Hadoop fs –put hdfs://localhost:8020/user/cloudera/Ajay/test 7
  • 8. 3. Hadoop fs du: Hadoop fs –du displays disk usage of file or directory in HDFs Show s the amount of space in Bytes occupied by each file or directory in HDFS. [cloudera@localhost ~]$ hadoop fs -du hdfs://localhost:8020/user/cloudera/Ajay 1333 hdfs://localhost:8020/user/cloudera/Ajay/pig_1403050574637.log 2341 hdfs://localhost:8020/user/cloudera/Ajay/pig_1407465524489.log 22 hdfs://localhost:8020/user/cloudera/Ajay/test 0 hdfs://localhost:8020/user/cloudera/Ajay/test3 114 hdfs://localhost:8020/user/cloudera/Ajay/wctest1 –s to display total no of bytes used by the directory in HDFS [cloudera@localhost ~]$ hadoop fs -du -s hdfs://localhost:8020/user/cloudera/Ajay 3810 hdfs://localhost:8020/user/cloudera/Ajay -h shows the amount of space in kilo bytes occupied by each file or directory in HDFS [cloudera@localhost ~]$ hadoop fs -du -h hdfs://localhost:8020/user/cloudera/Ajay 1.3 K hdfs://localhost:8020/user/cloudera/Ajay/pig_1403050574637.log 2.3 K hdfs://localhost:8020/user/cloudera/Ajay/pig_1407465524489.log 22 hdfs://localhost:8020/user/cloudera/Ajay/test 0 hdfs://localhost:8020/user/cloudera/Ajay/test3 114 hdfs://localhost:8020/user/cloudera/Ajay/wctest1 8
  • 9. 4. Hadoop fs -put Used to copy a file from your systems Folder to Hdfs. In this Example I am copying the files from my Documents. pig_1403050574637.log, pig_1407465524489.log, wctest1 Hdfs Directory Ajay. You can use any type of URI to represent a directory in HDFS. [cloudera@localhost ~]hadoop fs -put pig_1403050574637.log hdfs://localhost:8020/user/cloudera/Ajay [cloudera@localhost ~]$ hadoop fs -put pig_1407465524489.log /user/cloudera/Ajay [cloudera@localhost ~]$ hadoop fs -put wctest1 hdfs://127.0.0.1:8020/user/cloudera/Ajay 9
  • 10. 10
  • 11. 5. hadoop fs chgrp: hadoop fs -chgrp used to change the group association of files. Optionally you can use the -R option to change recursively through the directory structure. hadoop fs -chgrp [-R] <NewGroupName> <file or directory name> hadoop fs -chgrp -R Hadoopusr hdfs://localhost:8020/user/cloudera/prem 6. hadoop fs chmod: hadoop fs -chmod is used to change the permissions of files. The -R option can be used to recursively change the permissions of a directory structure. hadoop fs -chmod [-R] <mode | octal mode> <file or directory name> hadoop fs -chmod -R 777 hdfs://localhost:8020/user/cloudera/prem 7. hadoop fs chown: hadoop fs -chown used to change the ownership of files. The -R option can be used to recursively change the owner of a directory structure. hadoop fs -chown [-R] <NewOwnerName>[:NewGroupName] <file or directory name> 11
  • 12. 8. Hadoop fs copyFromLocal: This command only copies a file from Local file system to Hdfs File system. Is case Sensitive. I am copying a file test from my Documents. hadoop fs -copyFromLocal test hdfs://localhost:8020/user/cloudera/Ajay 9 . Hadoop fs moveFromLocal: This command only Moves a file from Local file system to Hdfs File System. I am copying a file test3 from my Documetnts Folder. hadoop fs -moveFromLocal test3 hdfs://localhost:8020/user/cloudera/Ajay 10. Hadoop fs –copyToLocal: This command only copies a file from Hdfs to Local File system. I am copying a file in Hdfs /user/cloudera/Ajay/test3 to my Documents. hadoop fs -copyToLocal hdfs://localhost:8020/user/cloudera/Ajay/test3 /home/cloudera/Documents 12
  • 13. 13
  • 14. 11. Hadoop fs get: Hadoop fs –get is command which copies a file to Local File system from HDFS. Hadoo fs –get hdfs://localhost:8020/user/cloudera/Ajay/test3 /home/Documents/ 12. Hadoop fs getmerge -getmerge [-nl] <src> <localdst> Get all the files in the directories that match the source file pattern and merge and sort them to only one file on local fs. <src> is kept. -nl Adds a newline character at the end of each file. [cloudera@localhost Documents]$ touch test4 [cloudera@localhost Documents]$ hadoop fs -getmerge hdfs://localhost:8020 /user/cloudera/Ajay/test /home/cloudera/Documents/test4 14
  • 15. 13. Hadoop setrep: Hadoop fs –setrep to specify the replication factor for a file. The default replication factor is 3, which is specified in core-site.xml With the property dfs.replication=3. It means all the blocks in Hdfs replicated 3 times. The file test with replication factor 3, can be changed to replication factor 2 With the command setrep: Hadoop fs –setrep -w 2 –R hdfs://localhost:8020/user/cloudera/Ajay/test 15
  • 16. 14. Hadoop fs test: Hadoop fs –test [edz] tests whether the file or directory exists in Hdfs or not. --e to check file exists or not -d to check directory exists or not -z to check the file is Zero size or not. [cloudera@localhost ~]$ hadoop fs -test -e hdfs://localhost:8020/user/cloudera/Ajay/test [cloudera@localhost ~]$ hadoop fs -test -d hdfs://localhost:8020/user/cloudera/Ajay [cloudera@localhost ~]$ hadoop fs -test -z hdfs://localhost:8020/user/cloudera/Ajay/test3 [cloudera@localhost ~]$ It returns 0 if exists 16
  • 17. 15. Hadoop fs stat: Print statistics information about the file/directory . We can check the information Blocks with %b Groupname or owner with %g Filename with %n Replication with %r User name of owner %u Modification date with %y %u), modification date (%y, %Y) Hadoop fs -stat %r hdfs://localhost:8020/user/cloudera/Ajay/test specifies the replication factor of a file test---2 hadoop fs -stat %u hdfs://localhost:8020/user/cloudera/Ajay/test Output the user name—Ajay hadoop fs -stat hdfs://localhost:8020/user/cloudera/Ajay Outputs date and time when the directory Ajay is created 17
  • 18. 18 16 .Hadoop fs count: Hadoop fs –count used to count the number of directories, files and bytes for specified directory. it displays DIR_COUNT ,FILE_COUNT, CONTENT_SIZE FILE_NAME Hadoop fs –count hdfs://localhost:8020/user/cloudera/Ajay Hadoop fs –count -q Displays the Quota information about directory, (Refer dfsadmin PPT to assign quota to a directory) It displays QUOTA REMAINING_QUATA SPACE_QUOTA REMAINING_SPACE_QUOTA DIR_COUNT FILE_COUNT CONTENT_SIZE FILE_NAME Hadoop fs –count –q hdfs://localhost:8020/user/cloudera/Ajay
  • 19. 19 17.Hadoop fs rm hadoop fs -rm used to delete files in HDFS Hadoop fs –rm –r to delete directories in HDFS Hadoop fs -rm [-f] [-r|-R] [-skipTrash] filepath Hadoop fs -rm -skipTrash The file can not be moved to trash -f If the file does not exist, do not display a diagnostic message or modify the exit status to reflect an error. -[rR] Recursively deletes [cloudera@localhost ~]$ hadoop fs -mkdir /user/cloudera/trashdemo [cloudera@localhost ~]$ hadoop fs -touchz /user/cloudera/trashdemo/temp [cloudera@localhost ~]$ hadoop fs -rm -r -skipTrash hdfs://localhost:8020/user/cloudera/trashdemo Deleted hdfs://localhost:8020/user/cloudera/trashdemo
  • 20. 20 18.Hadoop fs expunge: Hadoop uses trash to store deleted files in HDFS core-site.xml contains property fs.trash.interval If you set Fs.trash.interval=0, means trash is disabled. To enable trash specify amount of time file resides in Trash Fs.trash.interval=100 I am creating a directory trashdemo and creating a file trashing in that directory. And I deleted it with hadoop fs –rmr. Trashdemo with the filele trashing moved to Trash. To clear the trash Use hadoop fs –expunge. hadoop fs -mkdir trashdemo hadoop fs -touchz hdfs://localhost:8020/user/cloudera/trashdemo/trashing hadoop fs -rm -r hdfs://localhost:8020/user/cloudera/trashdemo/trashing Moved: 'hdfs://localhost:8020/user/cloudera/trashdemo/trashing‘ to trash at: hdfs://localhost:8020/user/cloudera/.Trash/Current hadoop fs -expunge 14/08/17 22:52:24 INFO fs.TrashPolicyDefault: Created trash checkpoint: /user/cloudera/.Trash/140817225224 hadoop fs –expunge
  • 21. 21
  • 22. 22 19.Hadoop fs touchz Hadoop fs –touchz creates a zero length file in a specified directory. Hadoop fs –touchz hdfs://locahost:8020/user/cloudera/ajay/zerosize a file with the name zerosize with length zero bytes is create in the Directory ajay 20. Hadoop fs text Hadoop fs –text takes a source file and outputs the file in text format. The allowed formats are zip and TextRecordInputStream. hadoop fs -text hdfs://localhost:8020/user/cloudera/Ajay/pig_1403050574637.log
  • 23. 23 21. Hadoop fs usage Hadoop fs –usage Displays the usage for given command or all commands if none is specified. Hadoop fs –usage copyFromLocal Displays how to use copyFromLocal command. 22. Hadoop fs tail: Hadoop fs –tail Show the last 1KB of the file. hadoop fs -tail hdfs://localhost:8020/user/cloudera/Ajay/pig_1403050574637.l og