840 likes | 1.14k Views
Unix Tutorial. CSU480. Outline. Getting Started System Resources Shells Special Unix Features Text Processing Other Useful Commands. The Unix Operating System. Kernel System calls Multi-user, multi-tasking OS. File System. FS is the focus point of Unix Looks like an inverted tree
E N D
Unix Tutorial CSU480
Outline • Getting Started • System Resources • Shells • Special Unix Features • Text Processing • Other Useful Commands
The Unix Operating System • Kernel • System calls • Multi-user, multi-tasking OS
File System • FS is the focus point of Unix • Looks like an inverted tree • Root directory / • Each node is either a file or a directory • Path name Absolute path Relative path . The current directory .. The parent of current directory
Directory, File and I-node • Every directory and file is listed in its parent directory • The root’s parent is itself • All Unix files are non-structured (bit stream) • A directory is a special file: • File name • I-node number
Unix Programs • Shell: between user and the kernel • Commands: • Built-in shell command (pwd) • Source compiled, object code file (ls) • Shell script (**.sh) • $PATH=/bin:/usr/bin:/usr/local/bin, etc
Getting started • Logging in • Linux Command Line Structure • Control Keys • stty – terminal control • Getting Help • Directory Navigation and Control • File Maintenance Commands • Display Commands
Logging in • Username & password • Unux is case sensitive • Changing password • passwd • Choosing an hard-to-crack password • Exiting system • Ctrl-D
Identity • username<->userid • groupname<->groupid • A user can belong to more than one group • Primary group: /etc/passwd • Additional groups: /etc/group
Identity % id uid=1101(frank) gid=10(staff) % id uid=1101(frank) gid=10(staff) groups=10(staff),5(operator),14(sysadmin),110(uts) % groups staff sysadmin uts operator
Unix Command Line Structure • Format: command [options] [arguments] • Arguments: action object, usu. files • Options: change the way it performs • command -[option][option][option] • ls -alR • command -option1 -option2 -option3 • ls -a -l -R
Control Keys • Used to perform special functions • Ctrl-Key (^-Key) ^-U: “line-kill” signal ^-A: go to the beginning of the line ^-E: go to the end of the line ^-K: kill until the end of the line
Getting Help • man command • % man -k password • passwd (5) - password file • passwd (1) - change password information • % man 5 passwd
mkdir & rmdir • mkdir -p create the intermediate (parent) directories, as needed -m mode access permissions (SVR4). • rmdir: directory must be empty
File Maintenance Commands • cp –r: recursively copy a directory • mv: Actually all you’ve done is to update the directory table entry to give the file a new name. The contents of the file remain where they were. • rm: Actually, all you’ve done is to remove the directory table entry and mark the inode as unused. The file contents are still on the disk, but the system now has no way of identifying those data blocks with a file name. -r: recursively -f: force
chmod u – user g – group o – other read=4, write=2, execute=1 or read=r, write=w, execute=x + add permissions - remove permissions = set permissions
chmod • chmod 755 file1 or chmod u=rwx,go=rx file1 • As for directory: r: can read the content of the directory w: can create/delete files of the directory x: can “go through” the directory
chown • chown new_user:new_group file • Note: On most versions of Unix this can only be done by the super-user, i.e. a normal user can’t give away ownership of their files.
df • df is used to report the number of disk blocks and inodes used and free for each file system. • Options: -l local file systems only (SVR4) -k report in kilobytes (SVR4)
du • du reports the amount of disk space in use for the files or directories you specify. • Options: -a display disk usage for each file, not just subdirectories -s display a summary total only -k report in kilobytes (SVR4)
ps • ps is used to report on processes currently running on the system. • Options: -e Select all processes. -f does full-format listing.
who • who reports who is logged in at the present time. • Syntax who [am i]
which • which will report the name of the file that is be executed when the command is invoked. This will be the full path name or the alias that’s found first in your path. • Syntax which command(s)
hostname/uname • hostname (uname -n on SysV) reports the host name of the machine the user is logged into • uname has additional options to print information about system hardware type and software version.
script • script creates a script of your session input and output. Using the script command, you can capture all the data transmission from and to your terminal screen until you exit the script program. This can be useful during the programming-and-debugging process, to document the combination of things you have tried, or to get a printed copy of it all for later perusal. • Syntax script [-a] [file] <. . .> exit
date • date displays the current data and time. A superuser can set the date and time. • Syntax date [options] [+format]
Shells • The shell sits between you and the operating system, acting as a command interpreter. • cat /etc/shells /bin/sh /bin/bash /sbin/nologin /bin/ash /bin/bsh /bin/ksh /usr/bin/ksh /usr/bin/pdksh /bin/tcsh /bin/csh /bin/zsh
Shells • sh: Bourne shell (not suited for interactive) • csh: uses C type syntax (job control) • ksh: Korn shell • bash: Bourne Again Shell (GNU) • tcsh: T-C shell • cshe: extended C shell
Built-in Commands • These commands are executed directly in the shell and don’t have to call another program to be run.