In an E-MapReduce (EMR) Hadoop cluster, you can run Alluxio shell commands or Hadoop shell commands to perform operations on files that are stored in the Alluxio file system. This topic describes the common commands that you can run to manage data.

Prerequisites

  • A Hadoop cluster is created, and Alluxio is selected from the optional services when you create the cluster. For more information, see Create a cluster.
  • You have logged on to the cluster. For more information, see Log on to a cluster.

Background information

The following table describes the common commands that you can run to manage data.
Command Description
mkdir

Creates a directory in the Alluxio file system.

cat

Queries the content of a file in Alluxio.

ls

Queries information about all files or subdirectories that you created in a specified directory. You must specify an absolute path when you query information about files and subdirectories.

mv

Moves files or directories from the source to the destination.

copyFromLocal

Uploads a local file to a specified directory of Alluxio.

copyToLocal

Downloads a file that is stored in a specified directory of Alluxio to a local directory.

rm

Removes a file from a specified directory of Alluxio.

For more information, see Alluxio.

mkdir

Creates a directory in the Alluxio file system.

  • Syntax:
    • Alluxio shell command:
      alluxio fs mkdir <path1> [path2] ... [pathn]
    • Hadoop shell command:
      hadoop dfs -mkdir alluxio://<path1> [path2] ... [pathn]
  • Examples:
    • Create a /dir directory in the Alluxio file system.
      alluxio fs mkdir /dir
      If the following information is returned, the /dir directory is created:
      Successfully created directory /dir
    • Create a /logs subdirectory in the /dir directory.
      alluxio fs mkdir /dir/logs
      If the following information is returned, the /logs subdirectory is created in the /dir directory:
      Successfully created directory /dir/logs

ls

Queries information about all files or subdirectories that you created in a specified directory. You must specify an absolute path when you query information about files and subdirectories.

  • Syntax:
    • Alluxio shell command:
      alluxio fs ls <path>
    • Hadoop shell command:
      hadoop dfs -ls alluxio://<path>
  • Examples:
    • View the information about the hello.txt file stored in the /tmp directory.
      alluxio fs ls /tmp/hello.txt
      ls-1
    • View the information about the /logs subdirectory in the /dir directory.
      alluxio fs ls /dir/logs
      ls-2

cat

Queries the content of a file in Alluxio.

  • Syntax:
    • Alluxio shell command:
      alluxio fs cat <path>
    • Hadoop shell command:
      hadoop dfs -cat alluxio://<path>
  • Example: Query the information about the hello.txt file stored in the /tmp3 directory.
    alluxio fs cat hello.txt
    The information shown in the following figure is returned, which is the content of the hello.txt file. cat-1

mv

Moves files or directories from the source to the destination.

  • Syntax:
    • Alluxio shell command:
      alluxio fs mv <path>
    • Hadoop shell command:
      hadoop dfs -mv alluxio://<path>
  • Examples:
    • Move the hello.txt file from the /tmp/ directory to the /tmp3/logs/ directory.
      alluxio fs mv /tmp/hello.txt /tmp3/logs/hello.txt
      You can run the ls command to view file movement. mv-1
    • Move the test directory from the /tmp/ directory to the /dir/sub-dir/ directory.
      hadoop fs -mv /tmp/test /dir/sub-dir/
      You can run the ls command to view directory movement. mv-2

copyFromLocal

Notice You can run an Alluxio shell command copyFromLocal or a Hadoop shell command put to upload a local file to a specified directory of Alluxio.

Uploads a local file to a specified directory of Alluxio.

  • Syntax:
    • Alluxio shell command:
      alluxio fs copyFromLocal <src> <remoteDst>
    • Hadoop shell command:
      hadoop dfs -put <src> alluxio://<remoteDst>
  • Example: Upload the local file hello_world.txt to the /dir/logs2 directory of Alluxio.
    alluxio fs copyFromLocal hello_world.txt /dir/logs2
    If the following information is returned, the file is uploaded:
    Copied file:///root/hello_world.txt to /dir/logs2

copyToLocal

Notice You can run an Alluxio shell command copyToLocal or a Hadoop shell command get to download a file that is stored in a specified directory of Alluxio to a local directory.

Downloads a file that is stored in a specified directory of Alluxio to a local directory.

  • Syntax:
    • Alluxio shell command:
      alluxio fs copyToLocal <src> <localDst>
    • Hadoop shell command:
      hadoop dfs -get <src> alluxio://<localDst>
  • Example: Download the hello_world2.txt file stored in the /dir/sub-dir/ directory of Alluxio to the local directory /emr.
    alluxio fs copyToLocal /dir/sub-dir/hello_world2.txt /emr
    If the following information is returned, the file is downloaded:
    Copied /dir/sub-dir/hello_world2.txt to file:///emr

rm

Removes a file from a specified directory of Alluxio.

  • Syntax:
    • Alluxio shell command:
      alluxio fs rm <path>
    • Hadoop shell command:
      hadoop dfs -rm alluxio://<path>
  • Example: Remove the hello_world.txt file from the /dir/logs2 directory of Alluxio.
    alluxio fs rm /dir/logs2/hello_world.txt
    If the following information is returned, the file is removed:
    /dir/logs2/hello_world.txt has been removed