|
|
(40 intermediate revisions by the same user not shown) |
Line 1: |
Line 1: |
| My Solaris 10 notes | | == My Solaris 10 notes == |
|
| |
|
| == Components of Sun OS ==
| | [[Solaris 10 Associate]] notes |
|
| |
|
| Three components of Sun OS
| | [[Solaris 10 System Administration Part I]] notes |
| * Kernel - the core of Sun OS and manages all physical resources of the computer
| |
| * Shell - a command interpreter and interfaces between user and kernel
| |
| * Directory Hierarchy
| |
|
| |
|
| === Default shells ===
| | [[Solaris 10 System Administration Part II]] notes |
| Sun OS default primary shells:
| |
| * Bourne shell - original unix system shell and default for root user. regular user prompt is $ and root is #
| |
| * C shell - command line history, aliasing, and job control. default regular user is hostname% and root is hostname#
| |
| * Korn Shell - superset of Bourne shell plus C shell like features and enhancements. command line history, aliasing, job control, and command line editing default regular prompt is $ and root is #
| |
|
| |
|
| Sun OS contains three alternative shells:
| | == Firefox == |
| * Bash shell - GNU project Bourne Again SHell is bourne compatible shell that contains handy features from Korn and C shell.
| | Firefox plugins (for Flash) |
| * Z shell - resembles Korn shell plus enhancements
| | [http://kb.mozillazine.org/Determining_plugin_directory_on_Linux determine plugin directory] for Firefox (works for Solaris 10 x86) |
| * TC shell - C compatible shell plus enhancements
| |
|
| |
|
| == Logging into Sun OS == | | == My Solaris 11 notes == |
| | |
| All users must log into system
| |
| | |
| === Desktop login ===
| |
| | |
| Use direct login or options
| |
| | |
| password requirements 6-8 characters, contain at least two alpha characters and one numerical or special character. cannot be same as user login name, different than last password by at least three characters, reverse of user login name
| |
| password requirements don't apply to root user or regular user password set by root user
| |
| | |
| | |
| == Desktop Environment ==
| |
| | |
| Solaris 10 includes Common Desktop Environment (CDE) and Java Desktop System (JDS) desktop environments.
| |
| | |
| == Command Line ==
| |
| | |
| Run command line in a terminal window
| |
| | |
| Use Unix system commands to instruct the computing system to perform specific tasks
| |
| | |
| Commands can be executed with or without options or arguments
| |
| | |
| Unix command syntax is the order and structure of command line components.
| |
| | |
| Unix command line syntax = [command] [options] [arguments]
| |
| | |
| * command determines what system will execute
| |
| * option determines how command will run and always begins with - and are case sensitive, can use multiple options, combine options into one - or use a - for each option
| |
| * argument determines what command will affect
| |
| | |
| Multiple commands can be entered on one command line by using semi-colon(;) between each command.
| |
| | |
| === Basic Solaris 10 commands ===
| |
| | |
| <populate>
| |
| | |
| == man pages ==
| |
| | |
| display man page by typing man command
| |
| | |
| Syntax:
| |
| * $ man command
| |
| * $ man option command
| |
| * $ man option filename
| |
| | |
| === Navigating man page ===
| |
| | |
| * Space bar = page forward
| |
| * Return = line forward
| |
| * b = page backward
| |
| * /pattern = to perform a forward pattern search
| |
| * n = to move to next pattern match, must be proceeded with /pattern search
| |
| * h = provides navigation help
| |
| * q = quit man page
| |
| | |
| === Searching man pages ===
| |
| This searches all man pages. To search while inside a man page see Navigating a man page pattern search.
| |
| | |
| Search by section syntax:
| |
| * man -s number [command|filename]
| |
| Search by keyword syntax:
| |
| * man -k keyword
| |
| | |
| == Directories ==
| |
| A directory is a list of references to objects
| |
| | |
| Objects include files, sub-directories, and symbolic links
| |
| | |
| Each reference consists of a name and number
| |
| | |
| The name of object is used to identify & access object
| |
| | |
| The number specifies the inode. inode stores information about the object
| |
| | |
| pwd command shows current directory path
| |
| | |
| ls commands displays contents of current directory
| |
| | |
| Syntax:
| |
| * ls
| |
| * ls -options
| |
| * ls -options filename
| |
| * ls -options path_2_different_directory
| |
| | |
| <describe some common options, put screenshot of a long listing>
| |
| -a
| |
| | |
| -l
| |
| | |
| -la
| |
| | |
| -ld directory
| |
| | |
| -R
| |
| | |
| -F cover output /(directory), *(executable), none, @(symbolic link))
| |
| | |
| Use file command to determine certain file types
| |
| | |
| Syntax:
| |
| * file filename
| |
| | |
| === Navigating directories ===
| |
| | |
| Initial login is set to home directory
| |
| | |
| Navigate using cd command
| |
| | |
| Syntax:
| |
| * cd directory
| |
| | |
| Using cd without options or arguments moves to home directory (some shells use cd ~)
| |
| | |
| path name abbreviations
| |
| . = current or working directory
| |
| .. = parent directory
| |
| | |
| cd .. moves to parent directory
| |
| | |
| cd ../.. moves up two parent directories, you can use /.. to move up more parent directories
| |
| | |
| use absolute or relative path names to navigate directories
| |
| | |
| cd absolute_path_name
| |
| | |
| cd relative_path_name
| |
| | |
| == Files ==
| |
| | |
| Commands to view file in read-only format:
| |
| * cat (displays one or more text files without pausing)
| |
| * more (displays text files one page at a time, to navigate use man navigation keys)
| |
| * tail (displays last 10 lines of a text file,use -n or +n to change number of lines, replace n with an integer, -n displays n lines from end of file while +n displays file contents from line n to end of file)
| |
| * head (displays first 10 lines of a text file, use -n to change number of lines, replace n with an integer)
| |
| * wc (-l line count, -w word count, -c byte count, -m character count)
| |
| | |
| <add more detail about each command>
| |
| | |
| === Printing files ===
| |
| | |
| Print using lp command
| |
| | |
| Syntax:
| |
| * lp options filename
| |
| | |
| Options:
| |
| * -d destination (use while not printing to default printer)
| |
| * -o nobanner (no banner is printed)
| |
| * -n number (number of copies)
| |
| * -m (sends mail message to owner after print job is complete)
| |
| | |
| Display status of all user print requests
| |
| | |
| Syntax:
| |
| * lpstat -options printername
| |
| | |
| Options:
| |
| * -p (status of all printers)
| |
| * -o (status of all output requests)
| |
| * -d (status of default printer)
| |
| * -t (extended status of all printers)
| |
| * -s (status summary of all printers)
| |
| * -a (identifies which printers are accepting print requests)
| |
| | |
| Status response from lpstat command:
| |
| * request-ID = name of the printer and job number
| |
| * user-ID = name of user accessing the printer
| |
| * file size = output size in bytes
| |
| * date/time = current date and time
| |
| * status = status of print request
| |
| | |
| Cancel print requests
| |
| | |
| Syntax:
| |
| * cancel request-ID
| |
| * cancel -u username
| |
| | |
| == Modifying Directory Contents ==
| |
| | |
| === Copy Files & Directories ===
| |
| | |
| ==== Copy Files ====
| |
| | |
| Use cp command to copy the contents of a file to another file.
| |
| | |
| Syntax:
| |
| * cp -option source_file target_file_or_directory
| |
| | |
| Common options:
| |
| * -i (prevents accidental overwrite of file or directory, prompts user when an overwrite might occur)
| |
| * -r (recursive, includes the contents of directory and all sub-directories when copying a directory)
| |
| | |
| Examples:
| |
| | |
| Copy file within a directory:
| |
| | |
| <code>cp source_file target_file</code>
| |
| | |
| Copy multiple files to a different directory (relative path example):
| |
| | |
| <code>cp source_file1 source_file2 target_directory</code>
| |
| | |
| ==== Copy Directories ====
| |
| | |
| Use cp -r command & option to copy the contents of a directory recursively to another directory
| |
| | |
| Syntax:
| |
| * cp -options source_directory target_directory
| |
| | |
| Note:
| |
| * If target_directory does not exist one will be created with source_directory name.
| |
| * If target_directory exists a new sub-directory below target_directory will be created with source_directory name.
| |
| | |
| Copying multiple directories
| |
|
| |
| Syntax:
| |
| * cp -options source_directory1 source_directory2 target_directory
| |
| | |
| === Moving Files & Directories ===
| |
| | |
| The mv command moves & can rename files & directories within the directory hierarchy
| |
| | |
| Syntax:
| |
| * mv -option source_file_or_directory target_file_or_directory
| |
| | |
| Examples:
| |
| | |
| Rename file1 in same directory to file2:
| |
| | |
| <code>mv file1 file2</code>
| |
| | |
| Move file1 to another directory:
| |
| | |
| <code>mv file1 ../</code>
| |
| | |
| Move & rename file1 to file2 in another directory:
| |
| | |
| <code>mv file1 ../file2</code>
| |
| | |
| Move & rename directory1 to directory2 in same directory:
| |
| | |
| <code>mv directory1 directory2</code>
| |
| | |
| === Creating Files & Directories ===
| |
| | |
| ==== Creating Files ====
| |
| | |
| You can use touch command to create an empty file or a text editor program
| |
| | |
| Syntax:
| |
| * touch filename
| |
| | |
| ==== Creating Directories ====
| |
| | |
| Use mkdir command to create directories
| |
| | |
| Syntax:
| |
| * mkdir directory_name
| |
| * mkdir -p directory_names (-p creates all the parent directories that do not exist)
| |
| | |
| === Removing files & directories ===
| |
| | |
| Remove file using rm command.
| |
| | |
| Syntax:
| |
| * rm -option filename
| |
| | |
| rm options:
| |
| * -i (prompts before deleting each file)
| |
| | |
| Remove empty directories. If directories are not empty an error message will result.
| |
| | |
| Syntax:
| |
| * rmdir directories
| |
| | |
| Remove directories that are not empty
| |
| | |
| Syntax:
| |
| * rm -options directories
| |
| | |
| rm options:
| |
| * -i (prompts before deleting each file or directory)
| |
| * -r (recursive, includes all contents of directory and sub-directories)
| |
| | |
| === Using Symbolic links ===
| |
| | |
| A symbolic link is a pointer that contains the path name to another file or directory. Use ln -s command to create a symbolic link file. The file name for the symbolic link appears in the directory in which it is created.
| |
| | |
| Syntax:
| |
| * ln -s source_file target_file
| |
| | |
| Where source_file variable refers to the file in which you create a symbolic link. The target_file variable refers to the name of symbolic link. If source file does not exist a symbolic link to a non-existing file is created.
| |
| | |
| You remove symbolic link files the same way you would any other file using rm command.
| |
| | |
| == vi text editor ==
| |
| | |
| vi editor modes:
| |
| * command (delete, change, copy, move, position cursor, search, exit)
| |
| * edit (enter text)
| |
| * last line (advanced options)
| |
| | |
| Switching between modes:
| |
| * default mode when creating or opening file is command
| |
| * i (insert text, switches to edit mode)
| |
| * Esc (returns to command mode)
| |
| * : (last line mode)
| |
| | |
| vi syntax:
| |
| * vi -options filename
| |
| | |
| vi options:
| |
| * -R (opens in read-only mode) view command does same thing, syntax = view filename
| |
| * -r (recovers specified file, if no file specified lists all files that can be recovered)(use if system crashes)
| |
| | |
| Inserting & appending text:
| |
| * a (appends text after cursor)
| |
| * A (appends text at end of line)
| |
| * i (inserts text before cursor)
| |
| * I (inserts text at beginning of line)
| |
| * o (opens a new line below the cursor)
| |
| * O (opens a new line above the cursor)
| |
| * :r filename (inserts text from another file)
| |
| | |
| Moving cursor in vi:
| |
| * h, left arrow, Backspace (left one character)
| |
| * j, down arrow (down one line)
| |
| * k, up arrow (up one line)
| |
| * l, right arrow, space bar (right one character)
| |
| * b (back one word)
| |
| * w (forward one word)
| |
| * e (end of current word)
| |
| * $ (end of the current line)
| |
| * 0 (beginning of the current line)
| |
| * ^ (to first non-white space character on the line)
| |
| * Return (to beginning of next line)
| |
| * G (goes to last line of file)
| |
| * nG (goes to n line of file)
| |
| * :n (goes to n line of file)
| |
| * Ctrl+F (pages forward one screen)
| |
| * Ctrl+B (pages back one screen)
| |
| * Ctrl+U (scrolls up 1/2 screen)
| |
| * Ctrl+D (scrolls down 1/2 screen)
| |
| * Ctrl+L (refreshes screen)
| |
| * Ctrl+G (displays current buffer)
| |
| | |
| Delete text in vi:
| |
| * r (overwrite one character on cursor)
| |
| * R (overwrites all characters from cursor and to the right until Esc is pressed)
| |
| * C (overwrites characters from cursor to end of line)
| |
| * s (substitutes a string for a character at cursor)
| |
| * x (deletes the character at cursor)
| |
| * dw (deletes a word or part of word to the right of character)
| |
| * dd (deletes line containing the cursor
| |
| * D (deletes the line from the cursor to right end of line
| |
| * :n,nd (deletes lines n-n)
| |
| * CW (overwrites characters at cursor location)
| |
| * J (joins current line & the line below)
| |
| * xp (transposes the character at the cursor and to right of cursor)
| |
| * ~ (changes the case of the letter at cursor)
| |
| * u (undo previous command)
| |
| * U (undo all changes to current line)
| |
| * . (repeats previous command)
| |
| | |
| ===Search & replace text in vi===
| |
| | |
| To search & replace text in vi use these commands:
| |
| * /string (searches forward for string)
| |
| * ?string (searches backward for string)
| |
| * n (searches for next occurrence of string, after searching for a string)
| |
| * N (searches for previous occurrence of string, after searching for a string)
| |
| * :%s/string1/string2/g (search for string1, replace with string2 globally)
| |
| | |
| === Copy & paste in vi ===
| |
| | |
| To copy & paste in vi use these commands:
| |
| * yy (yanks a copy of a line)
| |
| * p (puts yanked or deleted text under the line with cursor)
| |
| * P (puts yanked or deleted text before the line with cursor)
| |
| * :n,n co n (copies lines n-n and puts after line n)
| |
| * :n,n m n (moves lines n-n to line n)
| |
| | |
| === Save & quit commands ===
| |
| | |
| To save & quit in vi use these commands:
| |
| * :w (writes contents of buffer to disk in existing file)
| |
| * :w filename (writes contents of buffer to filename)
| |
| * :wq (writes contents of buffer to disk in existing file and quits vi editor)
| |
| * :x (same as wq)
| |
| * ZZ (same as wq)
| |
| * q! (quits without saving changes)
| |
| | |
| === Customizing vi session ===
| |
| | |
| Use set command to set or unset variables in current vi session:
| |
| * :set nu (show line numbers)
| |
| * :set nonu (hides line numbers)
| |
| * :set ic (instructs searches to ignore case)
| |
| * :set noic (instructs searches to be case sensitive)
| |
| * :set list (displays invisible characters)
| |
| * :set nolist (invisible characters are invisible)
| |
| * :set showmode (displays current mode)
| |
| * :set noshowmode (disables showing current mode)
| |
| * :set (displays all vi variables that are set)
| |
| * :set all (displays all set vi variables and their current value)
| |
| | |
| Pre-load vi with customizations:
| |
| # Create .exrc file in home directory
| |
| # Enter one set variable per line in .exrc file without colon
| |
| | |
| vi editor reads the .exrc file each time vi is executed.
| |
| | |
| == Korn shell ==
| |
| | |
| Metacharacters are specific characters having special meaning to Korn shell
| |
| | |
| Three types of metacharacters:
| |
| * path name metacharacters
| |
| * file name substitution metacharacters
| |
| * quoting metacharacters
| |
| | |
| Path name metacharacters:
| |
| * ~ (home directory of current user)
| |
| * ~username (home directory of username)
| |
| * - (stores previous working directory)
| |
| | |
| File name substitution metacharacters:
| |
| * * (wildcard character, represents zero or more characters, except leading period of hidden file)
| |
| * ? (wildcard character, represents any single character except leading period of hidden file)
| |
| * [ ] (square bracket characters represent a set or range of characters for a single character position)
| |
| | |
| Quoting metacharacters:
| |
| * ' ' (instructs shell to ignore all enclosed metacharacters)
| |
| * ` (instructs shell to execute and display the output for a Unix system command)
| |
| * " " (instructs shell to ignore all enclosed metacharacters except `, \, and $)
| |
| * \ (instructs shell to ignore the next character as a metacharacter)
| |
| * $ (instructs shell that the following text is the name of a shell variable)
| |
| * <code>$(command)</code>(instructs shell to execute & display the output for the command identified)
| |
| | |
| === Korn shell variables ===
| |
| | |
| A shell variable refers to temporary storage area in memory. Variables contain information needed for customizing the shell or other processes to function correctly
| |
| | |
| ==== set,unset, view variables ====
| |
| | |
| To set, unset, & view variables:
| |
| | |
| {| border="1" cellspacing="0" cellpadding="5" align="center"
| |
| ! command
| |
| ! action
| |
| |-
| |
| | VAR = value, export VAR=value
| |
| | set a variable
| |
| |-
| |
| | unset VAR
| |
| | unset a variable
| |
| |-
| |
| | set, env, or export
| |
| | display all variables
| |
| |-
| |
| | echo $VAR or print
| |
| | display values stored in variables
| |
| |}
| |
| | |
| <talk about default korn shell variables>
| |
| | |
| <talk about customizing korn shell variables>
| |
| | |
| === useful links ===
| |
| | |
| [http://www.linux.com/archive/feature/133683 Korn] shell and why use Korn over BASH
| |
| | |
| === Using history command ===
| |
| | |
| By default history command displays the last 16 commands to the standard output
| |
| | |
| Syntax:
| |
| * history option
| |
| | |
| History options:
| |
| * -n (displays the command history without line numbers)
| |
| * -r (display the history list in reverse order)
| |
| | |
| History examples:
| |
| <code>$ history ls dir</code> would display the most recent ls command to the most recent dir command
| |
| | |
| r command is an alias built into Korn shell that enables the reuse of a command.
| |
| | |
| Examples using r command:
| |
| <pre>$ history
| |
| 609 mkdir test
| |
| 610 cd test
| |
| 611 pwd
| |
| 612 cd space
| |
| 613 ls -l
| |
| $ r 613</pre>
| |
| | |
| Rerun the most recent occurrence of a command that begins with "c":
| |
| <pre>$ r c
| |
| cd space</pre>
| |
| | |
| Rerun the most recent occurrence of a command that begins with "c", replace space with water, and perform the modified command:
| |
| <pre>$ history
| |
| 609 mkdir test
| |
| 610 cd test
| |
| 611 pwd
| |
| 612 cd space
| |
| 613 ls -l
| |
| $ r c
| |
| cd space
| |
| $ r space=water
| |
| cd water</pre>
| |
| | |
| Use a shell in-line editor to edit previously executed commands & rerun edited commands
| |
| | |
| Use the vi editor to turn on & enable the shell history editing feature. Each example sets vi for in-line editor:
| |
| * $ set -o vi
| |
| * $ export EDIT=/bin/vi
| |
| * $ export VISUAL=/bin/vi
| |
| | |
| Confirmation that built-in editor vi is enabled by running this command:
| |
| <code>set -o | grep -w vi</code>
| |
| | |
| Edit and execute previously executed command:
| |
| # use <code>history</code> command
| |
| # Press Esc key to access command history
| |
| # use vi commands to edit previously executed command
| |
| # Press Enter to execute modified command
| |
| | |
| <add some examples>
| |
| | |
| File name completion within vi mode of command-line editing:
| |
| | |
| Syntax:
| |
| # command -options arguments
| |
| # Press Esc and backslash (\)
| |
| | |
| == Command redirection ==
| |
| | |
| * each process that korn shell creates works with file descriptors
| |
| * file descriptors determine where the input to the command originates and where the output and error messages are sent
| |
| | |
| | |
| {| border="1" cellspacing="0" cellpadding="5" align="center"
| |
| ! file descriptor number
| |
| ! file descriptor abbreviation
| |
| ! definition
| |
| |-
| |
| | 0
| |
| | stdin
| |
| | standard command input
| |
| |-
| |
| | 1
| |
| | stdout
| |
| | standard command output
| |
| |-
| |
| | 2
| |
| | stderr
| |
| | standard command error
| |
| |}
| |
| | |
| === standard input ===
| |
| | |
| Less-than sign (<) forces a command to read input from file
| |
| | |
| Syntax:
| |
| * <code>command < filename</code>
| |
| | |
| <insert examples>
| |
| | |
| === standard output ===
| |
| | |
| Greater-than sign (>) sends output from a command to a file
| |
| | |
| Syntax:
| |
| * <code>command > filename</code>
| |
| | |
| <insert examples>
| |
| | |
| === standard error ===
| |
| | |
| File descriptor number 2 and greater-than (>) redirects standard error to file. Redirection of standard error will suppress error messages from going to display device
| |
| | |
| Syntax:
| |
| * <code>command 2> filename</code>
| |
| | |
| <insert examples>
| |
| | |
| === Pipe character ===
| |
| | |
| Use pipe character (|) to redirect standard output to standard input another command
| |
| | |
| Syntax:
| |
| * <code>command | command</code>
| |
| | |
| <insert examples>
| |
| | |
| == Shell as command-line interpreter ==
| |
| | |
| Korn shell interprets commands entered by:
| |
| # parsing the line
| |
| # processing metacharacters & redirection
| |
| # controlling execution of commands
| |
| | |
| Then the shell searches for the command & once found executes command
| |
| | |
| Command-line interpretation example:
| |
| * <code>ps -ef | sort +1 | more</code>
| |
| * breaks command line into tokens: ps, -ef, |, sort, +1, |, & more
| |
| * identifies ps, sort, & more as commands
| |
| * identifies -ef & +1 as options
| |
| * identifies | as an i/o operation
| |
| * sets up stdout from ps to be stdin to sort and stdout from sort to be stdin to more
| |
| * locates ps, sort, & more & executes them in order
| |
| | |
| == User initialization files ==
| |
| | |
| Use system-wide or user-specific initialization files to customize working environments
| |
| | |
| {| border="1" cellspacing="0" cellpadding="5" align="center"
| |
| ! shell
| |
| ! system-wide
| |
| ! primary user
| |
| ! user initialization files when a new shell started
| |
| ! shell path name
| |
| |-
| |
| | Bourne
| |
| | /etc/profile
| |
| | $HOME/.profile
| |
| |
| |
| | /bin/sh
| |
| |-
| |
| | Korn
| |
| | /etc/profile
| |
| | $HOME/.profile & $HOME/.kshrc
| |
| | /$HOME/.kshrc
| |
| | /bin/ksh
| |
| |-|
| |
| | C
| |
| | /etc/.login
| |
| | $HOME/.cshrh & $HOME/.login
| |
| | $HOME/.cshrc
| |
| | /bin/csh
| |
| |-
| |
| |}
| |
| | |
| === .profile file ===
| |
| | |
| <code>.profile</code>
| |
| * kshrc file is executed very time when you login or when ksh sub-shell is started
| |
| * defines Korn shell specific settings such as aliases, shell functions, history variables, & all shell options
| |
| | |
| === .cshrc file ===
| |
| | |
| .cshrc file is a C shell initialization file that you define in your home directory
| |
| * .cshrc file is executed very time when you login
| |
| * use to customize environment variables and terminal settings
| |
| * instruct the system to initiate applications
| |
| | |
| === ~/.dtprofile file ===
| |
| * file that resides in your home directory
| |
| * determines generic & customized settings for desktop environment
| |
| * settings overwrite desktop default settings
| |
| * shell reads the .dtprofile first, .profile second, & .kshrc last
| |
| * shell reads .profile & .kshrc when a new terminal session is opened
| |
| | |
| === ~/.profile file ===
| |
| * define ENV variable in ~/.profile file
| |
| * instructs login process to execute the file referenced by ENV variable
| |
| * re-run file or logout & login the terminal session to verify change
| |
| | |
| === ~/.kshrc file ===
| |
| * configure PS1 Korn shell variable by editing ~/.kshrc file
| |
| * re-run file or logout & login the terminal session to verify change
| |
| | |
| == Basic file & directory permissions ==
| |
| | |
| view permissions by using <code>ls -l</code> command
| |
| | |
| <insert figure & examples, explain each column>
| |
| | |
| === types of users ===
| |
| | |
| {| border="1" cellspacing="0" cellpadding="5" align="center"
| |
| ! field
| |
| ! description
| |
| |-
| |
| | owner
| |
| | permissions for the assigned owner of file or directory
| |
| |-
| |
| | group
| |
| | permissions for the members assigned to group that owns the file or directory
| |
| |-
| |
| | other
| |
| | permissions for all users that are not the owner or members of group
| |
| |}
| |
| | |
| === Permission sets ===
| |
| | |
| * each type of user has three permissions called a permission set
| |
| * each permission set consists of read, write, and execute permissions
| |
| * each file and directory has three permission sets for each type of user
| |
| * owner, group, & other users
| |
| * r = read only, w = write, x = execute
| |
| * file or directory show r,w, or x that means permission is given, a dash (-) means permission denied
| |
| | |
| | |
| {| border="1" cellspacing="0" cellpadding="5" align="center"
| |
| ! permission
| |
| ! character
| |
| ! file access
| |
| ! directory access
| |
| |-
| |
| | read
| |
| | r
| |
| | view file contents & copying of file
| |
| | view listing of directory with <code>ls</code> command
| |
| |-
| |
| | write
| |
| | w
| |
| | change file contents
| |
| | change directory contents (delete requires w+e)
| |
| |-
| |
| | execute
| |
| | e
| |
| | execute file (execute shell script requires r+e)
| |
| | change to directory by using <code>cd</code> command, can use <code>ls</code> only if you specify filename as argument
| |
| |}
| |
| | |
| === determining file & directory access ===
| |
| | |
| * files and directories have a user ID (UID) and group ID (GID)
| |
| * UID is owner of file & directory
| |
| * GID is group of users who own file & directory
| |
| * only one UID & GID are assigned at a time
| |
| | |
| ==== ls -n command ====
| |
| | |
| Use <code>ls -n</code> command to view UIDs & GIDs of files & directories
| |
| | |
| <insert examples>
| |
| | |
| Solaris OS compares the user, group, then other permissions when accessing a file or directory. When a match is found those permissions are applied.
| |
| | |
| === changing permissions ===
| |
| | |
| * Use <code>chmod</code> command to change permission sets on files & directories
| |
| * owner or root can use <code>chmod</code> command
| |
| * <code>chmod</code> command can change permissions using symoblic (r,w,e,-,+) or octal (0-7) mode
| |
| | |
| Syntax examples:
| |
| * symbolic mode is <code>chmod symbolic_mode filename</code> where symbolic_mode includes user affected (owner,group,other), function performed (-/+), permission (r,w,e)
| |
| * u = owner, g = group, o = other, a = all permissions
| |
| * + = add permission set, - = removes permission set, = = assign permission absolutely
| |
| * r = read, w = write, x = execute
| |
| | |
| <insert examples using chmod in symbolic mode>
| |
| | |
| Syntax examples:
| |
| * octal mode is <code>chmod octal_mode filename</code> where octal_mode includes three octal numbers
| |
| * octal numbers for permission sets are 4 = read, 2 = write, 1 = execute
| |
| | |
| octal digits for various permission sets:
| |
| | |
| {| border="1" cellspacing="0" cellpadding="5" align="center"
| |
| ! octal value
| |
| ! permission sets
| |
| ! binary
| |
| |-
| |
| | 7
| |
| | rwx
| |
| | 111 (4+2+1)
| |
| |-
| |
| | 6
| |
| | rw-
| |
| | 110
| |
| |-
| |
| | 5
| |
| | r-w
| |
| | 101
| |
| |-
| |
| | 4
| |
| | r--
| |
| | 100
| |
| |-
| |
| | 3
| |
| | -wx
| |
| | 011
| |
| |-
| |
| | 2
| |
| | -w-
| |
| | 010
| |
| |-
| |
| | 1
| |
| | --x
| |
| | 001
| |
| |-
| |
| | 0
| |
| | ---
| |
| | 000
| |
| |}
| |
| | |
| Combine octal values to change permission sets.
| |
| | |
| <insert examples using chmod command in octal mode>
| |
| | |
| === changing default permissions ===
| |
| | |
| * at creation every file & directory has default permissions
| |
| * user mask affects default file permissions assigned to file & directory
| |
| * use <code>umask</code> command to apply user mask value & modify default permissions
| |
| * <code>umask</code> is a three-digit octal value for read, write, execute
| |
| * default user mask for Solaris 10 is 022
| |
| | |
| {| border="1" cellspacing="0" cellpadding="5" align="center"
| |
| ! user mask octal value
| |
| ! file permissions
| |
| ! directory permissions
| |
| |-
| |
| | 0
| |
| | rw-
| |
| | rwx
| |
| |-
| |
| | 1
| |
| | rw-
| |
| | rw-
| |
| |-
| |
| | 2
| |
| | r--
| |
| | r-x
| |
| |-
| |
| | 3
| |
| | r--
| |
| | r--
| |
| |-
| |
| | 4
| |
| | -w-
| |
| | -wx
| |
| |-
| |
| | 5
| |
| | -w-
| |
| | -w-
| |
| |-
| |
| | 6
| |
| | ---
| |
| | --x
| |
| |-
| |
| | 7
| |
| | ---
| |
| | ---
| |
| |}
| |
| | |
| === Apply umask value for files ===
| |
| | |
| Determine default permissions for new files by applying user mask value to initial permission value in octal mode
| |
| | |
| {| border="1" cellspacing="0" cellpadding="5" align="center"
| |
| ! permission field symoblic mode
| |
| ! permission field octal mode
| |
| ! description
| |
| |-
| |
| | rw-rw-rw-
| |
| | 666
| |
| | initial permissions specified by system for file creation
| |
| |-
| |
| | ----w--w-
| |
| | 022
| |
| | default Solaris 10 user mask to be removed
| |
| |-
| |
| | rw-r--r--
| |
| | 644
| |
| | default permissions assigned to created files
| |
| |}
| |
| | |
| === Apply umask value for directories ===
| |
| | |
| Determine default permissions for new directories by applying user mask value to initial permission value in octal mode
| |
| | |
| {| border="1" cellspacing="0" cellpadding="5" align="center"
| |
| ! permission field symoblic mode
| |
| ! permission field octal mode
| |
| ! description
| |
| |-
| |
| | rwxrwxrwx
| |
| | 777
| |
| | initial permissions specified by system for directory creation
| |
| |-
| |
| | ----w--w-
| |
| | 022
| |
| | default Solaris 10 user mask to be removed
| |
| |-
| |
| | rwxr-xr-x
| |
| | 755
| |
| | default permissions assigned to created directories
| |
| |}
| |
| | |
| === changing umask value ===
| |
| | |
| * use <code>umask</code> command to change at user initialization or command line (existing session only)
| |
| * syntax:
| |
| ** to show umask <ocde>umask</code>
| |
| ** to set umask at command line <code>umask octal_mode</code>
| |
| | |
| == Access Control Lists (ACL) ==
| |
| | |
| ACL allows owner of file or directory to grant or deny specific user access using owner, group, & other
| |
| | |
| === ACL commands & descriptions ===
| |
| | |
| {| border="1" cellspacing="0" cellpadding="5" align="center"
| |
| ! ACL command examples
| |
| ! description
| |
| |-
| |
| | <code>getfacl -a filename_or_directoryname</code>
| |
| | shows name, owner, group, & ACL entries for file & directory
| |
| |-
| |
| | <code>setfacl -m acl_entries filename_or_directoryname</code>
| |
| | modifies ACL entries on file & directory
| |
| |-
| |
| | <code>setfacl -s acl_entries filename_or_directoryname</code>
| |
| | substitutes new ACL entries on file & directory
| |
| |-
| |
| | <code>setfacl -d acl_entries filename_or_directoryname</code>
| |
| |
| |
| * deletes one or more ACL entries on file & directory
| |
| * unable to delete file owner, group owner, or ACL mask)
| |
| |-
| |
| | <code>setfacl -r [-m,-s] filename_or_directoryname</code>
| |
| | recalculates ACL mask based on ACL entries, when used with -m or -s option
| |
| |}
| |
| | |
| === Viewing ACL entries ===
| |
| | |
| ACL entry syntax:
| |
| * entry-type:[UID or GID]:permission
| |
| ** entry-type specifies the scope of the file or directory permissions to owner, owner's group, specific users, additional groups, or ACL mask
| |
| ** UID or GID specifies the UID or GID
| |
| ** permissions specifies permissions for entry-type using r,w,x,-, or octal values 0-7
| |
| | |
| {| border="1" cellspacing="0" cellpadding="5" align="center"
| |
| ! entry type
| |
| ! description
| |
| |-
| |
| | u::permission
| |
| | permissions for file owner
| |
| |-
| |
| | g::permission
| |
| | permission for owner's group
| |
| |-
| |
| | o:permission
| |
| | permissions for users other than owner or member of owner's group
| |
| |-
| |
| |
| |
| * u:UID:permission or
| |
| * u:username:permission
| |
| | permissions for specific user that must exist in /etc/passwd file
| |
| |-
| |
| |
| |
| * g:GID:permission or
| |
| * g:groupname:permission
| |
| | permissions for specific group that must exist in /etc/group file
| |
| |-
| |
| | m:permission
| |
| |
| |
| * ACL mask that sets maximum effective permissions allowed for all specified users & groups
| |
| * does not impact owner or other
| |
| |}
| |
| | |
| ==== Determining Non-trivial ACL entries ====
| |
| | |
| Use <code>ls -l</code> command to determine if a file or directory has a non-trivial ACL entry
| |
| | |
| The presence of a plus sign (+) at end of permission field indicates that file or directory has an ACL entry
| |
| | |
| ==== Determining trivial ACL entries ====
| |
| | |
| Use <code>getfacl</code> command to display list of trivial ACL entries for file or directory
| |
| | |
| | |
| <insert examples of getfacl and setfacl>
| |
| | |
| ==== Configure ACLs using File Manager GUI ====
| |
| | |
| <add examples & screenshots>
| |
| | |
| == Search Files & Directories ==
| |
| | |
| === Searching for contents in files ===
| |
| | |
| Search contents of files for string patterns with <code>grep</code>, <code>egrep</code>, <code>fgrep</code> commands
| |
| | |
| ==== grep command ====
| |
| | |
| * <code>grep</code> command searches contents one or more file names for a specific character pattern
| |
| * grep means globally search for a regular expression & print all lines containing regular expression
| |
| * grep does not change file contents
| |
| * Syntax: <code>grep options pattern filename</code>
| |
| | |
| From grep man page:
| |
| <pre>
| |
| DESCRIPTION
| |
| The grep utility searches text files for a pattern and
| |
| prints all lines that contain that pattern. It uses a com-
| |
| pact non-deterministic algorithm.
| |
| | |
| Be careful using the characters $, *, [, ^, |, (, ), and \
| |
| in the pattern_list because they are also meaningful to the
| |
| shell. It is safest to enclose the entire pattern_list in
| |
| single quotes '... '.
| |
| | |
| If no files are specified, grep assumes standard input. Nor-
| |
| mally, each line found is copied to standard output. The
| |
| file name is printed before each line found if there is more
| |
| than one input file.
| |
| | |
| OPTIONS
| |
| The following options are supported for both /usr/bin/grep
| |
| and /usr/xpg4/bin/grep:
| |
| | |
| -b Precede each line by the block number on which it was
| |
| found. This can be useful in locating block numbers by
| |
| context (first block is 0).
| |
| | |
| -c Print only a count of the lines that contain the pat-
| |
| tern.
| |
| | |
| -h Prevents the name of the file containing the matching
| |
| line from being appended to that line. Used when
| |
| searching multiple files.
| |
| | |
| -i Ignore upper/lower case distinction during comparis-
| |
| ons.
| |
| | |
| -l Print only the names of files with matching lines,
| |
| separated by NEWLINE characters. Does not repeat the
| |
| names of files when the pattern is found more than
| |
| once.
| |
| | |
| -n Precede each line by its line number in the file
| |
| (first line is 1).
| |
| | |
| -s Suppress error messages about nonexistent or unread-
| |
| able files.
| |
| | |
| -v Print all lines except those that contain the pattern.
| |
| | |
| -w Search for the expression as a word as if surrounded
| |
| by \< and \>.
| |
| </pre>
| |
| | |
| <table style="text-align: left; width: 50%;" align="center" border="1"
| |
| cellpadding="0" cellspacing="0">
| |
| <tr>
| |
| <td></td>
| |
| <td>Definition</td>
| |
| </tr>
| |
| <tr>
| |
| <td>-i</td>
| |
| <td>ignore case sensitivies</td>
| |
| </tr>
| |
| <tr>
| |
| <td>-l</td>
| |
| <td>print only the names of files with matching lines, does
| |
| not repeat the names of files when pattern is found >1</td>
| |
| </tr>
| |
| <tr>
| |
| <td>-n</td>
| |
| <td>precedes each line by its line number in the file</td>
| |
| </tr>
| |
| <tr>
| |
| <td>-v</td>
| |
| <td>prints all lines except those that contain the pattern</td>
| |
| </tr>
| |
| <tr>
| |
| <td>-c</td>
| |
| <td>prints only a count of lines that contain the pattern</td>
| |
| </tr>
| |
| <tr>
| |
| <td>-w</td>
| |
| <td>search for the expression as a word as if surrounded by
| |
| \< and \>, ignoring matches that are substrings of larger
| |
| words</td>
| |
| </tr>
| |
| </table>
| |
| | |
| <insert examples using grep>
| |
| | |
| ===== Regular expression metacharacters =====
| |
| | |
| <table style="text-align: center; width: 50%;" align="center" border="1"
| |
| cellpadding="0" cellspacing="0">
| |
| <tr>
| |
| <td>Metacharacter</td>
| |
| <td>Purpose</td>
| |
| <td>Example</td>
| |
| <td>Result</td>
| |
| </tr>
| |
| <tr>
| |
| <td>^</td>
| |
| <td>begining of line anchor</td>
| |
| <td>'^pattern'</td>
| |
| <td>matches all lines beginning with pattern</td>
| |
| </tr>
| |
| <tr>
| |
| <td>$</td>
| |
| <td>end of line anchor</td>
| |
| <td>'pattern$'</td>
| |
| <td>matches all lines ending with pattern</td>
| |
| </tr>
| |
| <tr>
| |
| <td>.</td>
| |
| <td>matches one character</td>
| |
| <td>'p.....n'</td>
| |
| <td>matches lines containing a "p", followed by five
| |
| characters, and followed by an "n"</td>
| |
| </tr>
| |
| <tr>
| |
| <td>*</td>
| |
| <td>matches the preceding item zero or more times</td>
| |
| <td>'[a-z]*'</td>
| |
| <td>matches lowercase alphabet characters only</td>
| |
| </tr>
| |
| <tr>
| |
| <td>[ ]</td>
| |
| <td>matches one character in a pattern</td>
| |
| <td>'[Pp]attern'</td>
| |
| <td>matches lines containing Pattern or pattern</td>
| |
| </tr>
| |
| <tr>
| |
| <td>[^]</td>
| |
| <td>matches one character not in the pattern</td>
| |
| <td>'[^a-m]attern'</td>
| |
| <td>matches lines that do not contain a-m and followed by attern</td>
| |
| </tr>
| |
| </table>
| |
| | |
| <insert examples regular expression metacharacters>
| |
| | |
| ==== egrep command ====
| |
| | |
| <code>egrep</code> command searches the contents of one or more files for a pattern using extended regular expression metacharacters (regular expression characters plus more)
| |
| | |
| Syntax:
| |
| | |
| <code>egrep options pattern filename</code>
| |
| | |
| <table style="text-align: center; width: 50%;" align="center" border="1"
| |
| cellpadding="0" cellspacing="0">
| |
| <tr>
| |
| <td>Metacharacter</td>
| |
| <td>Purpose</td>
| |
| <td>Example</td>
| |
| <td>Result</td>
| |
| </tr>
| |
| <tr>
| |
| <td>+</td>
| |
| <td>matches one or more of the preceding characters</td>
| |
| <td>'[a-z]+ark'</td>
| |
| <td>matches one or more lowercase letters followed by ark</td>
| |
| </tr>
| |
| <tr>
| |
| <td>x|y</td>
| |
| <td>matches either x or y</td>
| |
| <td>'boat|airplane'</td>
| |
| <td>matches for either expresssion</td>
| |
| </tr>
| |
| <tr>
| |
| <td>(|)</td>
| |
| <td>group characters</td>
| |
| <td>'(1|2)+'<br>'gam(es|ing)+'</td>
| |
| <td>matches for one or more occurrences (1 or 2, games or gaming)</td>
| |
| </tr>
| |
| </table>
| |
| | |
| ===== examples using egrep =====
| |
| | |
| <insert examples>
| |
| | |
| search for all lines containing one or more lowercase alphabets followed by the pattern 'body' one or more times, perform the command:
| |
| | |
| <code>$ egrep '[a-z]+body' /etc/passwd</code>
| |
| | |
| to search for lines containing the pattern Network Admin or uucp Admin, perform the command:
| |
| | |
| <code>$ egrep '(Network|uucp) Admin' /etc/passwd</code>
| |
| | |
| ==== fgrep command ====
| |
| | |
| use fgrep command to search a file for a literal string or group of characters
| |
| | |
| fgrep commands reads all characters as text (no metacharacters)
| |
| | |
| syntax:
| |
| | |
| <code>fgrep options string filename</code>
| |
| | |
| ===== examples using fgrep =====
| |
| | |
| search for all lines in the file containing an * character, use the command:
| |
| | |
| <code>$ fgrep '*' /etc/system</code>
| |
| | |
| search for a string adm in all files in the current directory with the names ending with .sh string, use the command:
| |
| | |
| <code>$ fgrep adm *.sh</code>
| |
| | |
| === searching for files and directories ===
| |
| | |
| | |
| ==== find command ====
| |
| | |
| use <code>find</code> command to locate files or directories in the directory hierarchy
| |
| | |
| <code>find</code> command recursively descends the directory tree in the path name list, looking for files that match search criteria
| |
| | |
| as <code>find</code> command matches files matching search criteria the absolute path for each file is displayed on screen
| |
| | |
| syntax:
| |
| | |
| <code>find pathname expression action</code>
| |
| | |
| <code>find</code> command arguments:
| |
| * pathname = absolute or relative path where the search originates
| |
| * expression = search criteria specified by one or more options. specifying multiple options causes the find command to use the boolean operator <code>and</code>, so all listed expressions must be verified as true
| |
| * action = action required after the files have been located. the default print action is to print all path names matching the criteria to the screen
| |
| | |
| ===== find expressions =====
| |
| | |
| some expressions for <code>find</code> command
| |
| | |
| <table style="text-align: left; width: 50%;" border="1"
| |
| cellpadding="0" cellspacing="0">
| |
| <tr>
| |
| <td>expression</td>
| |
| <td>definition</td>
| |
| </tr>
| |
| <tr>
| |
| <td>-name filename</td>
| |
| <td>finds files matching the specified filename, metacharacters are acceptable if placed inside quote marks " " or ' '</td>
| |
| </tr>
| |
| <tr>
| |
| <td>-size [+|-]n</td>
| |
| <td>finds files that are > +n or < -n or = n. n is 512-byte blocks</td>
| |
| </tr>
| |
| <tr>
| |
| <td>-atime [+|-]n</td>
| |
| <td>finds files that have been accessed > +n or < -n or = n. n is days</td>
| |
| </tr>
| |
| <tr>
| |
| <td>-mtime [+|-]n</td>
| |
| <td>find files that have been modified > +n or < -n or = n. n is days</td>
| |
| </tr>
| |
| <tr>
| |
| <td>-user userID</td>
| |
| <td>finds all files that are owned by the userID</td>
| |
| </tr>
| |
| <tr>
| |
| <td>-type</td>
| |
| <td>finds a file type, for example f = file and d = directory</td>
| |
| </tr>
| |
| <tr>
| |
| <td>-perm</td>
| |
| <td>finds files that have certain access permission bits</td>
| |
| </tr>
| |
| </table>
| |
| | |
| ===== find actions =====
| |
| | |
| <table style="text-align: left; width: 50%;" border="1"
| |
| cellpadding="0" cellspacing="0">
| |
| <tr>
| |
| <td>action</td>
| |
| <td>definition</td>
| |
| </tr>
| |
| <tr>
| |
| <td>-exec command {} \;</td>
| |
| <td>runs the specified command on each file located. a set of braces { } delimits where the file name is passed to the command from the preceding expressions. a space, backslash, and semicolon (\;) delimits the end of the command. There must be a space before the backslash (\)</td>
| |
| </tr>
| |
| <tr>
| |
| <td>-ok command {} \;</td>
| |
| <td>requires confirmation before find command applies the command to each file located. this is the interactive form of the -exec command</td>
| |
| </tr>
| |
| <tr>
| |
| <td>-print</td>
| |
| <td>instructs the find command to print the current path name to terminal session. this is the default</td>
| |
| </tr>
| |
| <tr>
| |
| <td>-ls</td>
| |
| <td>displays the current path name and associated statistics, such as the inode number, the size in kilobytes, protection mode, the number of hard links, and the user</td>
| |
| </tr>
| |
| </table>
| |
| | |
| ===== find examples =====
| |
| | |
| <insert examples>
| |
| | |
| search home directory looking for files or directories called deleteme and asking before deleting any matches perform this command:
| |
| | |
| <code>$ find ~ -name deleteme -ok rm {} \;</code>
| |
| | |
| to look for all files that have not been modified in the last two days starting in current directory perform this command:
| |
| | |
| <code>$ find . -mtime +2</code>
| |
| | |
| to find files larger than 10 blocks (512-byte blocks X 10 = 5,120 bytes) starting in your home directory perform this command:
| |
| | |
| <code>$ find ~ -size +10</code>
| |
| | |
| == basic process control ==
| |
| | |
| every program a user runs in Solaris OS creates a process
| |
| | |
| Solaris OS starts processes called daemons that are processes running in the background and providing services
| |
| | |
| | |
| === PID, UID, GID ===
| |
| | |
| every process has a unique process identification number (PID) which the kernel users to track, control, and manage the process
| |
| | |
| each process is associated with a user id (UID) and group id (GID)
| |
| | |
| UIDs & GIDs indicate who owns a process & determine the functions of a process
| |
| | |
| === parent process ===
| |
| | |
| when one process spawns another process the originator is called the parent of the new process
| |
| | |
| new process is called the child process
| |
| | |
| while the child process runs the parent process waits
| |
| | |
| when child process finishes its task, it informs the parent process, which in turn, terminates the child process
| |
| | |
| if the parent process is an interactive shell, a prompt appears, indicating that it is ready for a new command
| |
| | |
| === viewing processes ===
| |
| | |
| use the process status (ps) command to list the processes that are scheduled to run in that shell
| |
| | |
| ps command displays the PID, the terminal identifier (TTY), the cumulative execution time (TIME), and the command name (CMD) for each process
| |
| | |
| Syntax:
| |
| | |
| <code>ps options</code>
| |
| | |
| ==== ps options ====
| |
| | |
| From ps man pages:
| |
| <pre>OPTIONS
| |
| The following options are supported:
| |
| | |
| -a Lists information about all processes
| |
| most frequently requested: all those
| |
| except session leaders and processes not
| |
| associated with a terminal.
| |
| | |
| -A Lists information for all processes.
| |
| Identical to -e, below.
| |
| | |
| -c Prints information in a format that
| |
| reflects scheduler properties as
| |
| described in priocntl(1). The -c option
| |
| affects the output of the -f and -l
| |
| options, as described below.
| |
| | |
| -d Lists information about all processes
| |
| except session leaders.
| |
| | |
| -e Lists information about every process
| |
| now running.
| |
| | |
| When the -eoption is specified, options
| |
| | |
| SunOS 5.10 Last change: 9 Jan 2008 1
| |
| | |
| User Commands ps(1)
| |
| | |
| -z, -t, -u, -U, -g, -G, -p, -g, -s and
| |
| -a options have no effect.
| |
| | |
| -f Generates a full listing. (See below for
| |
| significance of columns in a full list-
| |
| ing.)
| |
| | |
| -g grplist Lists only process data whose group
| |
| leader's ID number(s) appears in
| |
| grplist. (A group leader is a process
| |
| whose process ID number is identical to
| |
| its process group ID number.)
| |
| | |
| -G gidlist Lists information for processes whose
| |
| real group ID numbers are given in
| |
| gidlist. The gidlist must be a single
| |
| argument in the form of a blank- or
| |
| comma-separated list.
| |
| | |
| -j Prints session ID and process group ID.
| |
| | |
| -l Generates a long listing. (See below.)
| |
| | |
| -L Prints information about each light
| |
| weight process (lwp) in each selected
| |
| process. (See below.)
| |
| | |
| -n namelist Specifies the name of an alternative
| |
| system namelist file in place of the
| |
| default. This option is accepted for
| |
| compatibility, but is ignored.
| |
| | |
| -o format Prints information according to the for-
| |
| mat specification given in format. This
| |
| is fully described in DISPLAY FORMATS.
| |
| Multiple -o options can be specified;
| |
| the format specification will be inter-
| |
| preted as the space-character-separated
| |
| concatenation of all the format option-
| |
| arguments.
| |
| | |
| -p proclist Lists only process data whose process ID
| |
| numbers are given in proclist.
| |
| | |
| SunOS 5.10 Last change: 9 Jan 2008 2
| |
| | |
| User Commands ps(1)
| |
| | |
| -P Prints the number of the processor to
| |
| which the process or lwp is bound, if
| |
| any, under an additional column header,
| |
| PSR.
| |
| | |
| -s sidlist Lists information on all session leaders
| |
| whose IDs appear in sidlist.
| |
| | |
| -t term Lists only process data associated with
| |
| term. Terminal identifiers are specified
| |
| as a device file name, and an identif-
| |
| ier. For example, term/a, or pts/0.
| |
| | |
| -u uidlist Lists only process data whose effective
| |
| user ID number or login name is given in
| |
| uidlist. In the listing, the numerical
| |
| user ID will be printed unless you give
| |
| the -f option, which prints the login
| |
| name.
| |
| | |
| -U uidlist Lists information for processes whose
| |
| real user ID numbers or login names are
| |
| given in uidlist. The uidlist must be a
| |
| single argument in the form of a blank-
| |
| or comma-separated list.
| |
| | |
| -y Under a long listing (-l), omits the
| |
| obsolete F and ADDR columns and includes
| |
| an RSS column to report the resident set
| |
| size of the process. Under the -y
| |
| option, both RSS and SZ (see below) will
| |
| be reported in units of kilobytes
| |
| instead of pages.
| |
| | |
| -z zonelist Lists only processes in the specified
| |
| zones. Zones can be specified either by
| |
| name or ID. This option is only useful
| |
| when executed in the global zone.
| |
| | |
| -Z Prints the name of the zone with which
| |
| the process is associated under an addi-
| |
| tional column header, ZONE. The ZONE
| |
| column width is limited to 8 characters.
| |
| Use ps -eZ for a quick way to see infor-
| |
| mation about every process now running
| |
| | |
| SunOS 5.10 Last change: 9 Jan 2008 3
| |
| | |
| User Commands ps(1)
| |
| | |
| along with the associated zone name. Use
| |
| | |
| ps -eo zone,uid,pid,ppid,time,comm,...
| |
| | |
| to see zone names wider than 8 charac-
| |
| ters.
| |
| | |
| Many of the options shown are used to select processes to
| |
| list. If any are specified, the default list will be ignored
| |
| and ps will select the processes represented by the
| |
| inclusive OR of all the selection-criteria options.</pre>
| |
| | |
| ==== ps -ef output description ====
| |
| | |
| <describe output, include screenshot>
| |
| | |
| ==== search for specific processes ====
| |
| | |
| ===== ps and grep commands =====
| |
| | |
| use ps and grep commands to search for specific character process
| |
| | |
| Example:
| |
| | |
| <pre># ps -ef | grep ttymon
| |
| root 380 368 0 Mar 21 ? 0:01 /usr/lib/saf/ttymon
| |
| root 412 7 0 Mar 21 console 0:00 /usr/lib/saf/ttymon -g -d /dev/console -l console -m ldterm,ttcompat -h -p lxla
| |
| root 13615 13241 0 16:33:28 syscon 0:00 grep ttymon
| |
| #</pre>
| |
| | |
| ===== pgrep =====
| |
| | |
| use pgrep command to search for specific process by name
| |
| | |
| Syntax:
| |
| * pgrep options pattern
| |
| | |
| pgrep man options:
| |
| <pre>OPTIONS
| |
| The following options are supported:
| |
| | |
| -c ctidlist Matches only processes whose process con-
| |
| tract ID is in the given list.
| |
| | |
| SunOS 5.10 Last change: 6 May 2004 1
| |
| | |
| User Commands pgrep(1)
| |
| | |
| -d delim Specifies the output delimiter string to be
| |
| printed between each matching process ID. If
| |
| no -d option is specified, the default is a
| |
| newline character. The -d option is only
| |
| valid when specified as an option to pgrep.
| |
| | |
| -f The regular expression pattern should be
| |
| matched against the full process argument
| |
| string (obtained from the pr_psargs field of
| |
| the /proc/nnnnn/psinfo file). If no -f
| |
| option is specified, the expression is
| |
| matched only against the name of the execut-
| |
| able file (obtained from the pr_fname field
| |
| of the /proc/nnnnn/psinfo file).
| |
| | |
| -g pgrplist Matches only processes whose process group
| |
| ID is in the given list. If group 0 is
| |
| included in the list, this is interpreted as
| |
| the process group ID of the pgrep or pkill
| |
| process.
| |
| | |
| -G gidlist Matches only processes whose real group ID
| |
| is in the given list. Each group ID may be
| |
| specified as either a group name or a numer-
| |
| ical group ID.
| |
| | |
| -J projidlist Matches only processes whose project ID is
| |
| in the given list. Each project ID may be
| |
| specified as either a project name or a
| |
| numerical project ID.
| |
| | |
| -l Long output format. Prints the process name
| |
| along with the process ID of each matching
| |
| process. The process name is obtained from
| |
| the pr_psargs or pr_fname field, depending
| |
| on whether the -f option was specified (see
| |
| above). The -l option is only valid when
| |
| specified as an option to pgrep.
| |
| | |
| SunOS 5.10 Last change: 6 May 2004 2
| |
| | |
| User Commands pgrep(1)
| |
| | |
| -n Matches only the newest (most recently
| |
| created) process that meets all other speci-
| |
| fied matching criteria. Cannot be used with
| |
| option -o.
| |
| | |
| -o Matches only the oldest (earliest created)
| |
| process that meets all other specified
| |
| matching criteria. Cannot be used with
| |
| option -n.
| |
| | |
| -P ppidlist Matches only processes whose parent process
| |
| ID is in the given list.
| |
| | |
| -s sidlist Matches only processes whose process session
| |
| ID is in in the given list. If ID 0 is
| |
| included in the list, this is interpreted as
| |
| the session ID of the pgrep or pkill pro-
| |
| cess.
| |
| | |
| -t termlist Matches only processes which are associated
| |
| with a terminal in the given list. Each ter-
| |
| minal is specified as the suffix following
| |
| "/dev/" of the terminal's device path name
| |
| in /dev. For example, term/a or pts/0.
| |
| | |
| -T taskidlist Matches only processes whose task ID is in
| |
| the given list. If ID 0 is included in the
| |
| list, this is interpreted as the task ID of
| |
| the pgrep or pkill process.
| |
| | |
| -u euidlist Matches only processes whose effective user
| |
| ID is in the given list. Each user ID may be
| |
| specified as either a login name or a numer-
| |
| ical user ID.
| |
| | |
| -U uidlist Matches only processes whose real user ID is
| |
| in the given list. Each user ID may be
| |
| specified as either a login name or a
| |
| | |
| SunOS 5.10 Last change: 6 May 2004 3
| |
| | |
| User Commands pgrep(1)
| |
| | |
| numerical user ID.
| |
| | |
| -v Reverses the sense of the matching. Matches
| |
| all processes except those which meet the
| |
| specified matching criteria.
| |
| | |
| -x Considers only processes whose argument
| |
| string or executable file name exactly
| |
| matches the specified pattern to be matching
| |
| processes. The pattern match is considered
| |
| to be exact when all characters in the pro-
| |
| cess argument string or executable file name
| |
| match the pattern.
| |
| | |
| -z zoneidlist Matches only processes whose zone ID is in
| |
| the given list. Each zone ID may be speci-
| |
| fied as either a zone name or a numerical
| |
| zone ID. This option is only useful when
| |
| executed in the global zone. If the pkill
| |
| utility is used to send signals to processes
| |
| in other zones, the process must have
| |
| asserted the {PRIV_PROC_ZONE} privilege (see
| |
| privileges(5)).
| |
| | |
| -signal Specifies the signal to send to each matched
| |
| process. If no signal is specified, SIGTERM
| |
| is sent by default. The value of signal can
| |
| be one of the symbolic names defined in
| |
| signal.h(3HEAD) without the SIG prefix, or
| |
| the corresponding signal number as a decimal
| |
| value. The -signal option is only valid when
| |
| specified as the first option to pkill.</pre>
| |
| | |
| ===== ptree command =====
| |
| | |
| use ptree command to display a process tree based on a specified PID, default is to show all processes
| |
| | |
| an argument with all digits is taken to be a PID, otherwise a login name is presumed
| |
| | |
| output has specified PIDs or users, with child processes indented from their associated parent processes
| |
| | |
| <insert example screenshot & explanation)
| |
| | |
| === sending signal to process ===
| |
| | |
| * a signal is a message a user can send to a process
| |
| * processes respond to signals by performing the action specified in signal
| |
| * signals are identified by signal number and my a signal name, and each signal has an associated action
| |
| | |
| | |
| <put in chart for signal numbers / signal name / event / definition / default response>
| |
| | |
| | |
| ==== terminating processes ====
| |
| | |
| use kill command to send signal to terminate one or more processes
| |
| | |
| kill command sends signal 15 (terminate) signal by default which causes process to terminate in orderly manner. Signal 9 forces termination now.
| |
| | |
| can only kill your own commands (root can kill any process)
| |
| | |
| Sytax:
| |
| | |
| <code>kill [-signal] PIDs
| |
| | |
| use pkill command to send signal to terminate one or more processes
| |
| | |
| pkill command sends signal 15 (terminate) signal by default which causes process to terminate in orderly manner. Signal 9 forces termination now.
| |
| | |
| Syntax:
| |
| | |
| <code>pkill [-options] pattern</code>
| |
| | |
| == working with Korn shell ==
| |
| | |
| | |
| managing jobs
| |
| | |
| * a job is a process that the shell manages
| |
| * jobs are processes so each has a PID
| |
| * shell assigns each job a sequential job ID number
| |
| * shell enables user to run multiple jobs simultaneously
| |
| * job control commands enable user to manage multiple jobs within a shell
| |
| * three types of jobs:
| |
| ** foreground - occupies shell until job completes
| |
| ** background - command runs without occupying command, put ampersand(&) at end of a command line to launch background job (prompt returns immediately after pressing Enter)
| |
| ** stop - if user does Ctrl-Z for foreground job or perform stop command during background job that would make it a stop job
| |
| | |
| <table style="text-align: left; width: 50%;" border="1"
| |
| cellpadding="0" cellspacing="0">
| |
| <tr>
| |
| <td>command</td>
| |
| <td>value</td>
| |
| </tr>
| |
| <tr>
| |
| <td>jobs</td>
| |
| <td>lists all jobs currently running or are stopped in background</td>
| |
| </tr>
| |
| <tr>
| |
| <td>bg %n</td>
| |
| <td>runs the current or specified job in the background (n = job ID)</td>
| |
| </tr>
| |
| <tr>
| |
| <td>fg %n</td>
| |
| <td>brings current or specified job into foreground (n = job ID)</td>
| |
| </tr>
| |
| <tr>
| |
| <td>Ctrl+Z</td>
| |
| <td>stops foreground job and places it in the background as a stopped job</td>
| |
| </tr>
| |
| <tr>
| |
| <td>stop %n</td>
| |
| <td>stops a job that is running in the background (n = job ID)</td>
| |
| </tr>
| |
| </table>
| |
| | |
| === Korn shell alias utility ===
| |
| | |
| * alias is shorthand notation in Korn shell enabling user to customize Unix commands
| |
| * alias is defined by using the <code>alias</code> command
| |
| * Syntax: <code>alias name=command_string</code>
| |
| | |
| View aliases in Korn shell with alias command
| |
| | |
| Example:<pre>
| |
| $ alias
| |
| autoload='typeset -fu'
| |
| command='command '
| |
| functions='typeset -f'
| |
| history='fc -l'
| |
| integer='typeset -i'
| |
| local=typeset
| |
| nohup='nohup '
| |
| r='fc -e -'
| |
| stop='kill -STOP'
| |
| suspend='kill -STOP $$'
| |
| $</pre>
| |
| | |
| === Making alias for one command ===
| |
| | |
| Examples:
| |
| | |
| <code>$ alias rm='rm -i'</code>
| |
| | |
| <insert more>
| |
| | |
| === Making alias command sequences ===
| |
| | |
| create a command sequence by grouping several command together under a single alias
| |
| | |
| Examples:
| |
| | |
| Following command creates an alias 'info' to view the system information, uid, gid, and system date:
| |
| | |
| <code>$ alias info='uname -a; id; date'</code>
| |
| | |
| <insert more examples>
| |
| | |
| === Removing aliases ===
| |
| | |
| use <code>unalias</code> command to remove aliases from the alias list
| |
| | |
| Syntax:
| |
| | |
| <code>unalias alias_name</code>
| |
| | |
| Example:
| |
| | |
| This example removes 'info' alias setup from previous example:
| |
| | |
| $ unalias info
| |
| | |
| place aliases in Korn shell initialization file (typically .kshrc file) to ensure aliases are in every shell invoked
| |
| | |
| == Korn shell ==
| |
| | |
| === Korn shell variables ===
| |
| | |
| <insert some & include details>
| |
| | |
| | |
| === using Korn shell functions ===
| |
| | |
| * function is a group of Unix commands organized as separate entities
| |
| * using a function involves two steps:
| |
| ** define function
| |
| ** invoke function
| |
| * general format of a function is <code>function_name { command; ... command; }</code>
| |
| ** Ensure a space is inserted between brackets
| |
| * invoke a function syntax <code>$ function_name</code>
| |
| * list all functions with definitions use command <code>$ typeset -f</code>
| |
| * list all functions by name use command <code>$ typeset +f</code>
| |
| | |
| === customize Korn shell prompt ===
| |
| | |
| customize prompt string stored in PS1 shell variable example then run date command:
| |
| | |
| <pre>$ PS1="Oracle Solaris OS is robust $ "
| |
| Oracle Solaris OS is robust $ date
| |
| Oracle Solaris OS is robust $ Thu Apr 28 17:15:05 GMT 2011</pre>
| |
| | |
| === Korn shell options ===
| |
| | |
| * options are switches that control the behavior of Korn shell
| |
| * options are Boolean, either on or off
| |
| * set option on syntax: <code>$ set -o option_name</code>
| |
| * set option off syntax: <code>$ set +o option_name</code>
| |
| * show current option settings syntax: <code>$ set -o</code>
| |
| | |
| Example:
| |
| <pre>$ set -o
| |
| Current option settings
| |
| allexport off
| |
| bgnice on
| |
| emacs off
| |
| errexit off
| |
| gmacs off
| |
| ignoreeof off
| |
| interactive on
| |
| keyword off
| |
| markdirs off
| |
| monitor on
| |
| noexec off
| |
| noclobber off
| |
| noglob off
| |
| nolog off
| |
| notify off
| |
| nounset off
| |
| privileged off
| |
| restricted off
| |
| trackall off
| |
| verbose off
| |
| vi off
| |
| viraw off
| |
| xtrace off
| |
| $</pre>
| |
| | |
| <detail some of the options>
| |
| | |
| ==== noclobber ====
| |
| use noclobber option to prevent overwriting previous file content while redirecting standard output to an existing file
| |
| | |
| when noclobber option is set the shell refuses to redirect standard output to existing file and displays error message
| |
| | |
| disable noclobber on a command-by-command basis by using '>|' deactivation syntax on command line
| |
| | |
| | |
| <insert examples of using Korn shell functions>
| |
| | |
| == shell scripts ==
| |
| | |
| * a shell script is a text file that contain a sequence of Unix commands & comments
| |
| * scripts are often used to automate command sequences that repeat
| |
| * comments are preceded by a hash (#) symbol
| |
| * comments are ignored by shell
| |
| * user can invoke shell script by entering the script name at command line
| |
| * first line of script identifies the shell program that executes script
| |
| * syntax: <code>#! /full-pathname-of-shell
| |
| ** Example with Korn shell would be <code>#! /bin/ksh</code>
| |
| * the kernel uses the #! to identify the program that interprets the script
| |
| * shell interprets shell scripts line by line
| |
| * user must have read permissions to be able to read script
| |
| * user must have execute permissions to be able to run a script
| |
| | |
| == Passing values to shell script ==
| |
| | |
| * when a script is executing you can pass values to the script
| |
| * the shell stores the value after the script name in variable $1, second in variable $2, and so on
| |
| * these special variables are called <i>positional parameters</i>
| |
| | |
| Example passing values:
| |
| <pre>$ more testscript
| |
| #! /bin/ksh
| |
| echo $1 $2 #echo the first two parameters passed
| |
| $ ./testscript really now
| |
| really now
| |
| $</pre>
| |
| | |
| === using shift command ===
| |
| | |
| * Bourne shell accepts only single digit after $ sign while using ''positional parameter'' (cannot access tenth argument using $10 notation)
| |
| * <code>shift</code> command enables user to shift ''positional parameter'' values back one position
| |
| * example value set as $8 would be assigned to $7
| |
| * in Korn shell you can access n parameter directly by using syntax ${n} where n=integer
| |
| | |
| === checking exit status ===
| |
| | |
| * all commands in Unix environment return an exit status
| |
| ** exit status is a numeric value that indicates success or failure of a command
| |
| ** zero = success while integer [1-255] value indicates failure
| |
| * use exit status to indicate different error situations in shell script
| |
| * exit status of last command is held in <code>$?</code> special shell variable and can be tested using <code>echo</code> command
| |
| | |
| === using test command ===
| |
| | |
| * test command is useful in shell scripts to verify conditions, some conditions:
| |
| ** variable contents
| |
| ** file access permissions
| |
| ** file types
| |
| * syntax: <code>test expression</code> or <code>[ expression ]</code>
| |
| * test command evaluates an expression & returns an exit status of zero if result is true otherwise result is false & returns a non-zero exit status
| |
| | |
| examples using test command:
| |
| <pre>
| |
| Solaris 10$ test -d /blahblah
| |
| Solaris 10$ echo $?
| |
| 1
| |
| Solaris 10$ test -d /etc
| |
| Solaris 10$ echo $?
| |
| 0
| |
| Solaris 10$ [ -d /etc ]
| |
| Solaris 10$ echo $?
| |
| 0
| |
| Solaris 10$ [ -d /blahblah]
| |
| /bin/ksh: [: ']' missing
| |
| Solaris 10$ [ -d /blahblah ]
| |
| Solaris 10$ echo $?
| |
| 1
| |
| Solaris 10$ echo $SHELL
| |
| /bin/bash
| |
| Solaris 10$ test "$SHELL" = "/bin/bash"
| |
| Solaris 10$ echo $?
| |
| 0
| |
| Solaris 10$ test "$SHELL" = "/bin/nobash"
| |
| Solaris 10$ echo $?
| |
| 1
| |
| Solaris 10$ [ "$SHELL" = "/bin/bash" ]
| |
| Solaris 10$ echo $?
| |
| 0
| |
| Solaris 10$ [ "$SHELL" = "/bin/nobash" ]
| |
| Solaris 10$ echo $?
| |
| 1
| |
| Solaris 10$ ls -l /etc/group
| |
| -rw-r--r-- 1 root root 707 Apr 20 14:35 /etc/group
| |
| Solaris 10$
| |
| Solaris 10$ test -x /etc/group
| |
| Solaris 10$ echo $?
| |
| 1
| |
| Solaris 10$ test -r /etc/group
| |
| Solaris 10$ echo $?
| |
| 0</pre>
| |
| | |
| test options used in above example (from man page):
| |
| * -r FILE exists and read permission is granted
| |
| * -x FILE exists and execute (or search) permission is granted
| |
| * -d FILE exists and is a directory
| |
|
| |
|
| | To be populated... |
|
| |
|
| <center>[[Computing|To Computing Area]]</center> | | <center>[[Computing|To Computing Area]]</center> |