Familiar with common HDFS operations

Create a file txt in the "/home/hadoop/" directory of the local Linux file system, and enter some words at will.

  1. mkdir hadoop
  2. cd hadoop
  3. touch 123.txt
  4. gedit 123.txt

View file location locally (ls)

  1. ls -al

Display file contents locally

  1. gedit 123.txt

Use the command to upload "txt" in the local file system to the input directory of the current user directory in HDFS.

  1.  cd /usr/local/hadoop
  2. ./sbin/start-dfs.sh
  3. ./bin/hdfs dfs -mkdir /input
  4. ./bin/hdfs dfs -put ~/hadoop/123.txt /input

View files in hdfs (-ls)

  1.  ./bin/hdfs dfs -ls /input

Display the content of the file in hdfs

  1.  ./bin/hdfs dfs -cat /input/123.txt

delete the local txt file and view the directory

  1. cd hadoop
  2.  rm -r 123.txt
  3. ls -al

Download the txt to the original local location from hdfs.

  1.  ./bin/hdfs dfs -get /input/123.txt ~/hadoop

delete txt from hdfs and view directory

  1.  ./bin/hdfs dfs -rm -r /input/123.txt
  2. ./bin/hdfs dfs -ls

Guess you like

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