Chapter 2 Familiar with UNIX commands
Tien-Hsiung Weng 翁添雄 [email protected] Objectives
• Familiar with command basic and syntax • Learn how the shell uses the PATH variables to locate commands • Understand few basic commands: – man, echo, printf, mailx, passwd, who, date, stty, uname • Get introduce to the X-windows UNIX command basic
• UNIX commands: – Internal (builtin) and external command • Some commands are internal, built into the shell. – cd command is built-in. (the shell interprets that command and changes your current directory). – ls command is an external program stored in the file /bin/ls. • The shell does not start a separate process to run internal commands. • External commands require the shell to fork and exec a new subprocess; this takes some time, especially on a busy system. • Check a command is internal or external: –$ type cd - cd is a shell builtin Structure of a Command • ls -l -u -t chap01
• Command filenames need no specific extensions. • A command’s behavior is determined by its arguments and options. • Command and arguments must be separated by whitespace. • Generally possible to combine multiple options into a single one • (like ls -l -u -t == ls -lut) • Order of combining is generally not important • (like ls -lut == ls -utl) command
date date date + %m date + %h Display system date $ $ $ d – day y – year s –h, m, second hour, minute, D – in format mm/dd/yy date T – in formant hh:mm:ss date ). should be used. man command man -s 5 passwd and man first to know how man passwd man • man documentation not available for most internal commands of the • shell. • Use Displays documentation of commands, configuration files, system calls and library functions. • in a number of sections. Commands are found Section 1. Organized • May need to use section number when entry exists in multiple sections • (e.g. command
echo echo echo “Enter a number:” echo $SHELL echo “Today is” date + Display messages $ $ $ $ ` date +%h command
printf “Today is %s \n” ` printf printf $SHELL printf “My shell is %s \n” $SHELL printf Display messages $ $ $ $ PATH environment variable
• Usually UNIX commands are kept in directories: – /bin and /usr/bin – /etc and /usr/etc - used by system administrators in. • Internal command: – When you type the name of a command, the shell first checks if it is a built-in command, if so, executes it. • External command with absolute pathname: – /bin/ls -- the command is executed, if ls file is in the dir. • With no absolute pathname: – the shell looks in its search path for an executable program or script with the given name. The search path is stored in an environment variable called PATH. – PATH=/bin:/usr/bin:/usr/bin/X11:/usr/ucb:/home/tim/bin: PATH environment variable
• echo command to show the value of PATH variable: • In BASH: – $echo $PATH – $set PATH= – $set PATH=/bin:/usr/bin:/usr/local/bin • In csh: – %setenv PATH – %setenv PATH=/bin:/usr/bin:/usr/local/bin
• Where is the commands? – $ whereis ls – $ which echo – $ locate grep command change your password, encrypted passwd passwd the system every time user login and stored in the file /etc/shadow (/etc/passwd on older system) Changing your password $ passwd • • (this file is used for authentication by Shadow command --- release (version of OS) --- name and domain host uname –r –n –a --- all display uname uname uname uname SUNOS 5.8 Show what is your machine’s name and OS $ $ $ $ command
who Show users that currently working on the system: $ who $ who am I command w Show users that currently working on the system: $ w command
stty Intr - interrupt key Most shell allow to suspend and resume a job. [Ctrl-z] Kill a job [Ctrl-u] Eof [Ctrl-d] Interrupt [Ctrl-c] or [Delete] Erase text [Ctrl-h] Stop scrolling of display or locks keyboard [Ctrl-s] Resume scrolling of display or unlock keyboard [Ctrl-q] Change and display terminal setting when things go wrong $ stty -a $ stty intr DEL $ stty erase [Backspace] See page 46 on text book command
stty command
stty command
stty < msg.txt [email protected] command
mailx [email protected] Using email with mailx: $ mailx Mail to thweng with subject “Our meeting” using msg.txt file as message $ mailx –s “Our meeting”