데이터 베이스 MySQL 튜토리얼 HDFS命令完全手册-1

HDFS命令完全手册-1

Jun 07, 2016 pm 04:41 PM
hdfs linux 주문하다 수동

HDFS在设计上仿照Linux下的文件操作命令,所以对Linux文件命令熟悉的小伙伴在这里很好上手。另外在Hadoop DFS中没有pwd概念,所有都需要全路径。(本文基于版本2.5 CDH 5.2.1) 列出命令列表、格式和帮助,以及选择一个非参数文件配置的namenode。 hdfs dfs -

HDFS在设计上仿照Linux下的文件操作命令,所以对Linux文件命令熟悉的小伙伴在这里很好上手。另外在Hadoop DFS中没有pwd概念,所有都需要全路径。(本文基于版本2.5 CDH 5.2.1)
列出命令列表、格式和帮助,以及选择一个非参数文件配置的namenode。

hdfs dfs -usage
hadoop dfs -usage ls 
hadoop dfs -help
-fs <local|namenode:port>      specify a namenode
hdfs dfs -fs hdfs://test1:9000 -ls /
로그인 후 복사

——————————————————————————–
-df [-h] [path …] :
Shows the capacity, free and used space of the filesystem. If the filesystem has
multiple partitions, and no path to a particular partition is specified, then
the status of the root partitions will be shown.

$ hdfs dfs -df
Filesystem                 Size   Used     Available  Use%
hdfs://test1:9000  413544071168  98304  345612906496    0%
로그인 후 복사

——————————————————————————–
-mkdir [-p] path … :
Create a directory in specified location.

-p Do not fail if the directory already exists

-rmdir dir … :
Removes the directory entry specified by each directory argument, provided it is
empty.

hdfs dfs -mkdir /tmp
hdfs dfs -mkdir /tmp/txt
hdfs dfs -rmdir /tmp/txt
hdfs dfs -mkdir -p /tmp/txt/hello
로그인 후 복사

——————————————————————————–
-copyFromLocal [-f] [-p] localsrc … dst :
Identical to the -put command.

-copyToLocal [-p] [-ignoreCrc] [-crc] src … localdst :
Identical to the -get command.

-moveFromLocal localsrc …
Same as -put, except that the source is deleted after it’s copied.

-put [-f] [-p] localsrc …
Copy files from the local file system into fs. Copying fails if the file already
exists, unless the -f flag is given. Passing -p preserves access and
modification times, ownership and the mode. Passing -f overwrites the
destination if it already exists.

-get [-p] [-ignoreCrc] [-crc] src … localdst :
Copy files that match the file pattern src to the local name. src is kept.
When copying multiple files, the destination must b/e a directory. Passing -p
preserves access and modification times, ownership and the mode.

-getmerge [-nl] src localdst :
Get all the files in the directories that match the source file pattern and
merge and sort them to only one file on local fs. src is kept.

-nl Add a newline character at the end of each file.

-cat [-ignoreCrc] src … :
Fetch all files that match the file pattern src and display their content on
stdout.

