last 명령어 (AIX 5.3·6.1)

핵심 정리

  • /var/adm/wtmp에 남은 로그인과 로그오프를 최신 것부터 보여 줍니다. 세션 시작 시각, 지속 시간, 단말, 재부팅으로 끝난 세션과 아직 이어지는 세션이 나옵니다.
  • last 사용자, last 단말(예: last console, last 0은 tty0), last reboot(재부팅 기록), last -n 20(20줄), last -t MMDDhhmm(그 시각에 로그인해 있던 사용자).
  • 사용자 이름과 단말을 함께 주면 어느 하나라도 맞는 기록을 모두 보여 줍니다.
  • -X는 8자보다 긴 사용자 이름을 자르지 않습니다. -f 파일로 다른 wtmp 파일(예: 돌려 둔 예전 파일)을 읽습니다.
  • wtmp는 계속 커지므로 회계(accounting)나 정기 작업으로 비웁니다(> /var/adm/wtmp).
항목 내용
버전 AIX 5.3, AIX 6.1 (두 버전의 내용이 같음)
원문 IBM Commands Reference — 5.3 Volume 3, 6.1 Volume 3
파일 /usr/bin/last, /var/adm/wtmp
관련 명령어 who, lastlogin, acctcon1, fwtmp, lsuser -a time_last_login

목적

이전 로그인 정보를 보여 줍니다.

영어 원문

Displays information about previous logins.

구문

text
last [ -X ] [ -f FileName ] [ -t Time ] [ -n Number | -Number ] [ Name ... ] [ Terminal ... ]

설명

last 명령은 /var/adm/wtmp에 아직 남아 있는 모든 이전 로그인과 로그오프를 최신 것부터 보여 줍니다. /var/adm/wtmp는 로그인·로그아웃이 일어날 때마다 기록을 모으고, 일별 보고 절차에서 acctcon1과 acctcon2가 처리할 때까지 보관합니다. 시간 데몬 timed가 시스템 시각을 바꾸면 의사 사용자 "date"로 wtmp에 기록을 남깁니다. 바꾸기 전에는 "date |"로 시작하는 항목을, 바꾼 뒤에는 "date {"로 시작하는 항목을 남겨, 시각 변경을 걸친 로그인도 정확히 계산할 수 있게 합니다.

다음으로 목록을 제한할 수 있습니다.

  • -Number 매개변수나 -n 플래그로 지정한 줄 수
  • Name 매개변수로 지정한 사용자의 로그인·로그오프
  • Terminal 매개변수로 지정한 단말의 로그인·로그오프. 단말은 전체 이름이나 tty를 줄여 쓸 수 있습니다(예: tty0 또는 0).

참고: Name과 Terminal을 함께 주면 어느 조건이든 맞는 로그인·로그오프를 모두 보여 줍니다.

각 세션마다 다음을 보여 줍니다.

  • 세션 시작 시각
  • 지속 시간
  • 쓴 단말(tty)

해당하면 다음도 보여 줍니다.

  • 재부팅으로 끝난 세션
  • 아직 이어지는 세션

last가 인터럽트되면 /var/adm/wtmp를 어디까지 찾았는지 알려 줍니다. quit 신호로 인터럽트되면 어디까지 찾았는지 알리고 계속 찾습니다. 원문은 quit 신호로 SIGQUIT(3), SIGKILL(9), SIGTERM(15)을 듭니다. kill은 옵션 없이 쓰면 SIGTERM을 보내며, SIGQUIT을 보내려면 kill -3 PID를 씁니다.

영어 원문

The last command displays, in reverse chronological order, all previous logins and logoffs still recorded in the /var/adm/wtmp file. The /var/adm/wtmp file collects login and logout records as these events occur and holds them until the records are processed by the acctcon1 and acctcon2 commands as part of the daily reporting procedures. When the time daemon, timed, changes the system time, it logs entries in wtmp under the pseudo-user "date". An entry starting with "date |" is logged before the change, and one starting with "date {" is logged after the change. This allows for accurate accounting of logins that span a time change.

The list can be restricted to:

  • The number of lines specified either with the -Number parameter or with the -n flag.

  • Logins or logoffs by the users specified by the Name parameter.

  • Logins or logoffs from the terminals specified by the Terminal parameter.

  • A terminal can be named fully or abbreviated as a tty. For example, you can specify either the tty0 terminal or the 0 terminal.

