[AIX 운영 체제와 장치 관리 43] 디렉터리 — 디렉터리 종류와 구성, 경로 이름, mkdir·mvdir·pwd·cd·cp·ls·rmdir·dircmp
https://archive.horanglab.com/posts/aix-osdev-43
핵심 정리
- 디렉터리는 파일이나 하위 디렉터리 이름과 i-node 번호로 된 항목을 담는 특수 파일입니다. i-node에는 흩어진 데이터 블록 주소와 수정·접근 시간, 접근 모드, 링크 수, 소유자, 형식이 기록됩니다.
- 모든 디렉터리에는 자신(
.)과 부모(..) 항목이 있습니다. 경로 이름은 1023자를 넘을 수 없고, 절대 경로는/로 시작하며 상대 경로는 현재 디렉터리에서 시작합니다. mkdir -p는 없는 상위 디렉터리를 함께 만들고-m으로 권한을 정합니다. mvdir은 대상이 있으면 그 아래로 옮기고 없으면 이름을 바꿉니다.ls -l의 첫 글자는 형식(d, b, c, l, p, s, -), 다음 아홉 글자는 소유자·그룹·기타 권한이며,-e는 확장 보안 정보 여부(+)를 11번째 글자로 더합니다.- rmdir은 빈 디렉터리만 지우며 부모 디렉터리에 쓰기 권한이 있어야 합니다. dircmp는 두 디렉터리의 파일 이름과 내용을 비교합니다.
| 항목 | 내용 |
|---|---|
| 버전 | AIX 6.1 (5.3판과 거의 같음) |
| 원문 | Operating system and device management — 5.3판 131138쪽, 6.1판 460467쪽 |
| 관련 명령어 | mkdir, mvdir, pwd, cd, cp, ls, rm, rmdir, dircmp, df, ln |
| 관련 변수 | $HOME, $CDPATH, $COLUMNS |
디렉터리는 파일이나 다른 디렉터리에 접근하는 데 필요한 정보만 담는 독특한 형식의 파일입니다. 그래서 디렉터리는 다른 형식의 파일보다 공간을 적게 차지합니다.
파일 시스템은 디렉터리 묶음과 그 안의 파일로 이루어집니다. 파일 시스템은 흔히 거꾸로 선 나무로 나타냅니다. 슬래시(/) 기호로 나타내는 루트 디렉터리는 파일 시스템을 정의하며 파일 시스템 트리 그림 맨 위에 나옵니다.
트리 그림에서 디렉터리는 루트 디렉터리에서 아래로 갈라지며 파일과 하위 디렉터리를 모두 담을 수 있습니다. 갈라짐은 디렉터리 구조를 지나 파일 시스템의 모든 객체로 가는 고유한 경로를 만듭니다.
파일 모음은 디렉터리에 저장합니다. 이런 파일 모음은 서로 관련된 경우가 많아 디렉터리 구조에 저장하면 정리된 상태를 유지합니다.
파일은 읽거나 쓸 수 있는 데이터 모음입니다. 파일은 직접 만든 프로그램, 쓴 텍스트, 얻은 데이터, 쓰는 장치일 수 있습니다. 명령, 프린터, 터미널, 서신, 응용 프로그램이 모두 파일에 저장됩니다. 그래서 사용자는 시스템의 다양한 요소에 한결같은 방식으로 접근할 수 있고 파일 시스템은 큰 유연성을 얻습니다.
디렉터리로 파일과 다른 디렉터리를 묶어 파일 시스템을 모듈식 계층으로 정리할 수 있어 파일 시스템 구조에 유연성과 깊이를 줍니다.
디렉터리에는 디렉터리 항목이 있습니다. 각 항목에는 파일이나 하위 디렉터리 이름과 인덱스 노드 참조 번호(i-node 번호)가 있습니다. 속도를 높이고 디스크 공간을 잘 쓰려고 파일 데이터는 컴퓨터 메모리의 여러 위치에 저장됩니다. i-node 번호에는 파일에 딸린 흩어진 데이터 블록을 모두 찾는 데 쓰는 주소가 들어 있습니다. i-node 번호는 수정·접근 시간, 접근 모드, 링크 수, 파일 소유자, 파일 형식 같은 파일의 다른 정보도 기록합니다.
디렉터리는 특별한 명령 모음으로 다룹니다. 예를 들어 ln 명령으로 디렉터리 항목을 만들어 한 파일의 여러 이름을 같은 i-node 번호에 링크할 수 있습니다.
디렉터리에는 시스템의 모든 사용자가 보면 안 되는 정보가 들어 있는 경우가 많으므로 디렉터리 접근을 보호할 수 있습니다. 디렉터리 권한을 설정해 누가 디렉터리에 접근할 수 있는지, 또 어느 사용자가(있다면) 디렉터리 안 정보를 바꿀 수 있는지 정할 수 있습니다.
관련 개념
- 파일과 디렉터리 접근 모드 — 모든 파일에는 소유자가 있습니다. 새 파일은 만든 사용자가 소유자입니다. 소유자는 파일에 접근 모드를 지정합니다. 접근 모드는 다른 시스템 사용자에게 파일을 읽거나 수정하거나 실행할 권한을 줍니다. 파일 소유자나 root 권한 사용자만 파일의 접근 모드를 바꿀 수 있습니다.
디렉터리 종류
디렉터리는 운영 체제, 시스템 관리자, 사용자가 정의할 수 있습니다.
시스템 정의 디렉터리에는 명령 같은 특정 종류의 시스템 파일이 들어 있습니다. 파일 시스템 계층 맨 위에는 시스템 정의 /(root) 디렉터리가 있습니다. /(root) 디렉터리에는 보통 다음 표준 시스템 관련 디렉터리가 있습니다.
/dev— I/O 장치의 특수 파일이 있습니다./etc— 시스템 초기화와 시스템 관리용 파일이 있습니다./home— 시스템 사용자의 로그인 디렉터리가 있습니다./tmp— 임시 파일이 있으며 정해진 날짜가 지나면 자동으로 지워집니다./usr—lpp,include, 기타 시스템 디렉터리가 있습니다./usr/bin— 사용자가 실행할 수 있는 프로그램이 있습니다.
로그인 디렉터리 곧 홈 디렉터리($HOME) 같은 일부 디렉터리는 시스템 관리자가 정의하고 맞춥니다. 운영 체제에 로그인하면 로그인 디렉터리가 현재 디렉터리입니다.
직접 만든 디렉터리를 사용자 정의 디렉터리라 합니다. 이 디렉터리로 파일을 정리하고 관리할 수 있습니다.
디렉터리 구성
디렉터리에는 파일, 하위 디렉터리, 또는 둘 다 들어 있습니다. 하위 디렉터리는 디렉터리 안의 디렉터리입니다. 하위 디렉터리를 담은 디렉터리를 부모 디렉터리라 합니다.
각 디렉터리에는 자신을 만든 부모 디렉터리 항목 ..(점 둘)과 디렉터리 자신의 항목 .(점)이 있습니다. 대부분의 디렉터리 목록에서 이 파일은 숨겨집니다.
디렉터리 트리
디렉터리의 파일 시스템 구조는 쉽게 복잡해질 수 있습니다. 파일과 디렉터리 구조를 되도록 단순하게 유지합니다. 알아보기 쉬운 이름으로 파일과 디렉터리를 만듭니다. 그러면 파일을 다루기가 쉬워집니다.
부모 디렉터리
/(root)를 뺀 모든 디렉터리에는 부모 디렉터리가 하나 있고 자식 디렉터리가 있을 수 있습니다.
홈 디렉터리
로그인하면 시스템은 홈 디렉터리 또는 로그인 디렉터리라는 디렉터리에 사용자를 둡니다. 이 디렉터리는 시스템 관리자가 사용자마다 설정합니다. 홈 디렉터리는 개인 파일 저장소입니다. 보통 자기 용도로 만드는 디렉터리는 홈 디렉터리의 하위 디렉터리입니다. 언제든 홈 디렉터리로 돌아가려면 프롬프트에서 cd 명령을 입력하고 Enter를 누릅니다.
작업 디렉터리
늘 어떤 디렉터리 안에서 작업합니다. 지금 작업하는 디렉터리를 현재 디렉터리 또는 작업 디렉터리라 합니다. pwd(present working directory) 명령은 작업 디렉터리 이름을 알려 줍니다. 작업 디렉터리를 바꾸려면 cd 명령을 씁니다.
디렉터리 이름 규칙
각 디렉터리 이름은 그것이 저장된 디렉터리 안에서 고유해야 합니다. 그래야 디렉터리가 파일 시스템에서 고유한 경로 이름을 갖습니다.
디렉터리는 파일 이름 규칙에서 설명한 파일과 같은 이름 규칙을 따릅니다.
디렉터리 약어
약어로 특정 디렉터리를 편하게 지정할 수 있습니다.
다음은 약어 목록입니다.
| 약어 | 뜻 |
|---|---|
. |
현재 작업 디렉터리 |
.. |
현재 작업 디렉터리 위 디렉터리(현재 디렉터리의 부모) |
~ |
홈 디렉터리(Bourne 셸에서는 해당하지 않음. 자세한 내용은 Bourne 셸 참조) |
$HOME |
홈 디렉터리(모든 셸에 해당) |
디렉터리 경로 이름
모든 파일과 디렉터리는 파일 시스템 트리 구조를 지나는 고유한 경로, 곧 경로 이름으로 찾아갈 수 있습니다. 경로 이름은 파일 시스템 안 디렉터리나 파일의 위치를 지정합니다.
참고: 경로 이름 길이는 1023자를 넘을 수 없습니다.
파일 시스템은 다음 종류의 경로 이름을 씁니다.
- 절대 경로 이름 —
/(root)디렉터리부터 경로를 따라갑니다. 절대 경로 이름은 늘 슬래시(/) 기호로 시작합니다. - 상대 경로 이름 — 현재 디렉터리에서 부모나 하위 디렉터리와 파일을 지나 경로를 따라갑니다.
절대 경로 이름은 /(root) 디렉터리부터 아래로 디렉터리나 파일의 완전한 이름을 나타냅니다. 파일 시스템 어디에서 작업하든 절대 경로 이름을 지정하면 디렉터리나 파일을 늘 찾을 수 있습니다. 절대 경로 이름은 루트 디렉터리를 나타내는 기호인 슬래시(/)로 시작합니다. 경로 이름 /A/D/9는 9의 절대 경로 이름입니다. 첫 슬래시(/)는 검색 시작점인 /(root) 디렉터리를 나타냅니다. 나머지 경로 이름은 검색을 A로, 그다음 D로, 마지막으로 9로 이끕니다.
절대 경로 이름이 파일 시스템 안에서 각 파일에 고유한 이름을 주므로 9라는 파일이 둘 있을 수 있습니다. 경로 이름 /A/D/9와 /C/E/G/9는 9라는 서로 다른 파일 둘을 지정합니다.
전체 경로 이름과 달리 상대 경로 이름은 현재 작업 디렉터리를 바탕으로 디렉터리나 파일을 지정합니다. 상대 경로 이름에서는 점 둘(..) 표기로 파일 시스템 계층을 위로 올라갈 수 있습니다. 점 둘(..)은 부모 디렉터리를 나타냅니다. 상대 경로 이름은 현재 디렉터리에서 시작하는 경로를 지정하므로 슬래시(/)로 시작하지 않습니다. 상대 경로 이름은 현재 디렉터리 안 파일 이름이나 파일 시스템에서 현재 디렉터리보다 위나 아래 수준에 있는 파일이나 디렉터리의 경로 이름을 지정하는 데 씁니다. D가 현재 디렉터리이면 10에 접근하는 상대 경로 이름은 F/10입니다. 그러나 절대 경로 이름은 늘 /A/D/F/10입니다. 또 3에 접근하는 상대 경로 이름은 ../../B/3입니다.
현재 디렉터리 이름은 점(.) 표기로도 나타낼 수 있습니다. 점(.) 표기는 현재 디렉터리 이름을 읽는 프로그램을 실행할 때 흔히 씁니다.
디렉터리 만들기(mkdir 명령)
mkdir 명령으로 Directory 매개변수에 지정한 디렉터리를 하나 이상 만듭니다.
새 디렉터리마다 표준 항목인 점(.)과 점 둘(..)이 들어 있습니다. -m Mode 플래그로 새 디렉터리의 권한을 지정할 수 있습니다.
파일 시스템의 다른 위치로 가는 절대 경로 이름을 지정하지 않으면 디렉터리는 현재 디렉터리, 곧 작업 디렉터리 안에 만들어집니다.
다음은 mkdir 명령 사용 예입니다.
- 현재 작업 디렉터리에 기본 권한으로
Test라는 새 디렉터리를 만들려면 다음을 입력합니다.
mkdir Test
- 이미 만든
/home/demo/sub1디렉터리에rwxr-xr-x권한으로Test라는 디렉터리를 만들려면 다음을 입력합니다.
mkdir -m 755 /home/demo/sub1/Test
/home/demo/sub2디렉터리에 기본 권한으로Test라는 디렉터리를 만들려면 다음을 입력합니다.
mkdir -p /home/demo/sub2/Test
-p 플래그는 /home, /home/demo, /home/demo/sub2 디렉터리가 없으면 만듭니다.
전체 구문은 Commands Reference, Volume 3의 mkdir 명령을 봅니다.
디렉터리 옮기기와 이름 바꾸기(mvdir 명령)
mvdir 명령으로 디렉터리를 옮기거나 이름을 바꿉니다.
다음은 mvdir 명령 사용 예입니다.
- 디렉터리를 옮기려면 다음을 입력합니다.
mvdir book manual
manual 디렉터리가 있으면 book 디렉터리를 manual 디렉터리 아래로 옮깁니다. 없으면 book 디렉터리 이름을 manual로 바꿉니다.
- 디렉터리를 옮기면서 이름을 바꾸려면 다음을 입력합니다.
mvdir book3 proj4/manual
manual이라는 디렉터리가 이미 있으면 book3과 그 내용을 proj4/manual로 옮깁니다. 곧 book3이 proj4/manual의 하위 디렉터리가 됩니다. manual이 없으면 book3 디렉터리 이름을 proj4/manual로 바꿉니다.
전체 구문은 Commands Reference, Volume 3의 mvdir 명령을 봅니다.
현재 디렉터리 표시(pwd 명령)
pwd 명령으로 (/(root) 디렉터리부터) 현재 디렉터리의 전체 경로 이름을 표준 출력에 씁니다.
모든 디렉터리는 슬래시(/)로 구분합니다. 첫 슬래시(/)는 /(root) 디렉터리를 나타내고 마지막에 나온 디렉터리가 현재 디렉터리입니다.
예를 들어 현재 디렉터리를 표시하려면 다음을 입력합니다.
pwd
현재 디렉터리의 전체 경로 이름이 다음과 비슷하게 표시됩니다.
/home/thomas
다른 디렉터리로 바꾸기(cd 명령)
cd 명령으로 지금 디렉터리에서 다른 디렉터리로 옮깁니다. 지정한 디렉터리에 실행(검색) 권한이 있어야 합니다.
Directory 매개변수를 지정하지 않으면 cd 명령은 로그인 디렉터리(ksh와 bsh 환경에서는 $HOME, csh 환경에서는 $home)로 옮깁니다. 지정한 디렉터리 이름이 전체 경로 이름이면 그것이 현재 디렉터리가 됩니다. 전체 경로 이름은 /(root) 디렉터리를 나타내는 슬래시(/), 현재 디렉터리를 나타내는 점(.), 부모 디렉터리를 나타내는 점 둘(..)로 시작합니다. 디렉터리 이름이 전체 경로 이름이 아니면 cd 명령은 $CDPATH 셸 변수(또는 csh 변수 $cdpath)에 지정한 경로 가운데 하나를 기준으로 찾습니다. 이 변수는 $PATH 셸 변수(또는 csh 변수 $path)와 구문이 같고 의미도 비슷합니다.
다음은 cd 명령 사용 예입니다.
- 홈 디렉터리로 바꾸려면 다음을 입력합니다.
cd
/usr/include디렉터리로 바꾸려면 다음을 입력합니다.
cd /usr/include
- 디렉터리 트리를 한 단계 내려가
sys디렉터리로 가려면 다음을 입력합니다.
cd sys
현재 디렉터리가 /usr/include이고 sys라는 하위 디렉터리가 있으면 /usr/include/sys가 현재 디렉터리가 됩니다.
- 디렉터리 트리를 한 단계 올라가려면 다음을 입력합니다.
cd ..
특수 파일 이름 점 둘(..)은 현재 디렉터리 바로 위 디렉터리, 곧 부모 디렉터리를 가리킵니다.
전체 구문은 Commands Reference, Volume 1의 cd 명령을 봅니다.
디렉터리 복사(cp 명령)
cp 명령으로 SourceFile이나 SourceDirectory 매개변수에 지정한 파일이나 디렉터리 내용의 사본을 TargetFile이나 TargetDirectory 매개변수에 지정한 파일이나 디렉터리에 만듭니다.
TargetFile로 지정한 파일이 있으면 복사가 그 파일의 원래 내용을 덮어씁니다. SourceFile을 둘 이상 복사하면 대상은 디렉터리여야 합니다.
SourceFile의 사본을 디렉터리에 두려면 TargetDirectory 매개변수에 기존 디렉터리 경로를 지정합니다. 경로 끝에 새 파일 이름을 지정하지 않으면 디렉터리로 복사한 파일은 각자 이름을 유지합니다. -r이나 -R 플래그를 지정하면 cp 명령은 디렉터리 전체를 다른 디렉터리로 복사하기도 합니다.
다음은 cp 명령 사용 예입니다.
/home/accounts/customers/orders디렉터리의 모든 파일을/home/accounts/customers/shipments디렉터리로 복사하려면 다음을 입력합니다.
cp /home/accounts/customers/orders/* /home/accounts/customers/shipments
orders 디렉터리의 파일을(디렉터리는 빼고) shipments 디렉터리로 복사합니다.
- 모든 파일과 하위 디렉터리를 포함해 디렉터리를 다른 디렉터리로 복사하려면 다음을 입력합니다.
cp -R /home/accounts/customers /home/accounts/vendors
customers 디렉터리를 그 안의 모든 파일, 하위 디렉터리, 하위 디렉터리 안 파일과 함께 vendors 디렉터리로 복사합니다.
전체 구문은 Commands Reference, Volume 1의 cp 명령을 봅니다.
디렉터리 내용 표시(ls 명령)
ls 명령으로 디렉터리 내용을 표시합니다.
ls 명령은 지정한 각 Directory의 내용이나 지정한 각 File의 이름을 플래그로 요청한 다른 정보와 함께 표준 출력에 씁니다. File이나 Directory를 지정하지 않으면 ls 명령은 현재 디렉터리 내용을 표시합니다.
기본적으로 ls 명령은 모든 정보를 파일 이름의 알파벳순으로 표시합니다. root 권한 사용자가 실행하면 기본으로 -A 플래그를 써서 점(.)과 점 둘(..)을 뺀 모든 항목을 나열합니다. 점(.)으로 시작하는 것을 포함해 모든 파일 항목을 보려면 ls -a 명령을 씁니다.
출력 형식은 다음과 같이 정할 수 있습니다.
-l플래그로 한 줄에 항목 하나씩 나열합니다.-C나-x플래그로 항목을 여러 열로 나열합니다. 출력이 tty로 갈 때는-C플래그가 기본 형식입니다.-m플래그로 항목을 쉼표로 구분한 연속으로 나열합니다.
출력 줄의 문자 위치 수를 정하려고 ls 명령은 $COLUMNS 환경 변수를 씁니다. 이 변수가 설정돼 있지 않으면 terminfo 파일을 읽습니다. 두 방법 모두로 문자 위치 수를 알 수 없으면 기본값 80을 씁니다.
-e와 -l 플래그로 표시하는 정보는 다음과 같이 해석합니다.
각 항목의 첫 글자는 다음 가운데 하나일 수 있습니다.
- d — 디렉터리입니다.
- b — 블록 특수 파일입니다.
- c — 문자 특수 파일입니다.
- l — 심볼릭 링크입니다.
- p — FIFO(first-in, first-out) 파이프 특수 파일입니다.
- s — 로컬 소켓입니다.
-— 일반 파일입니다.
다음 아홉 글자는 세 글자씩 세 묶음으로 나뉩니다. 처음 세 글자는 파일이나 디렉터리 소유자의 권한을 보여 줍니다. 다음 세 글자는 그룹 안 다른 사용자의 권한을 보여 줍니다. 마지막 세 글자는 파일에 접근할 수 있는 그 밖의 모든 사람의 권한을 보여 줍니다. 각 묶음의 세 글자는 파일의 읽기, 쓰기, 실행 권한을 보여 줍니다. 디렉터리의 실행 권한은 디렉터리에서 지정한 파일을 검색하게 합니다.
권한은 다음과 같이 나타냅니다.
- r — 읽기 권한이 있습니다.
- t — 다른 사람에게 디렉터리 쓰기 권한이 있더라도 디렉터리 소유자나 파일 소유자만 그 디렉터리 안 파일을 지우거나 이름을 바꿀 수 있습니다.
- w — 쓰기(편집) 권한이 있습니다.
- x — 실행(검색) 권한이 있습니다.
-— 해당 권한이 없습니다.
-e 플래그로 표시하는 정보는 -l 플래그와 같고, 다음과 같이 해석하는 11번째 글자가 더해집니다.
+— 파일에 확장 보안 정보가 있습니다. 예를 들어 모드에 확장 ACL, TCB, TP 속성이 있을 수 있습니다.-— 파일에 확장 보안 정보가 없습니다.
디렉터리 안 파일 크기를 나열할 때 ls 명령은 간접 블록을 포함한 블록 총수를 표시합니다.
다음 예를 봅니다.
- 현재 디렉터리의 모든 파일을 나열하려면 다음을 입력합니다.
ls -a
점(.), 점 둘(..), 이름이 점(.)으로 시작하거나 시작하지 않는 다른 파일을 포함해 모든 파일을 나열합니다.
- 자세한 정보를 표시하려면 다음을 입력합니다.
ls -l chap1 .profile
chap1과 .profile의 자세한 정보를 긴 목록으로 표시합니다.
- 디렉터리의 자세한 정보를 표시하려면 다음을 입력합니다.
ls -d -l . manual manual/chap1
디렉터리 .과 manual, 파일 manual/chap1을 긴 목록으로 표시합니다. -d 플래그가 없으면 디렉터리 자체의 자세한 정보 대신 .과 manual 디렉터리 안 파일을 나열합니다.
전체 구문은 Commands Reference, Volume 3의 ls 명령을 봅니다.
디렉터리 지우기(rmdir 명령)
rmdir 명령으로 Directory 매개변수에 지정한 디렉터리를 시스템에서 지웁니다.
지우기 전에 디렉터리가 비어 있어야 하고(.과 ..만 있을 수 있음) 부모 디렉터리에 쓰기 권한이 있어야 합니다. 디렉터리가 비었는지 확인하려면 ls -a Directory 명령을 씁니다.
다음은 rmdir 명령 사용 예입니다.
- 디렉터리를 비우고 지우려면 다음을 입력합니다.
rm mydir/* mydir/.*
rmdir mydir
mydir의 내용을 지운 뒤 빈 디렉터리를 지웁니다. rm 명령은 점(.)과 점 둘(..) 디렉터리를 지우려 한다는 오류 메시지를 표시하고, 그다음 rmdir 명령이 그것과 디렉터리 자체를 지웁니다.
참고: rm mydir/* mydir/.*는 먼저 이름이 점으로 시작하지 않는 파일을 지우고, 그다음 점으로 시작하는 파일을 지웁니다. ls 명령은 -a 플래그를 쓰지 않으면 점으로 시작하는 파일 이름을 나열하지 않습니다.
/tmp/jones/demo/mydir디렉터리와 그 아래 모든 디렉터리를 지우려면 다음을 입력합니다.
cd /tmp
rmdir -p jones/demo/mydir
/tmp 디렉터리에서 jones/demo/mydir 디렉터리를 지웁니다. 지울 때 디렉터리가 비어 있지 않거나 쓰기 권한이 없으면 명령은 알맞은 오류 메시지와 함께 끝납니다.
전체 구문은 Commands Reference, Volume 4의 rmdir 명령을 봅니다.
디렉터리 내용 비교(dircmp 명령)
dircmp 명령으로 Directory1과 Directory2 매개변수에 지정한 두 디렉터리를 비교해 내용 정보를 표준 출력에 씁니다.
먼저 dircmp 명령은 각 디렉터리의 파일 이름을 비교합니다. 같은 파일 이름이 양쪽에 있으면 두 파일의 내용을 비교합니다.
출력에서 dircmp 명령은 각 디렉터리에만 있는 파일을 나열합니다. 그다음 두 디렉터리에 이름은 같지만 내용이 다른 파일을 나열합니다. 플래그를 지정하지 않으면 두 디렉터리에 이름과 내용이 모두 같은 파일도 나열합니다.
다음은 dircmp 명령 사용 예입니다.
proj.ver1과proj.ver2디렉터리의 파일 차이를 요약하려면 다음을 입력합니다.
dircmp proj.ver1 proj.ver2
proj.ver1과 proj.ver2 디렉터리의 차이 요약을 표시합니다. 요약은 한쪽 디렉터리에만 있는 파일과 양쪽에 있는 파일을 따로 나열합니다. 파일이 양쪽 디렉터리에 있으면 dircmp 명령은 두 사본이 같은지 적습니다.
proj.ver1과proj.ver2디렉터리의 파일 차이를 자세히 보려면 다음을 입력합니다.
dircmp -d -s proj.ver1 proj.ver2
-s 플래그는 같은 파일 정보를 표시하지 않습니다. -d 플래그는 양쪽 디렉터리에 있는 서로 다른 파일마다 diff 목록을 표시합니다.
전체 구문은 Commands Reference, Volume 2의 dircmp 명령을 봅니다.
파일 시스템과 디렉터리 명령 요약
다음은 파일 시스템과 디렉터리 명령, 디렉터리 처리 절차 명령, 디렉터리 약어 목록입니다.
표 66. 파일 시스템 명령 요약
| 명령 | 설명 |
|---|---|
| df | 파일 시스템 공간 정보를 알려 줍니다. |
표 67. 디렉터리 약어
| 약어 | 뜻 |
|---|---|
. |
현재 작업 디렉터리 |
.. |
현재 작업 디렉터리 위 디렉터리(현재 디렉터리의 부모) |
~ |
홈 디렉터리(Bourne 셸에서는 해당하지 않음. 자세한 내용은 Bourne 셸 참조) |
$HOME |
홈 디렉터리(모든 셸에 해당) |
표 68. 디렉터리 처리 절차 명령 요약
| 명령 | 설명 |
|---|---|
| cd | 현재 디렉터리를 바꿉니다. |
| cp | 파일이나 디렉터리를 복사합니다. |
| dircmp | 두 디렉터리와 공통 파일의 내용을 비교합니다. |
| ls | 디렉터리 내용을 표시합니다. |
| mkdir | 새 디렉터리를 하나 이상 만듭니다. |
| mvdir | 디렉터리를 옮깁니다(이름을 바꿉니다). |
| pwd | 작업 디렉터리의 경로 이름을 표시합니다. |
| rmdir | 디렉터리를 지웁니다. |
영어 원문
Directories
A directory is a unique type of file that contains only the information needed to access files or other directories. As a result, a directory occupies less space than other types of files.
File systems consist of groups of directories and the files within the directories. File systems are commonly represented as an inverted tree. The root directory, denoted by the slash (/) symbol, defines a file system and appears at the top of a file system tree diagram.
Directories branch downward from the root directory in the tree diagram and can contain both files and subdirectories. Branching creates unique paths through the directory structure to every object in the file system.
Collections of files are stored in directories. These collections of files are often related to each other; storing them in a structure of directories keeps them organized.
A file is a collection of data that can be read from or written to. A file can be a program you create, text you write, data you acquire, or a device you use. Commands, printers, terminals, correspondence, and application programs are all stored in files. This allows users to access diverse elements of the system in a uniform way and gives great flexibility to the file system.
Directories let you group files and other directories to organize the file system into a modular hierarchy, which gives the file system structure flexibility and depth.
Directories contain directory entries. Each entry contains a file or subdirectory name and an index node reference number (i-node number). To increase speed and enhance use of disk space, the data in a file is stored at various locations in the memory of the computer. The i-node number contains the addresses used to locate all the scattered blocks of data associated with a file. The i-node number also records other information about the file, including times of modification and access, access modes, number of links, file owner, and file type.
A special set of commands controls directories. For example, you can link several names for a file to the same i-node number by creating directory entries with the ln command.
Because directories often contain information that should not be available to all users of the system, directory access can be protected. By setting a directory's permissions, you can control who has access to the directory, also determining which users (if any) can alter information within the directory.
Related concepts
File and directory access modes Every file has an owner. For new files, the user who creates the file is the owner of that file. The owner assigns an access mode to the file. Access modes grant other system users permission to read, modify, or execute the file. Only the file's owner or users with root authority can change the access mode of a file.
Types of directories
Directories can be defined by the operating system, by the system administrator, or by users.
The system-defined directories contain specific kinds of system files, such as commands. At the top of the file system hierarchy is the system-defined /(root) directory. The /(root) directory usually contains the following standard system-related directories:
/dev— Contains special files for I/O devices./etc— Contains files for system initialization and system management./home— Contains login directories for the system users./tmp— Contains files that are temporary and are automatically deleted after a specified number of days./usr— Contains thelpp,include, and other system directories./usr/bin— Contains user-executable programs.
Some directories, such as your login or home directory ($HOME), are defined and customized by the system administrator. When you log in to the operating system, the login directory is the current directory.
Directories that you create are called user-defined directories. These directories allow you to organize and maintain your files.
Directory organization
Directories contain files, subdirectories, or a combination of both. A subdirectory is a directory within a directory. The directory containing the subdirectory is called the parent directory.
Each directory has an entry for the parent directory in which it was created, .. (dot dot), and an entry for the directory itself, . (dot). In most directory listings, these files are hidden.
Directory Tree
The file system structure of directories can easily become complex. Attempt to keep the file and directory structure as simple as possible. Create files and directories with easily recognizable names. This makes working with files easier.
Parent Directory
Each directory, except for /(root), has one parent directory and may have child directories.
Home Directory
When you log in, the system puts you in a directory called your home directory or login directory. Such a directory is set up by the system administrator for each user. Your home directory is the repository for your personal files. Normally, directories that you create for your own use will be subdirectories of your home directory. To return to your home directory at any time, type the cd command and press Enter at the prompt.
Working Directory
You are always working within a directory. Whichever directory you are currently working in is called your current or working directory. The pwd (present working directory) command reports the name of your working directory. Use the cd command to change working directories.
Directory naming conventions
The name of each directory must be unique within the directory where it is stored. This ensures that the directory has a unique path name in the file system.
Directories follow the same naming conventions as files, as explained in File naming conventions.
Directory abbreviations
Abbreviations provide a convenient way to specify certain directories.
The following is a list of abbreviations:
.— The current working directory...— The directory above the current working directory (the parent of the current directory).~— Your home directory. (This is not true for the Bourne shell. For more information, see “Bourne shell” on page 250.)$HOME— Your home directory. (This is true for all shells.)
Directory path names
Each file and directory can be reached by a unique path, known as the path name, through the file system tree structure. The path name specifies the location of a directory or file within the file system.
Note: Path names cannot exceed 1023 characters in length.
The file system uses the following kinds of path names:
- absolute path name — Traces the path from the
/(root)directory. Absolute path names always begin with the slash (/) symbol. - relative path name — Traces the path from the current directory through its parent or its subdirectories and files.
An absolute path name represents the complete name of a directory or file from the /(root) directory downward. Regardless of where you are working in the file system, you can always find a directory or file by specifying its absolute path name. Absolute path names start with a slash (/), the symbol representing the root directory. The path name /A/D/9 is the absolute path name for 9. The first slash (/) represents the /(root) directory, which is the starting place for the search. The remainder of the path name directs the search to A, then to D, and finally to 9.
Two files named 9 can exist because the absolute path names to the files give each file a unique name within the file system. The path names /A/D/9 and /C/E/G/9 specify two unique files named 9.
Unlike full path names, relative path names specify a directory or file based on the current working directory. For relative path names, you can use the notation dot dot (..) to move upward in the file system hierarchy. The dot dot (..) represents the parent directory. Because relative path names specify a path starting in the current directory, they do not begin with a slash (/). Relative path names are used to specify the name of a file in the current directory or the path name of a file or directory above or below the level of the current directory in the file system. If D is the current directory, the relative path name for accessing 10 is F/10. However, the absolute path name is always /A/D/F/10. Also, the relative path name for accessing 3 is ../../B/3.
You can also represent the name of the current directory by using the notation dot (.). The dot (.) notation is commonly used when running programs that read the current directory name.
Creating directories (mkdir command)
Use the mkdir command to create one or more directories specified by the Directory parameter.
Each new directory contains the standard entries dot (.) and dot dot (..). You can specify the permissions for the new directories with the -m Mode flag.
When you create a directory, it is created within the current, or working, directory unless you specify an absolute path name to another location in the file system.
The following are examples of how to use the mkdir command:
- To create a new directory called
Testin the current working directory with default permissions, type the following:
mkdir Test
- To create a directory called
Testwithrwxr-xr-xpermissions in a previously created/home/demo/sub1directory, type the following:
mkdir -m 755 /home/demo/sub1/Test
- To create a directory called
Testwith default permissions in the/home/demo/sub2directory, type the following:
mkdir -p /home/demo/sub2/Test
The -p flag creates the /home, /home/demo, and /home/demo/sub2 directories if they do not already exist.
See the mkdir command in the Commands Reference, Volume 3 for the complete syntax.
Moving or renaming directories (mvdir command)
Use the mvdir command to move or rename a directory.
The following are examples of how to use the mvdir command:
- To move a directory, type the following:
mvdir book manual
This moves the book directory under the directory named manual, if the manual directory exists. Otherwise, the book directory is renamed to manual.
- To move and rename a directory, type the following:
mvdir book3 proj4/manual
If a directory named manual already exists, this moves book3 and its contents to proj4/manual. In other words, book3 becomes a subdirectory of proj4/manual. If manual does not exist, this renames the book3 directory to proj4/manual.
See the mvdir command in the Commands Reference, Volume 3 for the complete syntax.
Displaying the current directory (pwd command)
Use the pwd command to write to standard output the full path name of your current directory (from the /(root) directory).
All directories are separated by a slash (/). The /(root) directory is represented by the first slash (/), and the last directory named is your current directory.
For example, to display your current directory, type the following:
pwd
The full path name of your current directory displays similar to the following:
/home/thomas
Changing to another directory (cd command)
Use the cd command to move from your present directory to another directory. You must have execute (search) permission in the specified directory.
If you do not specify a Directory parameter, the cd command moves you to your login directory ($HOME in the ksh and bsh environments, or $home in the csh environment). If the specified directory name is a full path name, it becomes the current directory. A full path name begins with a slash (/) indicating the /(root) directory, a dot (.) indicating current directory, or a dot dot (..) indicating parent directory. If the directory name is not a full path name, the cd command searches for it relative to one of the paths specified by the $CDPATH shell variable (or $cdpath csh variable). This variable has the same syntax as, and similar semantics to, the $PATH shell variable (or $path csh variable).
The following are examples of how to use the cd command:
- To change to your home directory, type the following:
cd
- To change to the
/usr/includedirectory, type the following:
cd /usr/include
- To go down one level of the directory tree to the
sysdirectory, type the following:
cd sys
If the current directory is /usr/include and it contains a subdirectory named sys, then /usr/include/sys becomes the current directory.
- To go up one level of the directory tree, type the following:
cd ..
The special file name, dot dot (..), refers to the directory immediately above the current directory, its parent directory.
See the cd command in the Commands Reference, Volume 1 for the complete syntax.
Copying directories (cp command)
Use the cp command to create a copy of the contents of the file or directory specified by the SourceFile or SourceDirectory parameters into the file or directory specified by the TargetFile or TargetDirectory parameters.
If the file specified as the TargetFile exists, the copy writes over the original contents of the file. If you are copying more than one SourceFile, the target must be a directory.
To place a copy of the SourceFile into a directory, specify a path to an existing directory for the TargetDirectory parameter. Files maintain their respective names when copied to a directory unless you specify a new file name at the end of the path. The cp command also copies entire directories into other directories if you specify the -r or -R flags.
The following are examples of how to use the cp command:
- To copy all the files in the
/home/accounts/customers/ordersdirectory to the/home/accounts/ customers/shipmentsdirectory, type the following:
cp /home/accounts/customers/orders/* /home/accounts/customers/shipments
This copies the files, but not the directories, from the orders directory into the shipments directory.
- To copy a directory, including all its files and subdirectories, to another directory, type the following:
cp -R /home/accounts/customers /home/accounts/vendors
This copies the customers directory, including all its files, subdirectories, and the files in those subdirectories, into the vendors directory.
See the cp command in the Commands Reference, Volume 1 for the complete syntax.
Displaying contents of a directory (ls command)
Use the ls command to display the contents of a directory.
The ls command writes to standard output the contents of each specified Directory or the name of each specified File, along with any other information you ask for with the flags. If you do not specify a File or Directory, the ls command displays the contents of the current directory.
By default, the ls command displays all information in alphabetic order by file name. If the command is executed by a user with root authority, it uses the -A flag by default, listing all entries except dot (.) and dot dot (..). To show all entries for files, including those that begin with a dot (.), use the ls -a command.
You can format the output in the following ways:
List one entry per line, using the
-lflag.List entries in multiple columns, by specifying either the
-Cor-xflag. The-Cflag is the default format when output is to a tty.List entries in a comma-separated series by specifying the
-mflag.
To determine the number of character positions in the output line, the ls command uses the $COLUMNS environment variable. If this variable is not set, the command reads the terminfo file. If the ls command cannot determine the number of character positions by either of these methods, it uses a default value of 80.
The information displayed with the -e and -l flags is interpreted as follows:
The first character of each entry may be one of the following:
- d — Entry is a directory.
- b — Entry is a block special file.
- c — Entry is a character special file.
- l — Entry is a symbolic link.
- p — Entry is a first-in, first-out (FIFO) pipe special file.
- s — Entry is a local socket.
-— Entry is an ordinary file.
The next nine characters are divided into three sets of three characters each. The first three characters show the file or directory owner's permission. The next three characters show the permission of the other users in the group. The last three characters show the permission of anyone else with access to the file. The three characters in each set show read, write, and execute permission of the file. Execute permission of a directory lets you search a directory for a specified file.
Permissions are indicated as follows:
- r — Read permission granted
- t — Only the directory owner or the file owner can delete or rename a file within that directory, even if others have write permission to the directory.
- w — Write (edit) permission granted
- x — Execute (search) permission granted
-— Corresponding permission not granted.
The information displayed with the -e flag is the same as with the -l flag, except for the addition of an 11th character, interpreted as follows:
+— Indicates a file has extended security information. For example, the file might have extended ACL, TCB, or TP attributes in the mode.-— Indicates a file does not have extended security information.
When the size of the files in a directory are listed, the ls command displays a total count of blocks, including indirect blocks.
See the following examples:
- To list all files in the current directory, type the following:
ls -a
This lists all files, including – dot (.) – dot dot (..) – Other files whose names might or might not begin with a dot (.)
- To display detailed information, type the following:
ls -l chap1 .profile
This displays a long listing with detailed information about chap1 and .profile.
- To display detailed information about a directory, type the following:
ls -d -l . manual manual/chap1
This displays a long listing for the directories . and manual, and for the file manual/chap1. Without the -d flag, this would list the files in the . and manual directories instead of the detailed information about the directories themselves.
See the ls command in the Commands Reference, Volume 3 for the complete syntax.
Deleting or removing directories (rmdir command)
Use the rmdir command to remove the directory, specified by the Directory parameter, from the system.
The directory must be empty (it can contain only . and ..) before you can remove it, and you must have write permission in its parent directory. Use the ls -aDirectory command to check whether the directory is empty.
The following are examples of how to use the rmdir command:
- To empty and remove a directory, type the following:
rm mydir/* mydir/.*
rmdir mydir
This removes the contents of mydir, then removes the empty directory. The rm command displays an error message about trying to remove the directories dot (.) and dot dot (..), and then the rmdir command removes them and the directory itself.
Note: rm mydir/* mydir/.* first removes files with names that do not begin with a dot, and then removes those with names that do begin with a dot. The ls command does not list file names that begin with a dot unless you use the -a flag.
- To remove the
/tmp/jones/demo/mydirdirectory and all the directories beneath it, type the following:
cd /tmp
rmdir -p jones/demo/mydir
This removes the jones/demo/mydir directory from the /tmp directory. If a directory is not empty or you do not have write permission to it when it is to be removed, the command terminates with appropriate error messages.
See the rmdir command in the Commands Reference, Volume 4 for the complete syntax.
Comparing the contents of directories (dircmp command)
Use the dircmp command to compare two directories specified by the Directory1 and Directory2 parameters and write information about their contents to standard output.
First, the dircmp command compares the file names in each directory. If the same file name is contained in both, the dircmp command compares the contents of both files.
In the output, the dircmp command lists the files unique to each directory. It then lists the files with identical names in both directories, but with different contents. If no flag is specified, it also lists files that have identical contents as well as identical names in both directories.
The following are examples of how to use the dircmp command:
- To summarize the differences between the files in the
proj.ver1andproj.ver2directories, type the following:
dircmp proj.ver1 proj.ver2
This displays a summary of the differences between the proj.ver1 and proj.ver2 directories. The summary lists separately the files found only in one directory or the other, and those found in both. If a file is found in both directories, the dircmp command notes whether the two copies are identical.
- To show the details of the differences between the files in the
proj.ver1andproj.ver2directories, type the following:
dircmp -d -s proj.ver1 proj.ver2
The -s flag suppresses information about identical files. The -d flag displays a diff listing for each of the differing files found in both directories.
See the dircmp command in the Commands Reference, Volume 2 for the complete syntax.
Command summary for file systems and directories
The following are commands for file systems and directories, commands for directory-handling procedures, and a list of directory abbreviations.
Table 66. Command summary for file systems
- df — Reports information about space on file systems.
Table 67. Directory abbreviations
.— The current working directory...— The directory above the current working directory (the parent directory).~— Your home directory. (This is not true for the Bourne shell. For more information, see “Bourne shell” on page 250.)$HOME— Your home directory. (This is true for all shells.)
Table 68. Command summary for directory-handling procedures
- cd — Changes the current directory.
- cp — Copies files or directories.
- dircmp — Compares two directories and the contents of their common files.
- ls — Displays the contents of a directory.
- mkdir — Creates one or more new directories.
- mvdir — Moves (renames) a directory.
- pwd — Displays the path name of the working directory.
- rmdir — Removes a directory.