<<

Chapter 2 Familiar with commands

Tien-Hsiung Weng 翁添雄 [email protected] Objectives

• Familiar with basic and syntax • Learn how the uses the PATH variables to commands • Understand few basic commands: – man, , , mailx, , , date, stty, • Get introduce to the X-windows UNIX command basic

• UNIX commands: – Internal (builtin) and external command • Some commands are internal, built into the shell. – command is built-in. (the shell interprets that command and changes your current ). – command is an external program stored in the /bin/ls. • The shell does not a separate to run internal commands. • External commands require the shell to fork and a new subprocess; this takes some , especially on a busy system. • Check a command is internal or external: –$ cd - cd is a Structure of a Command • ls -l -u -t chap01

• Command 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 mm//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 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

• 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 . • With no absolute pathname: – the shell looks in its search 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 : – $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? – $ ls – $ echo – $ locate 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 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 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] 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 $ 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 to thweng with subject “Our meeting” using msg.txt file as message $ mailx –s “Our meeting”