현재디렉토리에 존재하는 파일명을 기준으로 내림차순 정렬하기
작성자 정보
- 관리자 작성
- 작성일
컨텐츠 정보
- 2,517 조회
- 1 댓글
- 0 추천
- 목록
본문
현재디렉토리에 존재하는 파일명을 기준으로 내림차순 정렬하기
다음은 위의 예와 반대의 경우로서 파일이름을 기준으로 내림차순(역순)정렬을 한 것입니다.
[root@su250 ~]# ls -l /var/log | sort -rk 8 -rw-r--r-- 1 root root 0 2008-12-01 22:26 yum.log -rw-rw-r-- 1 root utmp 141696 2008-12-24 20:42 wtmp -rw-r--r-- 1 root root 0 2008-12-01 22:23 wpa_supplicant.log drwxr-xr-x 2 root root 4096 2008-10-02 23:32 vbox -rw------- 1 root root 0 2008-12-01 21:54 tallylog -rw------- 1 root root 0 2008-12-19 04:02 spooler-20081223 -rw------- 1 root root 0 2008-12-01 21:55 spooler-20081219 -rw------- 1 root root 0 2008-12-23 04:02 spooler -rw-r--r-- 1 root root 91 2008-12-22 23:03 spacefile drwxr-xr-x 2 root root 4096 2008-12-23 04:02 setroubleshoot -rw------- 1 root root 7144 2008-12-23 02:24 secure-20081223 -rw------- 1 root root 28346 2008-12-19 02:20 secure-20081219 -rw------- 1 root root 2533 2008-12-24 20:42 secure drwx------ 3 root root 4096 2008-12-01 22:01 samba -rw-r--r-- 1 root root 45798 2008-12-19 04:04 rpmpkgs-20081223 -rw-r--r-- 1 root root 45798 2008-12-06 04:02 rpmpkgs-20081219 -rw-r--r-- 1 root root 45798 2008-12-24 04:02 rpmpkgs drwxr-xr-x 2 root root 4096 2008-12-01 23:41 prelink drwx------ 2 root root 4096 2008-08-29 06:48 ppp drwxr-xr-x 2 ntp ntp 4096 2008-10-08 20:23 ntpstats -rw------- 1 root root 151722 2008-12-23 04:02 messages-20081223 -rw------- 1 root root 768661 2008-12-19 04:02 messages-20081219 -rw------- 1 root root 76664 2008-12-24 23:24 messages -rw------- 1 root root 2280 2008-12-23 04:02 maillog-20081223 -rw------- 1 root root 16240 2008-12-19 04:02 maillog-20081219 -rw------- 1 root root 1574 2008-12-24 20:41 maillog drwxr-xr-x 2 root root 4096 2008-12-01 21:59 mail -rw-r--r-- 1 root root 147168 2008-12-24 20:42 lastlog drwx------ 2 root root 4096 2008-12-23 04:02 httpd drwxrwx--T 2 root gdm 4096 2008-12-04 20:26 gdm -rw------- 1 root root 12096 2008-12-21 22:48 faillog -rw-r--r-- 1 root root 20944 2008-12-23 17:08 dmesg.old -rw-r--r-- 1 root root 20944 2008-12-24 20:41 dmesg drwxr-xr-x 2 root root 4096 2008-08-02 13:22 dirmngr drwxr-xr-x 2 lp sys 4096 2008-12-23 04:02 cups -rw------- 1 root root 3758 2008-12-23 04:02 cron-20081223 -rw------- 1 root root 21521 2008-12-19 04:02 cron-20081219 -rw------- 1 root root 4321 2008-12-25 01:01 cron -rw------- 1 root utmp 1920 2008-12-03 23:40 btmp -rw-r--r-- 1 root root 2285 2008-12-23 02:09 boot.log-20081223 -rw-r--r-- 2 root root 2285 2008-12-18 23:00 boot.log-20081219 -rw-r--r-- 1 root root 2285 2008-12-24 20:41 boot.log drwxr-x--- 2 root root 4096 2008-12-01 22:22 audit -rw------- 1 root root 21424 2008-12-01 22:16 anaconda.xlog -rw------- 1 root root 25749 2008-12-01 22:16 anaconda.syslog -rw------- 1 root root 27728 2008-12-01 22:16 anaconda.log -rw-r--r-- 1 root root 22149 2008-12-04 03:39 Xorg.0.log.old -rw-r--r-- 1 root root 22149 2008-12-04 23:33 Xorg.0.log drwxr-xr-x 2 root root 4096 2008-12-01 22:23 ConsoleKit 합계 1672 [root@su250 ~]# |
ls -l의 결과 중 각 행의 8번째 필드가 파일명을 나타내므로 "-k 8"라는 옵션과 -r옵션을 사용하여 표시한 것입니다.
즉, 이번 예에서 주목해야하는 것은 특정 디렉토리의 파일명을 기준으로 내림차순(역순)정렬을 하였다는 것입니다.
즉, 특정 디렉토리내의 파일명을 기준으로 내림차순(역순) 정렬하실 때에 유용하게 사용하십시오.
지금까지의 예를 보았듯이 sort명령어는 간단한 텍스트파일을 정렬하기에는 매우 유용한 도구입니다.
흔히 서버 내에 있는 텍스트파일의 정렬이나 간단한 편집작업은 PC로 가져와서 편집한 다음 다시 서버로 업로드 하는 것이 일반적이지만 vi와 sort를 조금만 익힌다면 이런 작업시간을 단축할 수 있다는 것을 기억하십시오. 파워풀하고 시스템관리를 위해 조금의 노력은 해야 하지 않을까요?
관련자료
-
이전
-
다음
spectator님의 댓글
- spectator
- 작성일