Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

How to create a file in specified directory ?

avatar

Hi Guys,
I have user "Mark" and it have directory "Cards".
Now i want to create a file in this directory "Cards" .
I have tried below commands :
" mkdir cards"
" touch cards/largedeck.txt"
but file was not created in that directory.
NOTE : i am using AWS machine.
Thanks

1 ACCEPTED SOLUTION

avatar
Expert Contributor
@Mudassar Hussain

If you are running a hadoop cluster in your AWS EC-2 instance and trying to create a file or folder then below are the command to achieve the same:

su - hdfs
hdfs dfs -mkdir /Mark
hdfs dfs -mkdir /Mark/Cards	

Now to create a file in the specified folder you have to use touch command:

hdfs dfs -touchz /Mark/Cards/largedeck.txt

Here are some links which will help you to understand the same:

Apache Link for shell commands

HCC - Link

HDP-DocsLink

View solution in original post

4 REPLIES 4

avatar
Expert Contributor
@Mudassar Hussain

If you are running a hadoop cluster in your AWS EC-2 instance and trying to create a file or folder then below are the command to achieve the same:

su - hdfs
hdfs dfs -mkdir /Mark
hdfs dfs -mkdir /Mark/Cards	

Now to create a file in the specified folder you have to use touch command:

hdfs dfs -touchz /Mark/Cards/largedeck.txt

Here are some links which will help you to understand the same:

Apache Link for shell commands

HCC - Link

HDP-DocsLink

avatar

Thanks @Sandeep Kumar for your prompt reply.
I have done the above step but file is not shown in that directory. Please see the below scree. is everything right :
directory.jpg

avatar
Master Mentor

@Mudassar Hussain

The following two paths are completely different:

1. /user/Mark/cards

AND

2. /Mark/cards

.

You created the directory "/Mark/cards" in the "mkdir" commands

But you are trying to list the data of "/user/Mark/cards"

.

Please check the output of following command to find your file "largedeck.txt"

# hadoop fs -ls /Mark/cards

.

So to avoid confusion .. please make sure that when you are creating a directory on HDFS please define the full path.

avatar

@Jay Kumar SenSharmaThanks a lot!
I got the desired output. but why it is showing "hdfs" the owner instead of "Mark" .although i change the ownership.

56455-hdfsowner.jpg

Correct me where i was wrong :
First of all i created user "Mark"
[root@namenode] adduser Mark
then check the space for user :
[root@namenode] hadoop fs -ls /user
My user not shown in the list so i create a space for my user
[root@namenode] sudo -u hdfs hadoop fs - mkdir /user/Mark
[root@namenode] hadoop fs -ls /user (now user show in the list)
Change the ownership
[root@namenode] sudo -u hdfs hadoop fs -chown Mark:hdfs /user/Mark
Now i login to user hdfs
[hdfs@namenode] hdfs dfs -mkdir /user/Mark/cards
[hdfs@namenode] hdfs dfs -touchz /user/Mark/cards/largedeck.txt
now login with "Mark" user and then type
[Mark@namenode] hadoop fs -ls /user/Mark/cards
Thanks