1ea046f7345e633f633db05acfc23083.ppt
- Количество слайдов: 45
CS 465 Using UNIX Basic Commands
The Virtual Terminal • You log on to Unix via a virtual terminal. – via telnet or secure shell (ssh) • Your terminal session is mediated by: – system-wide scripts – your shell and shell scripts – your kernel – your terminal emulation
Regis Unix Servers • The Regis Unix server is: acadunix. regis. edu • You can access acadunix with telnet from other computers via the Internet: telnet acadunix. regis. edu • You can also use a secure shell ssh program to access acadunix
Logging in/out • Log in – Connect to the UNIX system using telnet or ssh – At the log in prompt, type your userid (case sensitive) and press ENTER key. – At the password prompt, type your password (case sensitive) and press ENTER key.
The System Login File • System login file is run for every user when they log in • Exact location/name depends on your shell – Korn system login usually /etc/profile • Maintained by the system administrator
Your Personal Login File • Name depends on the shell. profile Bourne/Korn shells. login C shell • Runs every time you log in • Can use it to set up your environment to your own particular requirements
Your Home Directory. . login. profile. logout. plan Current working directory Parent directory login script file (csh) login script file (sh/ksh) logout script file finger resource file
The Unix Prompt • After you log in, and the startup files have been run, the shell will display a prompt $ • Different shells and different systems have different prompts. – Two common prompts are $ and #. – Your prompt can be changed. • A prompt (plus a cursor) tells you that the system is ready for your commands.
Changing Passwords • When? – First time you log on – Frequently (4~6 months) • How? $ passwd – old passwd is required • What password to choose? – At least 8 character long – Mixed lower/upper case alphabetical, numbers, and special characters – Avoid dictionary words, names and dates
Terminal Emulation • Terminal emulation is negotiated between your client machine and the Unix server. • Your virtual terminal ID (e. g. pts/0) and type (e. g. vt 100) are negotiated when you first connect and login.
Terminal Emulation who am i - identifies your terminal ID. $ who am i small 000 pts/0 $ Aug 25 15: 31 (xlate. regis. edu) echo $TERM - identifies your login terminal type. $ echo $TERM vt 100 $
Special Control Keys <CTRL>c <CTRL>d <CTRL>g <CTRL>h <CTRL>l <CTRL>u <CTRL>w <CTRL>z <CTRL>s <CTRL>q interrupt (stop program/command) halt or EOF bell backspace redraw screen kill (erase) line kill word suspend stop the screen from scrolling continue scrolling
The stty Command stty - set terminal type options stty -a - list all terminal settings stty erase ^h – Erase key is now <CTRL>h (backspace) So the Backspace key now works, but the Delete key no longer works.
Standard Command Format: command [options] <arguments> • stuff in brackets is optional • boldface words are literals (must be typed as is) • <> enclosed words are args (replace appropriately) • Commands are case sensitive (mostly lowercase) • Spaces must be inserted between commands, options, arguments
Standard Command Format • Options (also called flags) modify how the command works (command behavior) – single letters prefixed with a dash “-” – combined or separated (e. g. , -al = -a -l ) – come before arguments • Arguments define the command scope – Optional for some commands, mandatory for others – Some commands assume a default argument, if none is supplied – Usually files or directories
Basic Commands date - Prints the date and time $ date Mon Aug 25 15: 32: 35 MDT 2008 $ echo - Displays command line input to screen $ echo Hi, I am Pam, your instructor! $
Commands to Manipulate Files • ls lists files in a directory (names, not the contents of files) • cat, head, tail, page, more display files • rm removes files (and directories) • cp copies files (and directories) • mv moves (renames) files (and directories)
Displaying Filenames • The ls command is used to list files in your directories. • Syntax: ls [options] pathname • If a pathname is not given, the files in the current working directory are listed. $ ls file 1 file 2 $ list mailbox mystuff yoggle
Listing Files in a Directory The ls command has several options: -a list all files including the dot files -l long format (show file type, permissions, #links, owner, etc) -R recursive list subdirectories -F list directories with file type (trailing / * @)
Displaying Hidden Files that have names beginning with a period (. ) are hidden so they do not show up when you use the ls command. You must use the ls –a command to list all files in a directory, including hidden files. $ ls –a. . plan contacts. . . profile cprogs $ The hidden file listed above are: . . plan. profile house mydays something subdir
Displaying File Types ls -F displays the file type along with each file name / = directory file * = executable file @ = symbolic link If no symbol follows the filename, the file is a regular file. $ ls –F contacts cprogs/ $ house mydays* something subdir/ Files cprogs and subdir are directory files, and the file mydays is executable.
Displaying a Long Listing ls -l displays detailed information about a directory. BLOCK SIZE # DIRECTORIES GROUP 1 drwxr-xr-x 180 root 2 -rw-r--r-1 smith FILE TYPE FILE SIZE admin 512 fac 1314 Oct 1 Oct 3 PERMISSIONS OWNER MODIFY DATE . . / file FILE NAME
Displaying Directory Details ls -ld displays detailed information about a directory without listing information about each file. $ ls –ld drwxr-xr-x 6 small 000 faculty $ ls -ld /bin drwxr-xr-x 2 root $ 4096 Mar 8 11: 01. 4096 Feb 3 20: 42 /bin
Displaying Files in Subdirectories ls -R recursively displays the contents of a directory and all of its subdirectories. $ ls –R. : cprogs contacts dfawk mydays. /cprogs: palindrome. c /subdir: testfile $ shoes subdir reverse. c.
Getting Help • Check the manual pages! – For shell command, system programs, and library functions. • Format: man <command> man –k <keywords> • Man(ual) page format Name Synopsis Description (options, defaults, detail desc. , examples) Files See Also Bugs
man Examples $ man Displays help on the man command $ man who Displays help on the who command $ man -k mail Checks all man pages for keyword “mail”
man Output Example $ man ls Reformatting page. Wait. . . done User Commands ls(1) NAME ls - list contents of directory SYNOPSIS /usr/bin/ls [ -a. Abc. Cdf. Fgil. Lmnopqr. Rstux 1 ] [ file. . . ] /usr/xpg 4/bin/ls [ -a. Abc. Cdf. Fgil. Lmnopqr. Rstux 1 ] [ file. . . --More--(11%) spacebar - moves forward one page b – moves back one page h – displays more commands q – quits ]
Viewing Files cat concatonate and print to screen (ctrl-s and ctrl-q to stop/start) head tail display first x lines of file display last x lines of file (both default to 10 lines) page more page file to the screen display part of file to screen
Example: cat, head, tail $ cat letter Mr. Jones, It is getting late. Please order some pizza and stop by my office. We’ll tidy up a few more things before calling it a night. Thanks! Ben $ head – 2 letter Mr. Jones, It is getting late. Please order some pizza and stop $ tail – 1 letter Ben
Copying Files Format: cp [-ir…] file 1 file 2 cp [-ir…] file-list directory cp [-ir…] directory – i for interactive. Prompt whenever a file will be overwritten. – r for recursive. Copy a whole directory tree.
cp Examples $ ls letter 1 secret $ cp letter 1 letter 2 $ ls -F letter 1 letter 2 secret/ $ cp letter 1 letter 2 secret $ ls secret letter 1 letter 2
Moving /Renaming Files Format: mv [-i…] file 1 file 2 - Renames file 1 to file 2 mv [-i…] file-list directory - Moves files from current location to new directory mv [-i…] directory - Renames a directory
mv Examples $ ls letter memo saved $ mv memo 1 $ ls -F letter memo 1 saved/ $ mv saved trash $ ls -F letter memo 1 trash/
Deleting Files Format: rm file-list - Deletes files rm -r directory - Deletes directory and all files and directories within it - Use with CAUTION!
rm Examples $ ls -F letter 1 letter 2 secret/ $ rm letter 1 $ ls -F letter 2 secret/ $ ls –F secret memo morestuff/ $ rm –r secret $ ls letter 2
Finding User Information • who Who is logged on, when & where $ who denni 221 pts/1 small 000 pts/0 • finger Aug 25 14: 39 (164. 47. 158. 163) Aug 25 15: 31 (xlate. regis. edu) A bit more login information $ finger Login Name Office Phone small 000 Faculty - Pamela Small (xlate. regis. edu) Tty pts/0 Idle Login Time Aug 25 15: 31
Finding User Information $ finger small 000 Login: small 000 Name: Faculty - Pamela Smallwood Directory: /home/small 000 Shell: /usr/bin/ksh Office: Regis On since Mon Aug 25 15: 31 (MDT) on pts/0 from xlate. regis. edu No mail. Plan: An education is not a thing one gets, but a lifelong process.
Communicating with others • write - one way messaging $ write user • talk - interactive messaging $ talk user • e-mail programs mail - simple and old email program mailx - newer, improved email
write Example • write Send one way message to another user $ whoami smith 321 $ write jones 456 Bill, you’ve been idle for a long time! What are you doing? [hit CTRL-D to end write message] $ $ whoami jones 456 Message from smith 321 [Fri Mar 29 20: 18: 47] Bill, you’ve been idle for a long time! What are you doing? <EOT> $
talk Example (screen 1) • talk Instant messaging for UNIX $ whoami smith 321 $ talk jones 456 [Waiting for your party to respond] [Connection established] Hi Bill, what’s up? +---------------------+ Hi! I’m a little busy right now. Is it okay if I call you back latter?
talk Example (screen 2) $ whoami jones 456 $ Message from Talk_Daemon at 20: 41. . . talk: connection requested by smith 321 talk: respond with: talk smith 321 $ talk smith 321 [Waiting for your party to respond] [Connection established] Hi! I’m a little busy right now. Is it okay if I call you back latter? +-----------------------+ Hi Bill, what’s up?
Turning off talk & write mesg - turns on (y) or off (n) the ability to receive write/talk messages Syntax: $ mesg n $ mesg y
Unix E-mail • Entering mail to read your mail: $ mail or $ mailx • If you have any mail in your system mail box, an indexed list of the messages will be displayed on your screen. – To read the current message, just press the Return key
Leaving Unix • To exit from Unix and/or your current shell, type exit or <CTRL>-d at the prompt. • Make sure you always log completely out. Leaving yourself logged in is a serious security hole.
Questions • Advantages/Disadvantages of a command line system (vs. a GUI)? • Concerns?
1ea046f7345e633f633db05acfc23083.ppt