Note: If you specify both a Name and Terminal parameter, the last command displays all logins and logoffs meeting either criterion.

For each process, the last command displays the:

  • Time the session began

  • Duration

  • Terminal (tty) used

If applicable, the following information is included:

  • Terminations due to rebooting

  • Sessions that are still continuing

If the last command is interrupted, it indicates how far the search has progressed in the /var/adm/wtmp file. If interrupted with a quit signal, the command indicates how far the search has progressed and then continues the search. The quit signal can be any one of the following:

#define SIGQUIT 3 /* (*) quit, generated from terminal special char */

#define SIGKILL 9 /* kill (cannot be caught or ignored) */

#define SIGTERM 15 /* software termination signal */

The kill command sends the default SIGTERM signal when it is invoked without any option. If you want to send the SIGQUIT signal, enter the following: kill -3 (Process ID)

플래그

플래그 설명
-f FileName 로그인·로그오프를 읽을 다른 파일.
-n 목록에 보여 줄 줄 수.
-t Time 그 시각에 로그인해 있던 사용자를 보여 줍니다. 형식은 [[CC]YY]MMDDhhmm[.SS](CC 연도 앞 두 자리, YY 연도 뒤 두 자리, MM 월 0112, DD 일 0131, hh 시 0023, mm 분 0059, SS 초 00~59).
-X 사용자 이름을 처음 8자로 자르지 않고 모두 출력합니다.
영어 원문
  • -f FileName — Specifies an alternate file from which to read logins and logoffs.
  • -n — Specifies the number of lines to be displayed on the list.
  • -t Time — Displays users logged in at the given Time value. The Time variable is specified in the decimal form [[CC]YY]MMDDhhmm[.SS] where: CC Specifies the first two digits of the year. YY Specifies the last two digits of the year. MM Specifies the month of the year (01 to 12). DD Specifies the day of the month (01 to 31). hh Specifies the hour of the day (00 to 23). mm Specifies the minute of the hour (00 to 59). SS Specifies the second of the minute (00 to 59).
  • -X — Prints all available characters of each user name instead of truncating to the first 8 characters.

예제

명령 하는 일
last root console 사용자 root의 기록이나 console 단말의 기록을 모두
last reboot 시스템 재부팅 사이의 시간. 의사 사용자 reboot는 시스템이 다시 시작할 때 로그인함
last -t 04151030 4월 15일 오전 10시 30분에 로그인해 있던 사용자
last -n 10 10줄만
last -X 사용자 이름을 자르지 않고 모든 기록

자주 쓰는 형태:

bash
last | head -20                 # 최근 로그인
last reboot | head              # 최근 재부팅 시각
last -X app_service_user        # 긴 사용자 이름
who -b                          # 마지막 부팅 시각
/usr/sbin/acct/fwtmp < /var/adm/wtmp | tail   # wtmp를 텍스트로
영어 원문
  1. To display all the recorded logins and logoffs by user root or from the console terminal, type:
last root console
  1. To display the time between reboots of the system, type:
last reboot

The reboot pseudo-user logs in when the system starts again.

  1. To display all the users still logged in at 10.30 am on April 15th, enter:
last -t 04151030
  1. To display 10 lines in the list, type:
last -n 10
  1. To display all the recorded logins and logoffs without truncating the user name, type:
last -X

파일

파일 설명
/usr/bin/last last 명령
/var/adm/wtmp 로그인, 로그오프, 종료 기록을 포함한 접속 시간 회계 데이터
영어 원문
  • /usr/bin/last — Contains the last command.
  • /var/adm/wtmp — Contains connect-time accounting data, including login, logoff, and shutdown records.

Related reference:

  • lastlogin Command
  • kill Command

Related information:

  • acctcon1 , accton2
  • System accounting
  • Setting up an accounting subsystem

리눅스(GNU)와 다른 점

리눅스 last도 /var/log/wtmp를 읽으며 last 사용자, last reboot, last -n 10, last -F(전체 시각)를 씁니다. 실패한 로그인은 lastb(/var/log/btmp), 사용자마다 마지막 로그인은 lastlog로 봅니다. -t에 해당하는 것은 last -p 시각(present)입니다.