Computer Programming Practice (2008 Winter) Practice 2 기본 Unix/Linux 명령어숙지 2008. 12. 23
Contents Linux commands Basic commands File and Directory User Data Filtering Process Etc Conclusion & Recommended Sites 2/13
Basic commands (1/2) Echo: 입력내용또는시스템환경변수를화면에출력 $ echo I am a student $ echo 'I am a student $ echo HOME $ echo $HOME * 환경변수 : a set of dynamic values that can affect the way running proce sses will behave on a computer PATH 쉘에서사용자가입력하는명령을검색할디렉토리리스트 HOME 사용자의홈디렉토리 Man: 알고싶은명령어의매뉴얼을보여줌 $ man date 3/13
Basic commands (1/2) Cat: 텍스트파일내용을출력 $ cat /etc/passwd # 계정관련파일 ( 참조 ) smithj:x:561:561:joe Smith:/home/smithj:/bin/bash 사용자이름 : 패스워드 (/etc/shadow 저장 ): 사용자번호 : 그룹번호 : 사용자진짜이름 : 홈디렉토리 : 쉘 $ cat /etc/passwd /etc/hosts # concatenate two files, /etc/hosts : DNS 에묻기전에찾는 ip-hostname mapping 파일 $ cat -n /etc/passwd /etc/hosts # n : number more & less: 표준입력을페이지단위로출력, 이동, 검색가능 $ more /etc/passwd # h 를누르면명령어들이보인다. $ less /etc/passwd # less 는 more 와달리파일에서뒤쪽이동이가능, 시작시파일전체를읽지않기때문에큰파일의경우빨리동작 4/13
Basic commands (2/2) I/O Redirection Terminal 로연결된표준입력과표준출력을다른파일이나명령으로바꿈 $ cat -n a /etc/passwd less $ echo 'I am a student' > a $ ls $ echo 'I am a student' >> a $ cat a who > temp sort < temp who tee who.out # tee : send the output of a command to a file and standard output 5/13
File and Directory (1/3) pwd: 현재디렉터리의경로를보여줌 (print working directory) $ pwd ls: 디렉터리와파일의목록을보여줌 (lists) $ ls $ ls a #. 으로시작하는숨김파일도보여줌 $ ls l # long listing format -rw-r--r-- 1 root root 1067 2008-12-14 22:25 patch $ ls -la mkdir: 디렉터리를생성 (make directory) $ mkdir temp temp/child cd: 디렉터리를이동 (change directory) $ cd temp $ cd.. 6/13
File and Directory (2/3) cp: 파일이나디렉터리를지정된경로에복사 (copy) $ cp /etc/hosts./ $ cp -R temp temp2 # copy directories recursively rm: 파일이나디렉터리를삭제 (remove) $ rm temp $ rm -R temp # remove directories and their contents recursively mv: 파일이나디렉터리를이동하거나이름을바꿈 (move) $ mv temp temp3 $ mv./hosts temp2/ 7/13
File and Directory (3/3) which: command 가위치한곳의 full path 를화면에표시 ($PATH 기준 ) $ which ls /bin/ls whereis: command 의 binary, source, manual page 의위치를화면에표시 $ whereis ls ls: /bin/ls /usr/share/man/man1/ls.1.gz df: file system 의디스크사용량과남은양을화면에표시 $ df $ df h # print sizes in human readable format (e.g., 1K 234M 2G) 8/13
User whoami: 현재사용중인계정을화면에표시 $ whoami who, w: 현재호스트에접속중인계정들을화면에표시 $ who $ w 23:09:52 up 3 days, 1:46, 2 users, load average: 0.00, 0.00, 0.00 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT ybim pts/0 147.46.X.X 19:04 4:04 0.12s 0.00s vi /etc/olsrd.conf ybim pts/1 147.46.X.X 21:33 0.00s 0.26s 0.00s sshd: ybim [priv] finger: 사용자의정보를화면에표시 $ finger $ finger $USER 9/13
Data Filtering grep: 입력에서특정문자열을검색하여그문자열을포함하는 line 을화면에출력 $ grep $USER /etc/passwd # grep [OPTION]... PATTERN [FILE]... $ ls /etc grep passwd $ ls /etc grep n passwd # -n prints line number sort: 텍스트파일의내용을알파벳순서대로정렬하여화면에출력 $ ls /etc sort less $ ls /etc sort r less zsh_command_not_found xulrunner-1.9 xml Xdg... 10/13
Data Filtering head: 파일의첫부분을원하는양만큼화면에출력 (default: 10 lines) $ head /etc/passwd $ head -n 20 /etc/passwd $ ls /etc head -n 20 cut: 파일에서원하는필드를뽑아냄 (Cut out selected fields of each line of a file.) $ cat /etc/hosts $ cut -f 2 /etc/hosts # 기본 delimiter(tab) 을기준으로 2 번째필드 $ uname a Linux ybim-desktop 2.6.24-19-generic #1 SMP Wed Jun 18 14:43:41 UTC 2008 i686 GNU/Linux $ uname a cut d f 1,3 # 공백문자를 delimiter 로해서 1,3 번째필드 11/13
Process ps: 현재시스템의프로세스상태를보여줌 $ ps $ ps aux Top: provides a dynamic real-time of a running system $ top 12/13
ETC date: 현재시스템의날짜와시간을보여줌 $ date cal: 달력을보여줌 $ cal $ cal y # 현재년도의달력을모두보임 $ cal 2006 $ cal 8 1979 #1979 년 8 월 alias: 명령어의별칭을지음 $ alias l='ls -l $ l $ alias #alias 의리스트를보임 clear: 터미널스크린을지움 $ clear Logout : Exit a login shell $ logout 13/13
Conclusion & Recommended Sites There are many useful commands in Linux! Use man and help Help 는내부적으로정의된명령에대한정보를보임 There are many useful sites related with Linux commands http://www.oreillynet.com/linux/cmd/ http://www.math.utah.edu/lab/unix/unixcommands.html http://www.doc.ic.ac.uk/~wjk/unixintro/ Let s get into the Linux world! 14/13