220 likes | 454 Views
CS 497C – Introduction to UNIX Lecture 6: General-Purpose Utilities. Chin-Chih Chang chang@cs.twsu.edu. General-Purpose Utilities. The general-purpose utilities of the system can be broadly divided into two categories: Some commands tell you the state of the system.
E N D
CS 497C – Introduction to UNIXLecture 6: General-Purpose Utilities Chin-Chih Changchang@cs.twsu.edu
General-Purpose Utilities • The general-purpose utilities of the system can be broadly divided into two categories: • Some commands tell you the state of the system. • Others can aid you directly in your work. • In chapter 1, you used the passwd command to change your password. • When used without arguments, it sets the user’s own password:
passwd: Change Your Password $ passwd Changing password for gates (current) UNIX password: Enter new UNIX password: Retype new UNIX password: • When invoked by an ordinary user, passwd asks for the old password, then it demands the new password twice.
passwd: Change Your Password • If everything goes smoothly, the new password is registered by the system, and the prompt is returned. • Depending on the way they are configured, many systems conduct certain checks on the string that you enter as password. • They may either disallow you from framing easy-to-remember passwords or advise you against choosing a bad password.
passwd: Change Your Password • These are good practice when handling your own password: • Don’t choose a password similar to your old one. • Don’t use commonly used names. • Use a mix of alphabetic or numeric characters. • Make sure the password is unmeaningful enough to prevent other from guessing it. • Don’t write down the password in an easily accessible document. • Change the password regularly.
passwd: Change Your Password • When you enter a password, the string is encrypted by the system. • Encryption generates a string of seemingly random characters that UNIX uses subsequently to determine the authenticity of a password. • This encryption is stored in a file named shadow in the /etc directory.
who and w: Know the Users • UNIX maintains an account of all users who are logged on to the system. • There are two commands which display an informative listing of users – who and w. • Who produces a simple three or four-columnar output. $ who romeo pts/2 Aug 31 12:00 (sisko.cs.twsu.edu) juliet pts/5 Sep 2 15:10 (156.26.169.34)
who and w: Know the Users • The first column show the user-ids of the users currently working on the system. • The second column shows the device names of their respective terminals. These terminals are actually special files representing devices. • The third column shows the date and time of logging in. • The fourth column show the location (domain name or IP address) of logging in.
who and w: Know the Users • The option –H prints line of column headings. • The option –u adds user idle time. $ who –Hu USER LINE LOGIN-TIME IDLE FROM romeo pts/3 Aug 31 12:57 00:40 (kira.cs.twsu.edu) juliet pts/5 Sep 2 15:10 . (156.26.169.34) • A . shows juliet has activity in the last one minute. Romeo seems to be idling for the last 40 minutes.
who and w: Know the Users • The w command produces a more detailed output of users’ activities, and additionally displays many details of the system: $ w 4:46pm up 124 days, 19:10, 5 users, load average: 0.00, 0.00, 0.00 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT romeo pts/1 ge.cs.twsu.edu 3:02pm 40:45 0.04s 0.04s -bash juliet pts/2 alonzo.cs.twsu.e Fri12pm 2days 2.03s 1.98s pine • The first line of output shows the command was executed at 4:46 p.m. on a system having two users.
who and w: Know the Users • The system has been up and running for 124 days and 19 hours and 10 minutes. • The system load averages for the past one, five and fifteen minutes are virtually negligible. • The remaining output is who-like except for the last three columns. • The output shown under JCPU shows the total CPU time consumed by all processes at that terminal.
who and w: Know the Users • The command the user is currently executing is shown in the last column. • PCPU refers to the time consumed by that process. • Because the multitasking nature of UNIX permits a user to run more than one job at the same time, the JCPU and PCPU times can often be different. • who and w are regularly used by the system administrator to monitor whether terminals are being properly utilized.
tty: Know Your Terminal • The tty command tells you the filename of the terminal you are using. $ tty /dev/pts/6 • This shows the user is using the number 6 of pts terminal. • pts is known as pseudo terminal system. • The lock command lets you lock your terminal. But it is not available in Linux.
stty: Set Terminal Characteristics • The terminal is the device with which a user communicates with the system. • Different terminals are configured differently. It’s possible that your terminal may not behave in the way it’s meant to. • The stty command helps straighten these things out. • stty uses an enormous number of keywords.
stty: Set Terminal Characteristics • The –a (all) option displays the current settings. $ stty -a speed 9600 baud; rows 25; columns 80; line = 0; intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>; eol2 = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W; lnext = ^V; flush = ^O; min = 1; time = 0; -parenb -parodd cs8 -hupcl -cstopb cread -clocal -crtscts -ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon -ixoff -iuclc -ixany -imaxbel opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0 isig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt echoctl echoke
stty: Set Terminal Characteristics • The output shows the baud rate (the speed) of the terminal is 9600. • In this system, the [Ctrl-c] key interrupts a program. The erase character is [Ctrl-?], and the kill character is [Ctrl-u]. • Of special significance is the eof (end-of-file) character which is set to [Ctrl-d]. You can use this key with the cat command to end input from the keyboard.
stty: Set Terminal Characteristics • A series of keywords with a – prefixed are options which are turned off. The ones without a – prefixed are options which are turned on. • echoe decides whether backspacing should erase character. If it is set (without – prefix to it), backspacing removes the character from display.
stty: Set Terminal Characteristics • This setting can be reversed in this way: stty -echoe • The echo option decides if the input is echoed. By default, the option is turned on. You can turn it off and on as follows respectively: stty –echo stty echo
stty: Set Terminal Characteristics • If you like to use use [Ctrl-c] as the interrupt key instead of [Delete], you can use stty intr \^c • When you insert control characters into a file, you’ll see a ^ symbol prefixed to the character. For example, [Ctrl-l] is seen as ^l. It’s actually a single character occupying two slots on the terminal.
stty: Set Terminal Characteristics • When creating files with cat, you can use [Ctrl-d] to terminate input. Instead of [Ctrl-d], you can use [Ctrl-a] as the eof character: stty eof \^a • To set the terminal characteristics to values that will work on most terminals, use the following command: stty sane