File and Directory Commands
File Management Commands
Uploading Files
Local to HDFS Upload
hdfs dfs -put /local/path/file.txt /hdfs/destination/path/
Copy from Local with Different Name
hdfs dfs -put /local/path/sourcefile.txt /hdfs/destination/newfile.txt
Downloading Files
HDFS to Local Download
hdfs dfs -get /hdfs/path/file.txt /local/destination/path/
Directory Operations
Creating Directories
hdfs dfs -mkdir /user/hadoop/newdirectory
hdfs dfs -mkdir -p /user/hadoop/nested/directory
Listing Directory Contents
Simple Listing
hdfs dfs -ls /user/hadoop
Recursive Listing
hdfs dfs -ls -R /user/hadoop
File and Directory Manipulation
Copying Files
hdfs dfs -cp /source/path/file.txt /destination/path/
Moving Files
hdfs dfs -mv /source/path/file.txt /destination/path/
Removing Files and Directories
hdfs dfs -rm /path/to/file.txt
hdfs dfs -rm -r /path/to/directory
Advanced File Operations
Checking File Existence
hdfs dfs -test -e /path/to/file.txt
File Size and Space Usage
graph LR
A[File Space Commands] --> B[-du: Directory Usage]
A --> C[-df: Filesystem Usage]
Disk Usage Commands
hdfs dfs -du /user/hadoop
hdfs dfs -df -h
Command Comparison Table
Command |
Purpose |
Example |
-put |
Upload files |
hdfs dfs -put local.txt /hdfs/path |
-get |
Download files |
hdfs dfs -get /hdfs/path/file.txt local.txt |
-mkdir |
Create directory |
hdfs dfs -mkdir /user/dir |
-rm |
Remove files/directories |
hdfs dfs -rm /path/file.txt |
LabEx Practice Tip
LabEx provides interactive Hadoop environments where you can practice these HDFS shell commands in a safe, controlled setting.
Best Practices
- Always verify paths before executing commands
- Use
-f
flag carefully to force operations
- Check disk space before large file transfers
- Use wildcards for bulk operations