Chapter 5. Unix Basic Commands_ls CMD
ls CMD
_____________
list contents of directory
For each file that is a directory, ls lists the contents of
the directory. For each file that is an ordinary file, ls
repeats its name and any other information requested. The
output is sorted alphabetically by default. When no argument
is given, the current directory is listed. When several
arguments are given, the arguments are first sorted
appropriately, but file arguments appear before directories
and their contents.
(기본 사용 방법)
# ls -l
# ls -l dirname
# ls -ld
# ls -ld dirname // -d : direct 정보 -l : list
(옵션 사용 방법)
# ls
# ls -l
# ls -al
# ls -alF | more
# ls -ld /work
# ls -lR /work
# ls -li file1
# ls –altr // -t : sort by time stamp -r : reverse alphabetic
OPTIONS
-d If an argument is a directory, lists only its name
(not its contents). Often used with -l to get the
status of a directory.
-F Marks directories with a trailing slash (/), doors
with a trailing greater-than sign (>), executable
files with a trailing asterisk (*), FIFOs with a
trailing vertical bar (|), symbolic links with a
trailing 'at' sign (@), and AF_UNIX address family
sockets with a trailing equals sign (=).
-i For each file, prints the i-node number in the first
column of the report.
-l Lists in long format, giving mode, ACL indication,
number of links, owner, group, size in bytes, and time
of last modification for each file (see above). If the
file is a special file, the size field instead con-
tains the major and minor device numbers. If the time
of last modification is greater than six months ago,
it is shown in the format `month date year' for the
POSIX locale. When the LC_TIME locale category is not
set to the POSIX locale, a different format of the
time field may be used. Files modified within six
months show `month date time'. If the file is a sym-
bolic link, the filename is printed followed by "->"
and the path name of the referenced file.
-r Reverses the order of sort to get reverse alphabetic
or oldest first as appropriate.
-t Sorts by time stamp (latest first) instead of by name.
The default is the last modification time. (See -u and
-c.)
[참고] ls -l filename 명령어로 보여지는 출력화면 해석
# ls -l file1
-rw-r--r-- 1 user01 staff 432 시간 file1
- : d(directory), - (Regular File), s(Socket File), p(Pipe File),
l(Link File), b(block device file), c(character device file)
rw- : user01 사용자가 file1에 대한 퍼미션 설정(read, write)
r-- : staff이라는 그룹에 속한 사용자들이 file1에 대한 퍼미션 설정(read)
r-- : user01도 아니고 staff이라는 그룹에도 속하지 못한 사용자들이 file1에
대한 퍼미션(read)
1 : Hard Link Count
user01 : file1에 대한 소유권(Ownership)
staff : file2에 대한 그룹권(Groupship)
432 : 파일의 크기(File Size, bytes)
시간 : 파일이 수정되었거나 생성된 시간(mtime, Modify Time)
(mtime: Modify Time, ctime: Change Time, atime: Access Time) // ctim : 속성정보
file1 : 파일의 이름(Filename)
[참고] 파일 또는 디렉토리만 출력
# alias lsf='ls -l | grep "^-"'
# alias lsd='ls -l | grep "^d"'
# lsf
# lsd
[EX] lsf, lsd 실습
# alias lsf
# alias lsd
# cd /etc
# lsf
# lsd
[참고] 변환된 파일 사이즈 출력
alias ls='ls -hF' (-h : human) // -F 읽기 편한 형태로 변형
ls -l /etc/passwd
[참고] ls alias 선언
alias ls='ls -hF'
alias ll='ls -ailF | more'
alias lsf='ls -l | grep "^-"' // 일반 파일만 검색 할시 ls 정보에서 – 으로 시작하는경우
alias lsd='ls -l | grep "^d"' // directory 만 보고 싶을경우 ls 정보에서 d 로 시작하는경우
[참고] DOS / UNIX 명령어 비교
_________________________________________________________________
DOS UNIX
_________________________________________________________________
display list of files dir/w dir ls
dir ls -l
display contents of file type cat
display file with pauses type filename | more more
copy file copy cp
find string in file find grep
fgrep
compare files comp diff
rename file rename OR ren mv
delete file erase OR del rm
delete directory rmdir OR rd rmdir
change file protection attrib chmod
create directory mkdir OR md mkdir
change working directory chdir OR cd cd
get help help man
apropos
display date and time date, time date
display free disk space chkdsk df
print file print lpr
display print queue print lpq
_________________________________________________________________