Bird
Raised Fist0
Hadoopdata~5 mins

HDFS command line interface in Hadoop - Cheat Sheet & Quick Revision

Choose your learning style10 modes available
Recall & Review
beginner
What is the purpose of the HDFS command line interface?
The HDFS command line interface allows users to interact with the Hadoop Distributed File System to manage files and directories, such as creating, deleting, and viewing files.
Click to reveal answer
beginner
Which command lists files and directories in HDFS?
The command hdfs dfs -ls lists files and directories in the current or specified HDFS directory.
Click to reveal answer
beginner
How do you copy a file from the local file system to HDFS?
Use the command hdfs dfs -put <local_path> <hdfs_path> to copy a file from your local machine to HDFS.
Click to reveal answer
intermediate
What command removes a file or directory in HDFS?
The command hdfs dfs -rm <path> removes a file, and hdfs dfs -rm -r <path> removes a directory recursively in HDFS.
Click to reveal answer
beginner
How can you display the contents of a file stored in HDFS?
Use hdfs dfs -cat <hdfs_file_path> to print the contents of a file stored in HDFS to the terminal.
Click to reveal answer
Which command shows the files in the root directory of HDFS?
Ahdfs dfs -cat /
Bhdfs dfs -put /
Chdfs dfs -ls /
Dhdfs dfs -rm /
How do you copy a file named 'data.txt' from local to HDFS directory '/user/hadoop/'?
Ahdfs dfs -get data.txt /user/hadoop/
Bhdfs dfs -cat data.txt /user/hadoop/
Chdfs dfs -rm data.txt /user/hadoop/
Dhdfs dfs -put data.txt /user/hadoop/
Which command removes a directory and all its contents in HDFS?
Ahdfs dfs -rm /dir
Bhdfs dfs -rm -r /dir
Chdfs dfs -ls /dir
Dhdfs dfs -cat /dir
What does the command hdfs dfs -cat /file.txt do?
ADisplays the file content
BLists the file details
CDeletes the file
DCopies the file to local
Which command copies a file from HDFS to the local file system?
Ahdfs dfs -get
Bhdfs dfs -put
Chdfs dfs -rm
Dhdfs dfs -ls
Explain how to list, add, and remove files in HDFS using the command line interface.
Think about commands for viewing, uploading, and deleting files.
You got /3 concepts.
    Describe the difference between the commands hdfs dfs -put and hdfs dfs -get.
    Consider the direction of file transfer.
    You got /2 concepts.

      Practice

      (1/5)
      1. What does the HDFS command hdfs dfs -ls /user/hadoop do?
      easy
      A. Uploads local files to /user/hadoop in HDFS
      B. Deletes the directory /user/hadoop from HDFS
      C. Lists all files and directories in the HDFS path /user/hadoop
      D. Displays the content of files in /user/hadoop

      Solution

      1. Step 1: Understand the command structure

        The command hdfs dfs -ls is used to list files and directories in HDFS.
      2. Step 2: Analyze the given path

        The path /user/hadoop specifies the directory to list.
      3. Final Answer:

        Lists all files and directories in the HDFS path /user/hadoop -> Option C
      4. Quick Check:

        hdfs dfs -ls lists files [OK]
      Hint: Remember: '-ls' always lists files in given HDFS path [OK]
      Common Mistakes:
      • Confusing '-ls' with '-rm' which deletes files
      • Thinking '-ls' uploads files
      • Assuming it shows file content
      2. Which of the following is the correct syntax to upload a local file data.txt to HDFS directory /user/hadoop?
      easy
      A. hdfs dfs -put /user/hadoop data.txt
      B. hdfs dfs -copyFromLocal /user/hadoop data.txt
      C. hdfs dfs -get data.txt /user/hadoop
      D. hdfs dfs -put data.txt /user/hadoop

      Solution

      1. Step 1: Identify the correct command for uploading

        -put uploads local files to HDFS, and the syntax is hdfs dfs -put <local_path> <hdfs_path>.
      2. Step 2: Match the syntax with options

        hdfs dfs -put data.txt /user/hadoop correctly places data.txt as local file and /user/hadoop as HDFS destination.
      3. Final Answer:

        hdfs dfs -put data.txt /user/hadoop -> Option D
      4. Quick Check:

        -put local_file hdfs_path is correct [OK]
      Hint: Remember: local file first, then HDFS path in '-put' [OK]
      Common Mistakes:
      • Swapping local and HDFS paths
      • Using '-get' which downloads files
      • Using '-copyFromLocal' with wrong argument order
      3. What will be the output of the command hdfs dfs -cat /user/hadoop/sample.txt if the file contains:
      Hello Hadoop
      Welcome to HDFS
      medium
      A. Lists the file details of sample.txt
      B. Prints the content of sample.txt to the console
      C. Deletes sample.txt from HDFS
      D. Uploads sample.txt to HDFS

      Solution

      1. Step 1: Understand the '-cat' command

        hdfs dfs -cat prints the content of a file in HDFS to the console.
      2. Step 2: Analyze the file content

        The file sample.txt contains two lines: 'Hello Hadoop' and 'Welcome to HDFS'.
      3. Final Answer:

        Prints the content of sample.txt to the console -> Option B
      4. Quick Check:

        -cat shows file content [OK]
      Hint: Use '-cat' to display file content in HDFS [OK]
      Common Mistakes:
      • Confusing '-cat' with '-ls' which lists files
      • Thinking it deletes files
      • Assuming it uploads files
      4. You run the command hdfs dfs -rm /user/hadoop/data.csv but get an error saying file not found. What is the most likely cause?
      medium
      A. The file /user/hadoop/data.csv does not exist in HDFS
      B. You used the wrong command; '-rm' cannot delete files
      C. You need to use '-put' to delete files
      D. The HDFS service is down

      Solution

      1. Step 1: Understand the error message

        The error 'file not found' means the specified file does not exist at the given path.
      2. Step 2: Check command correctness

        -rm is the correct command to delete files in HDFS, so the error is not due to wrong command.
      3. Final Answer:

        The file /user/hadoop/data.csv does not exist in HDFS -> Option A
      4. Quick Check:

        File missing causes 'file not found' error [OK]
      Hint: Check file existence before deleting with '-rm' [OK]
      Common Mistakes:
      • Assuming '-rm' is wrong command
      • Trying to delete with '-put'
      • Ignoring file path correctness
      5. You want to copy all files from local directory /local/data/ to HDFS directory /user/hadoop/data/ and then verify the files are uploaded. Which sequence of commands is correct?
      hard
      A. hdfs dfs -put /local/data/* /user/hadoop/data/ then hdfs dfs -ls /user/hadoop/data/
      B. hdfs dfs -get /local/data/* /user/hadoop/data/ then hdfs dfs -cat /user/hadoop/data/
      C. hdfs dfs -rm /local/data/* then hdfs dfs -ls /user/hadoop/data/
      D. hdfs dfs -copyToLocal /local/data/* /user/hadoop/data/ then hdfs dfs -rm /user/hadoop/data/

      Solution

      1. Step 1: Choose the correct upload command

        -put uploads local files to HDFS. Using /local/data/* uploads all files from local directory.
      2. Step 2: Verify files in HDFS

        hdfs dfs -ls /user/hadoop/data/ lists files in the HDFS directory to confirm upload.
      3. Final Answer:

        hdfs dfs -put /local/data/* /user/hadoop/data/ then hdfs dfs -ls /user/hadoop/data/ -> Option A
      4. Quick Check:

        Upload with '-put' then list with '-ls' [OK]
      Hint: Upload with '-put' then check with '-ls' [OK]
      Common Mistakes:
      • Using '-get' which downloads files
      • Deleting local files before upload
      • Using '-copyToLocal' which copies from HDFS to local
      Recommended

      Ready to prove it?

      Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

      10 questions~5 mineasy hard