Difference between revisions of "Solaris"
Line 364: | Line 364: | ||
$</pre> | $</pre> | ||
'''The -F option shows file types''' | |||
Example using -F option: | |||
<pre>$ ls -F /export/home/paul | <pre>$ ls -F /export/home/paul | ||
dir1/ dir2/ local.cshrc local.profile symbolic_file@ | dir1/ dir2/ local.cshrc local.profile symbolic_file@ | ||
Line 369: | Line 372: | ||
$</pre> | $</pre> | ||
Example using -FR options together: | |||
<pre>$ ls -FR /export/home/paul | <pre>$ ls -FR /export/home/paul | ||
/export/home/paul: | /export/home/paul: |
Revision as of 08:56, 6 May 2011
My Solaris 10 notes
Main source:
Oracle Solaris 10 Operating System Essentials
useful links
Why can't I create home directory
Components of Sun OS
Three components of Sun OS
- 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
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:
- Bash shell - GNU project Bourne Again SHell is bourne compatible shell that contains handy features from Korn and C shell.
- Z shell - resembles Korn shell plus enhancements
- TC shell - C compatible shell plus enhancements
Logging into Sun OS
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
- 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 command
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 (text file), @(symbolic link))
From ls man page the first character printed out using various options:
The mode printed when the -e, -E, -g, -l, -n, -o, -v, -V, or -@ option is in effect consists of eleven characters. The first character can be one of the following: d The entry is a directory. D The entry is a door. l The entry is a symbolic link. b The entry is a block special file. c The entry is a character special file. p The entry is a FIFO (or "named pipe") special file. P The entry is an event port. s The entry is an AF_UNIX address family socket. - The entry is an ordinary file.
ls command options
From ls man page the options supported by ls command:
OPTIONS The following options are supported: /usr/bin/ls, /usr/xpg4/bin/ls, and /usr/xpg6/bin/ls The following options are supported for all three versions: -a Lists all entries, including those that begin with a dot (.), which are normally not listed. -A Lists all entries, including those that begin with a dot (.), with the exception of the work- ing directory (.) and the parent directory (..). -b Forces printing of non-printable characters to be in the octal \ddd notation. -c Uses time of last modification of the i-node (file created, mode changed, and so forth) for sorting (-t) or printing (-l or -n). -C Multi-column output with entries sorted down the columns. This is the default output format. -d If an argument is a directory, lists only its name (not its contents). Often used with -l to get the status of a directory. -e The same as -l, except displays time to the second, and with one format for all files regardless of age: mmm dd hh:mm:ss yyyy. -E The same as -l, except displays time to the nanosecond and with one format for all files regardless of age: yyyy-mm-dd hh:mm:ss.nnnnnnnnn (ISO 8601:2000 format). In addition, this option displays the offset from UTC in ISO 8601:2000 standard format (+hhmm or -hhmm) or no characters if the offset is indeterminable. The offset reflects the appropriate standard or alternate offset in force at the file's displayed date and time, under the current timezone. -f Forces each argument to be interpreted as a directory and list the name found in each slot. This option turns off -l, -t, -s, and -r, and turns on -a. The order is the order in which entries appear in the directory. -g The same as -l, except that the owner is not printed. -h All sizes are scaled to a human readable for- mat, for example, 14K, 234M, 2.7G, or 3.0T. Scaling is done by repetitively dividing by 1024. -H If an argument is a symbolic link that refer- ences a directory, this option evaluates the file information and file type of the directory that the link references, rather than those of the link itself. However, the name of the link is displayed, rather than the referenced direc- tory. -i For each file, prints the i-node number in the first column of the report. -l Lists in long format, giving mode, ACL indica- tion, number of links, owner, group, size in bytes, and time of last modification for each file (see above). If the file is a special file, the size field instead contains the major and minor device numbers. If the time of last modification is greater than six months ago, it is shown in the format `month date year' for the POSIX locale. When the LC_TIME locale category is not set to the POSIX locale, a dif- ferent format of the time field can be used. Files modified within six months show `month date time'. If the file is a symbolic link, the filename is printed followed by "->" and the path name of the referenced file. -L If an argument is a symbolic link, this option evaluates the file information and file type of the file or directory that the link references, rather than those of the link itself. However, the name of the link is displayed, rather than the referenced file or directory. -m Streams output format. Files are listed across the page, separated by commas. -n The same as -l, except that the owner's UID and group's GID numbers are printed, rather than the associated character strings. -o The same as -l, except that the group is not printed. -p Puts a slash (/) after each filename if the file is a directory. -q Forces printing of non-printable characters in file names as the character question mark (?). -r Reverses the order of sort to get reverse alphabetic or oldest first as appropriate. -R Recursively lists subdirectories encountered. -s Indicate the total number of file system blocks consumed by each file displayed. -t Sorts by time stamp (latest first) instead of by name. The default is the last modification time. (See -u and -c.) -u Uses time of last access instead of last modif- ication for sorting (with the -t option) or printing (with the -l option). -v The same as -l, except that verbose ACL infor- mation is displayed as well as the -l output. ACL information is displayed even if the file or directory doesn't have an ACL. -V The same as -l, except that compact ACL infor- mation is displayed after the -l output. The -V option is only applicable to file sys- tems that support NFSv4 ACLs, such as the Solaris ZFS file system.
ls command examples
View non-hidden contents of directory:
$ ls /export/home/paul dir1 dir2 local.cshrc local.profile symbolic_file dir1_files dir3 local.login script $
View long listing of non-hidden contents of directory:
$ ls -l /export/home/paul total 14 drwxr-xr-x 3 paul cops 512 May 5 12:36 dir1 -rw-r--r-- 1 paul cops 180 May 5 15:47 dir1_files drwxr-xr-x 2 paul cops 512 May 5 12:34 dir2 drwxr-xr-x 2 paul cops 512 May 5 12:34 dir3 -rw-r--r-- 1 paul cops 136 May 4 09:51 local.cshrc -rw-r--r-- 1 paul cops 157 May 4 09:51 local.login -rw-r--r-- 1 paul cops 174 May 4 09:51 local.profile -rwxr--r-- 1 paul cops 0 May 5 12:56 script -rw-r--r-- 1 paul cops 0 May 5 12:34 symbolic_file $
View long listing of all contents of directory:
$ ls -la /export/home/paul total 22 drwxr-xr-x 5 paul cops 512 May 6 09:17 . drwxr-xr-x 6 root root 512 May 6 09:15 .. -rw-r--r-- 1 paul cops 144 May 6 09:15 .profile -rw------- 1 paul cops 14 May 6 09:15 .sh_history drwxr-xr-x 3 paul cops 512 May 5 12:36 dir1 -rw-r--r-- 1 paul cops 180 May 5 15:47 dir1_files drwxr-xr-x 2 paul cops 512 May 5 12:34 dir2 drwxr-xr-x 2 paul cops 512 May 5 12:34 dir3 -rw-r--r-- 1 paul cops 136 May 4 09:51 local.cshrc -rw-r--r-- 1 paul cops 157 May 4 09:51 local.login -rw-r--r-- 1 paul cops 174 May 4 09:51 local.profile -rwxr--r-- 1 paul cops 0 May 5 12:56 script -rw-r--r-- 1 paul cops 0 May 5 12:34 symbolic_file $
Example using -d on directory, -d is useful if you want to only see directories specified as argument (versus contents of directory), more useful if combined with -l option:
$ ls -d /export/home/paul /export/home/paul $ ls /export/home/paul dir1 dir2 local.cshrc local.profile symbolic_file dir1_files dir3 local.login script $
Example using -d with -l option together in addition to using two arguments with one ls command:
$ ls -ld /export/home/paul drwxr-xr-x 5 paul cops 512 May 6 09:17 /export/home/paul $
Example of recursively listing subdirectories & contents:
$ ls -R /export/home/paul /export/home/paul: dir1 dir2 local.cshrc local.profile symbolic_file dir1_files dir3 local.login script /export/home/paul/dir1: file1 file2 file3 subdir1 /export/home/paul/dir1/subdir1: subfile1 subfile2 subfile3 /export/home/paul/dir2: /export/home/paul/dir3: $
The -F option shows file types
Example using -F option:
$ ls -F /export/home/paul dir1/ dir2/ local.cshrc local.profile symbolic_file@ dir1_files dir3/ local.login script* $
Example using -FR options together:
$ ls -FR /export/home/paul /export/home/paul: dir1/ dir2/ local.cshrc local.profile symbolic_file@ dir1_files dir3/ local.login script* /export/home/paul/dir1: file1 file2 file3 subdir1/ /export/home/paul/dir1/subdir1: subfile1 subfile2 subfile3 /export/home/paul/dir2: /export/home/paul/dir3: $
Use file command
use file
command to determine certain file types
Syntax:
- file filename
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:
cp source_file target_file
Copy multiple files to a different directory (relative path example):
cp source_file1 source_file2 target_directory
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:
mv file1 file2
Move file1 to another directory:
mv file1 ../
Move & rename file1 to file2 in another directory:
mv file1 ../file2
Move & rename directory1 to directory2 in same directory:
mv directory1 directory2
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)
$(command)
(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:
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
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:
$ history ls dir
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:
$ history 609 mkdir test 610 cd test 611 pwd 612 cd space 613 ls -l $ r 613
Rerun the most recent occurrence of a command that begins with "c":
$ r c cd space
Rerun the most recent occurrence of a command that begins with "c", replace space with water, and perform the modified command:
$ history 609 mkdir test 610 cd test 611 pwd 612 cd space 613 ls -l $ r c cd space $ r space=water cd water
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:
set -o | grep -w vi
Edit and execute previously executed command:
- use
history
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
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:
command < filename
<insert examples>
standard output
Greater-than sign (>) sends output from a command to a file
Syntax:
command > filename
<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:
command 2> filename
<insert examples>
Pipe character
Use pipe character (|) to redirect standard output to standard input another command
Syntax:
command | command
<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:
ps -ef | sort +1 | more
- 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
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
.profile
- 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 ls -l
command
<insert figure & examples, explain each column>
types of users
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
permission | character | file access | directory access |
---|---|---|---|
read | r | view file contents & copying of file | view listing of directory with ls command
|
write | w | change file contents | change directory contents (delete requires w+x) |
execute | x | execute file (execute shell script requires r+x) | change to directory by using cd command, can use ls 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 ls -n
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
chmod
command to change permission sets on files & directories - owner or root can use
chmod
command chmod
command can change permissions using symbolic (r,w,e,-,+) or octal (0-7) mode
Syntax examples:
- symbolic mode is
chmod symbolic_mode filename
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
chmod octal_mode filename
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:
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
umask
command to apply user mask value & modify default permissions umask
is a three-digit octal value for read, write, execute- default user mask for Solaris 10 is 022
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
permission field symbolic 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
permission field symbolic 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
umask
command to change at user initialization or command line (existing session only) - syntax:
- to show umask <ocde>umask
- to set umask at command line
umask octal_mode
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
ACL command examples | description |
---|---|
getfacl -a filename_or_directoryname
|
shows name, owner, group, & ACL entries for file & directory |
setfacl -m acl_entries filename_or_directoryname
|
modifies ACL entries on file & directory |
setfacl -s acl_entries filename_or_directoryname
|
substitutes new ACL entries on file & directory |
setfacl -d acl_entries filename_or_directoryname
|
|
setfacl -r [-m,-s] filename_or_directoryname
|
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
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 |
|
permissions for specific user that must exist in /etc/passwd file |
|
permissions for specific group that must exist in /etc/group file |
m:permission |
|
Determining Non-trivial ACL entries
Use ls -l
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 getfacl
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 grep
, egrep
, fgrep
commands
grep command
grep
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:
grep options pattern filename
From grep man page:
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 \>.
Definition | |
-i | ignore case sensitivies |
-l | print only the names of files with matching lines, does not repeat the names of files when pattern is found >1 |
-n | precedes each line by its line number in the file |
-v | prints all lines except those that contain the pattern |
-c | prints only a count of lines that contain the pattern |
-w | search for the expression as a word as if surrounded by
\< and \>, ignoring matches that are substrings of larger words |
<insert examples using grep>
Regular expression metacharacters
Metacharacter | Purpose | Example | Result |
^ | begining of line anchor | '^pattern' | matches all lines beginning with pattern |
$ | end of line anchor | 'pattern$' | matches all lines ending with pattern |
. | matches one character | 'p.....n' | matches lines containing a "p", followed by five characters, and followed by an "n" |
* | matches the preceding item zero or more times | '[a-z]*' | matches lowercase alphabet characters only |
[ ] | matches one character in a pattern | '[Pp]attern' | matches lines containing Pattern or pattern |
[^] | matches one character not in the pattern | '[^a-m]attern' | matches lines that do not contain a-m and followed by attern |
<insert examples regular expression metacharacters>
egrep command
egrep
command searches the contents of one or more files for a pattern using extended regular expression metacharacters (regular expression characters plus more)
Syntax:
egrep options pattern filename
Metacharacter | Purpose | Example | Result |
+ | matches one or more of the preceding characters | '[a-z]+ark' | matches one or more lowercase letters followed by ark |
x|y | matches either x or y | 'boat|airplane' | matches for either expresssion |
(|) | group characters | '(1|2)+' 'gam(es|ing)+' |
matches for one or more occurrences (1 or 2, games or gaming) |
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:
$ egrep '[a-z]+body' /etc/passwd
to search for lines containing the pattern Network Admin or uucp Admin, perform the command:
$ egrep '(Network|uucp) Admin' /etc/passwd
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:
fgrep options string filename
examples using fgrep
search for all lines in the file containing an * character, use the command:
$ fgrep '*' /etc/system
search for a string adm in all files in the current directory with the names ending with .sh string, use the command:
$ fgrep adm *.sh
searching for files and directories
find command
use find
command to locate files or directories in the directory hierarchy
find
command recursively descends the directory tree in the path name list, looking for files that match search criteria
as find
command matches files matching search criteria the absolute path for each file is displayed on screen
syntax:
find pathname expression action
find
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
and
, 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 find
command
expression | definition |
-name filename | finds files matching the specified filename, metacharacters are acceptable if placed inside quote marks " " or ' ' |
-size [+|-]n | finds files that are > +n or < -n or = n. n is 512-byte blocks |
-atime [+|-]n | finds files that have been accessed > +n or < -n or = n. n is days |
-mtime [+|-]n | find files that have been modified > +n or < -n or = n. n is days |
-user userID | finds all files that are owned by the userID |
-type | finds a file type, for example f = file and d = directory |
-perm | finds files that have certain access permission bits |
find actions
action | definition |
-exec command {} \; | 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 (\) |
-ok command {} \; | requires confirmation before find command applies the command to each file located. this is the interactive form of the -exec command |
instructs the find command to print the current path name to terminal session. this is the default | |
-ls | 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 |
find examples
<insert examples>
search home directory looking for files or directories called deleteme and asking before deleting any matches perform this command:
$ find ~ -name deleteme -ok rm {} \;
to look for all files that have not been modified in the last two days starting in current directory perform this command:
$ find . -mtime +2
to find files larger than 10 blocks (512-byte blocks X 10 = 5,120 bytes) starting in your home directory perform this command:
$ find ~ -size +10
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:
ps options
ps options
From ps man pages:
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.
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:
# 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 #
pgrep
use pgrep command to search for specific process by name
Syntax:
- pgrep options pattern
pgrep man options:
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.
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:
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:
pkill [-options] pattern
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
command
value
jobs
lists all jobs currently running or are stopped in background
bg %n
runs the current or specified job in the background (n = job ID)
fg %n
brings current or specified job into foreground (n = job ID)
Ctrl+Z
stops foreground job and places it in the background as a stopped job
stop %n
stops a job that is running in the background (n = job ID)
Korn shell alias utility
- alias is shorthand notation in Korn shell enabling user to customize Unix commands
- alias is defined by using the
alias
command
- Syntax:
alias name=command_string
View aliases in Korn shell with alias command
Example:
$ 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 $$'
$
Making alias for one command
Examples:
$ alias rm='rm -i'
<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:
$ alias info='uname -a; id; date'
<insert more examples>
Removing aliases
use unalias
command to remove aliases from the alias list
Syntax:
unalias alias_name
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
function_name { command; ... command; }
- Ensure a space is inserted between brackets
- invoke a function syntax
$ function_name
- list all functions with definitions use command
$ typeset -f
- list all functions by name use command
$ typeset +f
customize Korn shell prompt
customize prompt string stored in PS1 shell variable example then run date command:
$ 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
Korn shell options
- options are switches that control the behavior of Korn shell
- options are Boolean, either on or off
- set option on syntax:
$ set -o option_name
- set option off syntax:
$ set +o option_name
- show current option settings syntax:
$ set -o
Example:
$ 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
$
<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:
#! /full-pathname-of-shell
- Example with Korn shell would be
#! /bin/ksh
- 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 positional parameters
Example passing values:
$ more testscript
#! /bin/ksh
echo $1 $2 #echo the first two parameters passed
$ ./testscript really now
really now
$
using shift command
- Bourne shell accepts only single digit after $ sign while using positional parameter (cannot access tenth argument using $10 notation)
shift
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
$?
special shell variable and can be tested using echo
command
using test command
- test command is useful in shell scripts to verify conditions, some conditions:
- variable contents
- file access permissions
- file types
- syntax:
test expression
or [ expression ]
- 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:
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
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
Executing conditional commands
- && and || conditional constructs
- && ensures that a command is performed only if the preceding command succeeds
- || ensures that a command is performed only if the preceding command fails
- if command
- while command
- case command
Examples using && and ||:
Solaris 10$ pwd
/home/user1
Solaris 10$ mkdir $HOME/newdir && cd $HOME/newdir
Solaris 10$ pwd
/home/user1/newdir
Solaris 10$ mkdir /opt/newdir || cd /tmp
mkdir: cannot create directory `/opt/newdir': Permission denied
Solaris 10$ pwd
/tmp
Solaris 10$ mkdir /opt/newdir && cd $HOME/newdir
mkdir: cannot create directory `/opt/newdir': Permission denied
Solaris 10$ pwd
/tmp
Solaris 10$
- if command evaluates the exit status of a command to determine next action based on the returned exist value.
- exit value = zero the if command runs commands within then section
- exit value not equal to zero then if command runs commands within else section
- always close if statement with fi
Syntax:
if expression
then
command1
else
command2
fi
<add examples of if command>
using while command
while command helps repeat a command or group of commands
if exit result of expression is zero (success) then while will execute the do command and loop back to repeat expression
non-zero result status means loop will terminate
Syntax:
while expression
do
command
done
<add examples>
using case command
case command compares a single value against other values & performs a command or group of commands when a match is found
when match is found no other patterns are checked
Syntax:
case value in
pattern1) command
...
;;
pattern2) command
...
;;
patternN) command
...
;;
esac
<provide examples of using case command>
Archiving files
tar or jar commands are two commonly used archiving commands
- use tar command to create & extract files from a file archive
- tar command archives files to & extracts files from a single file called a tar file
- default device for tar file is magnetic tap device
- Syntax:
tar functions archivefilename filenames
Functions for tar command:
function
definition
c
creates a new tar file
t
lists the table of contents of the tar file
x
extract files from the tar file
v
executes in verbose mode, writes to the standard output
f
- specifies archive file or tape device
- default tape device is /dev/rmt/0
- if name of archive file is "-" the tar command reads from standard input when reading from a tar archive or writes to standard output if create tar archive
h
follows symbolic links as standard files or directories
Examples using tar: <insert examples using tar>
archive on USB drive
Volume Management daemon, vold, provides automatic detection of removable media
<add info volcheck command>
if not detected but not mounted run $ volrmmount -i rmdisk0
perform volrmmount command to create the /rmdisk directory and its contents when a flash drive is present
access files of flash drive by changing to /rmdisk/rmdisk0 directory
eject flash drive by using eject
command example syntax: eject rmdisk0
cannot be in working directory of the removable media while attempting to eject
using jar
command
- use
jar
command to compress & combine multiple files into a single archive
- Syntax:
jar options destination filenames
Options for tar command:
function
definition
c
creates a new jar
file
t
lists the table of contents of the jar
file
x
extract files from the jar
file
f
specifies jar
file to process, the jar
command sends data to screen if f
option is not used
v
executes in verbose mode
<insert examples using jar
command>
compressing files
using compress
command
Syntax: compress [ -v ] filename
compress command replaces the original file with a new file that has a .Z extension
<insert examples using compress
command>
$ compress -v file1.tar
using 7za
command
Syntax: 7za command archivefile filenames
or 7za command archivefile directory
<insert examples using 7za
command>
zcat
command
use zcat
command to view files that were compressed by the compress
command
zcat
command allows user to view contents of file & doesn't modify contents of a compressed file
Syntax: zcat filename
<insert examples of zcat
command>
Extract contents of compressed tar without uncompressing the tar file first:
$ zcat files.tar.Z | tar xvf -
uncompressing files
use uncompress
command to uncompress
Syntax: uncompress options filename
<insert examples of uncompress command>
gzip
command
use gzip
to compress files
Syntax: $ gzip [ -v ] filenames
use gzip
to uncompress files that have been compressed with gzip
Syntax: gzip filename
<insert examples of gzip filename
use gzcat
command
use gzcat filename
command to !!view!! files that were compressed with compress
or gzip
commands
original file is unchanged
Syntax: gzcat filename
<insert examples of using gzcat
command>
use zip & unzip
command
- use
zip
command to compress multiple files into a single archive file
- syntax:
zip target_filename source_filenames
- by default zip will add .zip extension
- use
zip
command to uncompress a zipped file
- syntax:
zip filename
- use
unzip
command with -l
option to list the files in a zip archive
- syntax:
unzip -l filename
<insert examples of using zip and unzip commands>
Remote login
~/.rhosts file
- ~/.rhosts file provides an authentication mechanism to determine if remote user can access local host with identify of local user
- ~/.rhosts bypasses the password authentication mechanism (/etc/passwd)
- if ~/.rhosts exists in local host user home directory the remote user can access local system
- plus character (+) in .rhosts allows user remote access from any known system without a password
use rlogin
command
- use
rlogin
command to establish remote login session on remote system
- syntax:
rlogin options hostname
-l
option allows user to specify user name for remote login session
- syntax:
rlogin -l username hostname
use rsh
command
- use
rsh
command to run a command on a remote system without having to log on to the remote system
- syntax:
rsh hostname command
- only works if remote system has ~/.rhosts file
if system does not respond to input the system may be frozen, use rlogin to access system remotely & terminate corrupted session
example:
$ rlogin remotehost
$ pkill shell
telnet command
- use
telnet
command to log on to remote system
- syntax:
telnet hostname
Virtual Network Computing
- Virtual Network Computing (VNC) provides a desktop session over Remote Frame Buffer (RFB) protocol
- VNC has two components
- X VNC server
- VNC client for X
X VNC Server
- Xvnc is an X VNC server that allows sharing of Solaris 10 X windows sessions with another Solaris, Linux, or Windows system
- use
vncserver
command to start or stop an Xvnc server
- syntax:
vncserver options
vncserver
command, when run for first time, runs the vncpasswd
command to set a password for accessing X windows sessions
VNC client for X
- Vncviewer is an X VNC client that allows viewing an X windows session from a remote Solaris, Linux, or Windows system on a Solaris 10 system
- use
vncviewer
command to establish a connection to a Xvnc server
- syntax:
vncviewer options host:display#
copying files or directories to and from remote systems
- use
rcp
command to copy files or directories from one host to another
- only works if remote system has ~/.rhosts file
- to copy directories & sub-directories use -r option
syntax:
rcp source_file_or_directory hostname:copied_file_or_directory
or
rcp hostname:source_file_or_directory copied_file_or_directory
or
rcp hostname:source_file_or_directory hostname:copied_file_or_directory
Transferring files between systems
- use
ftp
command (File Transfer Protocol) to transfer files between systems
- ftp enables user to specify login of user
- ftp command prompts for a user password
- syntax:
ftp hostname
FTP transfer modes
- FTP supports two transfer modes:
- American Standard Code for Information Interexchange (ASCII)
- binary
- ASCII mode is used when transferring text files
- binary mode is used when transferring non-text files
- binary mode is default for FTP
some FTP commands:
commands
definition
ls
lists files and directories on FTP server
cd
changes directory on FTP server
lcd
changes directory on local system
mget
multiple get command copies multiple files from FTP server to local system
mput
multiple put command copies multiple files from local system to FTP server
prompt
switches interactive prompting on or off
bye
ends FTP session
To Computing Area