在Ubuntu上使用HDFS(Hadoop分布式文件系统)命令,首先需要确保已经安装了Hadoop。以下是一些基本的HDFS命令及其用法:
确保Hadoop的环境变量已经配置好。编辑~/.bashrc
或~/.profile
文件,添加以下内容:
export HADOOP_HOME=/path/to/hadoop
export PATH=$PATH:$HADOOP_HOME/bin:$HADOOP_HOME/sbin
然后运行source ~/.bashrc
或source ~/.profile
使配置生效。
在终端中运行以下命令启动HDFS:
start-dfs.sh
在终端中运行以下命令停止HDFS:
stop-dfs.sh
hdfs dfs -ls /path/to/directory
hdfs dfs -mkdir /path/to/new/directory
hdfs dfs -rm -r /path/to/directory
hdfs dfs -rm /path/to/file
hdfs dfs -put /local/path/to/file /hdfs/path/to/destination
hdfs dfs -get /hdfs/path/to/source /local/path/to/destination
hdfs dfs -cat /path/to/file
hdfs dfs -cp /source/path /destination/path
hdfs dfs -mv /source/path /destination/path
hdfs dfs -mv /path/to/file /new/path/to/file
hdfs dfs -ls -l /path/to/file_or_directory
hdfs dfs -chmod 755 /path/to/file_or_directory
hdfs dfs -chown username:groupname /path/to/file_or_directory
hdfs dfsadmin -report
hdfs namenode -format
hdfs dfsadmin -safemode enter
hdfs dfsadmin -safemode leave
sudo
来执行。通过这些基本命令,你可以在Ubuntu上有效地管理和操作HDFS。