#通配符? * {} []
hdfs dfs -cat /tmp/*.txt
Hello, Hadoop
Hello, HDFS
hdfs dfs -cat /tmp/h?fs.txt 
Hello, HDFS
hdfs dfs -cat /tmp/h{a,d}*.txt 
Hello, Hadoop
Hello, HDFS
hdfs dfs -cat /tmp/h[a-d]*.txt
Hello, Hadoop
Hello, HDFS
echo "Hello, Hadoop" > hadoop.txt
echo "Hello, HDFS" > hdfs.txt
dd if=/dev/zero of=/tmp/test.zero bs=1M count=1024
    1024+0 records in
    1024+0 records out
    1073741824 bytes (1.1 GB) copied, 0.93978 s, 1.1 GB/s
hdfs dfs -moveFromLocal /tmp/test.zero /tmp
hdfs dfs -put *.txt /tmp
로그인 후 복사

——————————————————————————–
-ls [-d] [-h] [-R] [path …] :
List the contents that match the specified file pattern. If path is not
specified, the contents of /user/currentUser will be listed. Directory entries
are of the form:
permissions – userId groupId sizeOfDirectory(in bytes)
modificationDate(yyyy-MM-dd HH:mm) directoryName

and file entries are of the form:
permissions numberOfReplicas userId groupId sizeOfFile(in bytes)
modificationDate(yyyy-MM-dd HH:mm) fileName

-d Directories are listed as plain files.
-h Formats the sizes of files in a human-readable fashion rather than a number
of bytes.
-R Recursively list the contents of directories.

hdfs dfs -ls /tmp
hdfs dfs -ls -d /tmp
hdfs dfs -ls -h /tmp
  Found 4 items
  -rw-r--r--   3 hdfs supergroup         14 2014-12-18 10:00 /tmp/hadoop.txt
  -rw-r--r--   3 hdfs supergroup         12 2014-12-18 10:00 /tmp/hdfs.txt
  -rw-r--r--   3 hdfs supergroup        1 G 2014-12-18 10:19 /tmp/test.zero
  drwxr-xr-x   - hdfs supergroup          0 2014-12-18 10:07 /tmp/txt
hdfs dfs -ls -R -h /tmp
  -rw-r--r--   3 hdfs supergroup         14 2014-12-18 10:00 /tmp/hadoop.txt
  -rw-r--r--   3 hdfs supergroup         12 2014-12-18 10:00 /tmp/hdfs.txt
  -rw-r--r--   3 hdfs supergroup        1 G 2014-12-18 10:19 /tmp/test.zero
  drwxr-xr-x   - hdfs supergroup          0 2014-12-18 10:07 /tmp/txt
  drwxr-xr-x   - hdfs supergroup          0 2014-12-18 10:07 /tmp/txt/hello
로그인 후 복사

——————————————————————————–
-checksum src … :
Dump checksum information for files that match the file pattern src to stdout.
Note that this requires a round-trip to a datanode storing each block of the
file, and thus is not efficient to run on a large number of files. The checksum
of a file depends on its content, block size and the checksum algorithm and
parameters used for creating the file.

hdfs dfs -checksum /tmp/test.zero
  /tmp/test.zero	MD5-of-262144MD5-of-512CRC32C	000002000000000000040000f960570129a4ef3a7e179073adceae97
로그인 후 복사

——————————————————————————–
-appendToFile localsrc … dst :
Appends the contents of all the given local files to the given dst file. The dst
file will be created if it does not exist. If localSrc is -, then the input is
read from stdin.

hdfs dfs -appendToFile *.txt hello.txt
hdfs dfs -cat hello.txt
  Hello, Hadoop
  Hello, HDFS
로그인 후 복사

——————————————————————————–
-tail [-f] file :
Show the last 1KB of the file.

hdfs dfs -tail -f hello.txt
#waiting for output. then Ctrl + C
#another terminal
hdfs dfs -appendToFile - hello.txt
#then type something
로그인 후 복사

——————————————————————————–
-cp [-f] [-p | -p[topax]] src …
Copy files that match the file pattern src to a destination. When copying
multiple files, the destination must be a directory. Passing -p preserves status
[topax] (timestamps, ownership, permission, ACLs, XAttr). If -p is specified
with no arg, then preserves timestamps, ownership, permission. If -pa is
permission. Passing -f overwrites the destination if it already exists. raw
namespace extended attributes are preserved if (1) they are supported (HDFS
only) and, (2) all of the source and target pathnames are in the /.reserved/raw
hierarchy. raw namespace xattr preservation is determined solely by the presence
(or absence) of the /.reserved/raw prefix and not by the -p option.
-mv src … dst :
Move files that match the specified file pattern src to a destination dst.
When moving multiple files, the destination must be a directory.
-rm [-f] [-r|-R] [-skipTrash] src … :
Delete all files that match the specified file pattern. Equivalent to the Unix
command “rm src”

-skipTrash option bypasses trash, if enabled, and immediately deletes src
-f If the file does not exist, do not display a diagnostic message or
modify the exit status to reflect an error.
-[rR] Recursively deletes directories
-stat [format] path … :
Print statistics about the file/directory at path in the specified format.
Format accepts filesize in blocks (%b), group name of owner(%g), filename (%n),
block size (%o), replication (%r), user name of owner(%u), modification date
(%y, %Y)

hdfs dfs -stat /tmp/hadoop.txt
    2014-12-18 02:00:08
hdfs dfs -cp -p -f /tmp/hello.txt /tmp/hello.txt.bak
hdfs dfs -stat /tmp/hadoop.txt.bak
hdfs dfs -rm /tmp/not_exists
    rm: `/tmp/not_exists': No such file or directory
echo $?
    1
hdfs dfs -rm -f /tmp/123321123123123
echo $?
0
로그인 후 복사

——————————————————————————–
-count [-q] path … :
Count the number of directories, files and bytes under the paths
that match the specified file pattern. The output columns are:
DIR_COUNT FILE_COUNT CONTENT_SIZE FILE_NAME or
QUOTA REMAINING_QUOTA SPACE_QUOTA REMAINING_SPACE_QUOTA
DIR_COUNT FILE_COUNT CONTENT_SIZE FILE_NAME

-du [-s] [-h] path … :
Show the amount of space, in bytes, used by the files that match the specified
file pattern. The following flags are optional:

-s Rather than showing the size of each individual file that matches the
pattern, shows the total (summary) size.
-h Formats the sizes of files in a human-readable fashion rather than a number
of bytes.

Note that, even without the -s option, this only shows size summaries one level
deep into a directory.

The output is in the form
size name(full path)

hdfs dfs -count /tmp
           3            3         1073741850 /tmp
hdfs dfs -du /tmp
    14          /tmp/hadoop.txt
    12          /tmp/hdfs.txt
    1073741824  /tmp/test.zero
    0           /tmp/txt
hdfs dfs -du -s /tmp
    1073741850  /tmp
hdfs dfs -du -s -h /tmp
    1.0 G  /tmp
로그인 후 복사

——————————————————————————–
-chgrp [-R] GROUP PATH… :
This is equivalent to -chown … :GROUP …

-chmod [-R] MODE[,MODE]… | OCTALMODE PATH… :
Changes permissions of a file. This works similar to the shell’s chmod command
with a few exceptions.

-R modifies the files recursively. This is the only option currently
supported.
MODE Mode is the same as mode used for the shell’s command. The only
letters recognized are ‘rwxXt’, e.g. +t,a+r,g-w,+rwx,o=r.
OCTALMODE Mode specifed in 3 or 4 digits. If 4 digits, the first may be 1 or
0 to turn the sticky bit on or off, respectively. Unlike the
shell command, it is not possible to specify only part of the
mode, e.g. 754 is same as u=rwx,g=rx,o=r.

If none of ‘augo’ is specified, ‘a’ is assumed and unlike the shell command, no
umask is applied.

-chown [-R] [OWNER][:[GROUP]] PATH… :
Changes owner and group of a file. This is similar to the shell’s chown command
with a few exceptions.

-R modifies the files recursively. This is the only option currently
supported.

If only the owner or group is specified, then only the owner or group is
modified. The owner and group names may only consist of digits, alphabet, and
any of [-_./@a-zA-Z0-9]. The names are case sensitive.

WARNING: Avoid using ‘.’ to separate user name and group though Linux allows it.
If user names have dots in them and you are using local file system, you might
see surprising results since the shell command ‘chown’ is used for local files.

-touchz path … :
Creates a file of zero length at path with current time as the timestamp of
that path. An error is returned if the file exists with non-zero length

hdfs dfs -mkdir -p /user/spark/tmp
hdfs dfs -chown -R spark:hadoop /user/spark
hdfs dfs -chmod -R 775 /user/spark/tmp
hdfs dfs -ls -d /user/spark/tmp
    drwxrwxr-x   - spark hadoop          0 2014-12-18 14:51 /user/spark/tmp
hdfs dfs -chmod +t /user/spark/tmp
#user:spark
    hdfs dfs -touchz /user/spark/tmp/own_by_spark
#user:hadoop
useradd -g hadoop hadoop
su - hadoop
id
    uid=502(hadoop) gid=492(hadoop) groups=492(hadoop)
hdfs dfs -rm /user/spark/tmp/own_by_spark
rm: Permission denied by sticky bit setting: user=hadoop, inode=own_by_spark
#使用超级管理员(dfs.permissions.superusergroup = hdfs),可以无视sticky位设置
로그인 후 복사

——————————————————————————–
-test -[defsz] path :
Answer various questions about path, with result via exit status.
-d return 0 if path is a directory.
-e return 0 if path exists.
-f return 0 if path is a file.
-s return 0 if file path is greater than zero bytes in size.
-z return 0 if file path is zero bytes in size, else return 1.

hdfs dfs -test -d /tmp
echo $?
    0
hdfs dfs -test -f /tmp/txt
echo $?
    1
로그인 후 복사

——————————————————————————–
-setrep [-R] [-w] rep path … :
Set the replication level of a file. If path is a directory then the command
recursively changes the replication factor of all files under the directory tree
rooted at path.
-w It requests that the command waits for the replication to complete. This
can potentially take a very long time.

hdfs fsck /tmp/test.zero -blocks -locations
    Average block replication:	3.0
hdfs dfs -setrep -w 4  /tmp/test.zero
    Replication 4 set: /tmp/test.zero
    Waiting for /tmp/test.zero .... done
hdfs fsck /tmp/test.zero -blocks
    Average block replication:	4.0
로그인 후 복사
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.

핫 AI 도구

Undresser.AI Undress

Undresser.AI Undress

사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover

AI Clothes Remover

사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool

Undress AI Tool

무료로 이미지를 벗다

Clothoff.io

Clothoff.io

AI 옷 제거제

Video Face Swap

Video Face Swap

완전히 무료인 AI 얼굴 교환 도구를 사용하여 모든 비디오의 얼굴을 쉽게 바꾸세요!

뜨거운 도구

메모장++7.3.1

메모장++7.3.1

사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전

SublimeText3 중국어 버전

중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기

스튜디오 13.0.1 보내기

강력한 PHP 통합 개발 환경

드림위버 CS6

드림위버 CS6

시각적 웹 개발 도구

SublimeText3 Mac 버전

SublimeText3 Mac 버전

신 수준의 코드 편집 소프트웨어(SublimeText3)

VSCODE에 필요한 컴퓨터 구성 VSCODE에 필요한 컴퓨터 구성 Apr 15, 2025 pm 09:48 PM

대 코드 시스템 요구 사항 : 운영 체제 : Windows 10 이상, MacOS 10.12 이상, Linux 배포 프로세서 : 최소 1.6GHz, 권장 2.0GHz 이상의 메모리 : 최소 512MB, 권장 4GB 이상의 저장 공간 : 최소 250MB, 권장 1GB 및 기타 요구 사항 : 안정 네트워크 연결, Xorg/Wayland (LINUX)

VSCODE는 확장자를 설치할 수 없습니다 VSCODE는 확장자를 설치할 수 없습니다 Apr 15, 2025 pm 07:18 PM

VS 코드 확장을 설치하는 이유는 다음과 같습니다. 네트워크 불안정성, 불충분 한 권한, 시스템 호환성 문제, C 코드 버전은 너무 오래된, 바이러스 백신 소프트웨어 또는 방화벽 간섭입니다. 네트워크 연결, 권한, 로그 파일, 업데이트 대 코드 업데이트, 보안 소프트웨어 비활성화 및 대 코드 또는 컴퓨터를 다시 시작하면 점차 문제를 해결하고 해결할 수 있습니다.

VScode 란 무엇입니까? VScode 란 무엇입니까? Apr 15, 2025 pm 06:45 PM

VS Code는 Full Name Visual Studio Code로, Microsoft가 개발 한 무료 및 오픈 소스 크로스 플랫폼 코드 편집기 및 개발 환경입니다. 광범위한 프로그래밍 언어를 지원하고 구문 강조 표시, 코드 자동 완료, 코드 스 니펫 및 스마트 프롬프트를 제공하여 개발 효율성을 향상시킵니다. 풍부한 확장 생태계를 통해 사용자는 디버거, 코드 서식 도구 및 GIT 통합과 같은 특정 요구 및 언어에 확장을 추가 할 수 있습니다. VS 코드에는 코드에서 버그를 신속하게 찾아서 해결하는 데 도움이되는 직관적 인 디버거도 포함되어 있습니다.

vScode를 Mac에 사용할 수 있습니다 vScode를 Mac에 사용할 수 있습니다 Apr 15, 2025 pm 07:36 PM

VS 코드는 Mac에서 사용할 수 있습니다. 강력한 확장, GIT 통합, 터미널 및 디버거가 있으며 풍부한 설정 옵션도 제공합니다. 그러나 특히 대규모 프로젝트 또는 고도로 전문적인 개발의 경우 VS 코드는 성능 또는 기능 제한을 가질 수 있습니다.

Apr 16, 2025 pm 07:39 PM

메모장은 Java 코드를 직접 실행할 수는 없지만 다른 도구를 사용하여 명령 줄 컴파일러 (Javac)를 사용하여 Bytecode 파일 (filename.class)을 생성하면 달성 할 수 있습니다. Java Interpreter (Java)를 사용하여 바이트 코드를 해석하고 코드를 실행하고 결과를 출력하십시오.

Linux의 주요 목적은 무엇입니까? Linux의 주요 목적은 무엇입니까? Apr 16, 2025 am 12:19 AM

Linux의 주요 용도에는 다음이 포함됩니다. 1. 서버 운영 체제, 2. 임베디드 시스템, 3. 데스크탑 운영 체제, 4. 개발 및 테스트 환경. Linux는이 분야에서 뛰어나 안정성, 보안 및 효율적인 개발 도구를 제공합니다.

vscode를 사용하는 방법 vscode를 사용하는 방법 Apr 15, 2025 pm 11:21 PM

Visual Studio Code (VSCODE)는 Microsoft가 개발 한 크로스 플랫폼, 오픈 소스 및 무료 코드 편집기입니다. 광범위한 프로그래밍 언어에 대한 가볍고 확장 성 및 지원으로 유명합니다. VSCODE를 설치하려면 공식 웹 사이트를 방문하여 설치 프로그램을 다운로드하고 실행하십시오. VScode를 사용하는 경우 새 프로젝트를 만들고 코드 편집, 디버그 코드, 프로젝트 탐색, VSCODE 확장 및 설정을 관리 할 수 ​​있습니다. VSCODE는 Windows, MacOS 및 Linux에서 사용할 수 있으며 여러 프로그래밍 언어를 지원하며 Marketplace를 통해 다양한 확장을 제공합니다. 이점은 경량, 확장 성, 광범위한 언어 지원, 풍부한 기능 및 버전이 포함됩니다.

git의 창고 주소를 확인하는 방법 git의 창고 주소를 확인하는 방법 Apr 17, 2025 pm 01:54 PM

git 저장소 주소를 보려면 다음 단계를 수행하십시오. 1. 명령 줄을 열고 리포지토리 디렉토리로 이동하십시오. 2. "git remote -v"명령을 실행하십시오. 3. 출력 및 해당 주소에서 저장소 이름을 봅니다.

See all articles