Chapter 3 Familiarize yourself with common HDFS operations

Programmatically implement the following specified functions, and use the shell commands provided by Hadoop to accomplish the same tasks:

  1. Create a file txt in the "/home/hadoop/" directory of the local Linux file system, and enter some words at will.
  2. View file location locally (ls)
  3. Display file contents locally
  4. Use the command to upload "txt" in the local file system to the input directory of the current user directory in HDFS.
  5. View files in hdfs (-ls)
  6. Display the content of the file in hdfs
  7. delete the local txt file and view the directory
  8. Download the txt to the original local location from hdfs.
  9. delete txt from hdfs and view directory
mkdir hadoop
cd hadoop
touch test.txt
gedit test.txt
ls -al
gedit test.txt
cd /usr/local/hadoop
#Open hdfs 
./bin/hdfs dfs -mkdir /input ./bin/hdfs dfs -put ~/hadoop/test.txt /input
./bin/hdfs dfs -ls /input
./bin/hdfs dfs -cat /input/test.txt
cd ~/hadoop
rm -r test.txt
ls -al
#Enable hdfs
./bin/hdfs dfs -mkdir /input
./bin/hdfs dfs -get /input/test.txt ~/hadoop
./bin/hdfs dfs -rm -r /input/test.txt
./bin/hdfs dfs -ls

screenshot:

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324833555&siteId=291194637