Archive for January, 2021

Working with Shell

January 24th, 2021, posted in Solaris
In this section we will work with shell.

Shell is an interface between a user and the kernel. It is a command interpreter which interprets the commands entered by user and sends to kernel.

The Solaris shell supports three primary shells:
Bourne Shell:
It is original UNIX system shell.
It is default shell for root user.
The default shell prompt for the regular user is $ and root is #.
C Shell:
It has several features which bourne shell do not have.
The features are:
It has command-line history, aliasing, and job control.
The shell prompt for regular user is hostname% and for root user hostname#.
Korn Shell:
It is a superset of Bourne Shell with C shell like enhancements and additional features like command history, command line editing, aliasing & job control.

Alternative shells:
Bash(Bourne Again shell): It is Bourne compatible shell that incorporates useful features from Korn and C shells, such as command line history and editing and aliasing.
Z Shell: It resembles Korn shell and includes several enhancements.
TC Shell: It is completely compatible version of C shell with additional enhancements.

Shell Metacharacters:
Lets understand Shell Metacharacters before we can proceed any further.  These are the special characters, generally symbols that has specific meaning to the shell.There are three types of metacharacters:
1. Pathname metacharacter
2. File name substitution metacharacter
3. Redirection metacharacterPath Name Metacharacters:
Tilde (~) character: The ‘~’ represents the home directory of the currently logged in user.It can be used instead of the user’s absolute home path.Example : Lets consider ravi is the currently logged in user.
#cd ~
#cd ~/dir1
#cd ~immam
Note: ‘~’ is available in all shells except Bourne shell.

Dash(-) character: The ‘-‘ character represents the previous working directory.It can be used to switch between the previous and current working directory.
#cd ~
#cd –
#cd –

File Name Substitution Metacharacters :
Asterisk (*) Character: It is a called wild card character and represents zero or more characters except for leading period ‘.’ of a hidden file.
#ls dir*
dir1 dir2 directory1 directory2
Question Mark (?) MetacharactersIt is also a wild  card character and represents any single character except the leading period (.) of a hidden file.
#ls dir?
dir1 dir2
Compare the examples of Asterisk and Question mark metacharacter and you will get to know the difference.

Square Bracket Metacharacters: It represents a set or range of characters for a single character position.
The range list can be anything like : [0-9], [a-z], [A-Z].
#ls [a-d]*
apple boy cat dog
The above example will list all the files/directories starting with either ‘a’ or ‘b’ or ‘c’ or ‘d’.
#ls [di]*
dir1 dir2 india ice
The above example will list all the files starting with either ‘d’ or ‘i’.

Few shell metacharacters are listed below:

~ The ‘~’ represents the home directory of the currently logged in user
The ‘-‘ character represents the previous working directory
* A wild card character that matches any group of characters of any length
? A wild card character that matches any single character
$ Indicates that the following text is the name of a shell (environment) variable whose value is to be used
| Separates command to form a pipe and redirects the o/p of one command as the input to another
< Redirect the standard input
> Redirect the standard output to replace current contents
>> Redirect the standard output to append to current contents
; Separates sequences of commands (or pipes) that are on one line
\ Used to “quote” the following metacharacter so it is treated as a plain character, as in \*
& Place a process into the background

Korn Shell Variables: It is referred to as temporary storage area in memory.It enables us to store value into the variable. These variables are of two types :
1. Variables that are exported to subprocesses.
2. Variables that are not exported to subprocesses.Lets check few commands to work with these variables:
To set a variable 
#export VAR
Note: There is no space on the either side of the ‘=’ sign.

To unset a variable
#unset VAR

To display all variables:  
We can use ‘set’ or ‘env’ or ‘export’ command.

To display value of a variable
echo $VAR or print $VAR
Note: When a shell variable follows $ sign, then the shell substitutes it by the value of the variable.

Default Korn Shell Variables :
EDITOR : The default editor for the shell.
FCEDIT : It defines the editor for the fc command.
HOME : Sets the directory to which cd command switches.
LOGNAME : Sets the login name of the user.
PATH : It specifies the paths where shell searches for a command to be executed.
PS1 :It specifies the primary korn shell ($)
PS2 : It specifies the secondary command prompt (>)
SHELL : It specifies the name of the shell.

Using quoting characters:

Quoting is the process that instructs the shell to mask/ignore the special meaning of the metacharacters. Following are few use of the quoting characters:

Single quotation mark (”): It instructs the shell to ignore all enclosed metacharacters.
#echo $SHELL
#echo ‘$SHELL’
Double quotation mark (“”): It instructs the shell to ignore all enclosed shell metacharacters, except for following :
1. The single backward quotation(`) mark : This executes the solaris command inside the single quotation.Example: 
# echo “Your current working directory is `pwd`”
Your current working directory is /export/home/immam
In the above example the ‘`’ is used to execute the ‘pwd’ command inside the quotation mark.

2. The blackslash(\) in the front of a metacharacter : This ignores the meaning of the metacharacter.Example: 
#echo “$SHELL”
#echo “\$SHELL”
In the above example, the inclusion of ‘\’ ignores the meaning of metacharacter ‘$’

3. The ‘$’ sign followed by command inside parenthesis : This executes the command inside the parenthesis.Example: 
# echo “Your current working directory is $(pwd)”
Your current working directory is /export/home/immam

In the above example enclosing the pwd command inside parenthesis and $ sign before parenthesis, executes the pwd command.

Displaying the command history:
The shell keeps the history of all the commands entered. We can re-use this command in our ways. For a given user this list of command used is shared among all the korn shells.
Syntax: history option
The output will somewhat like following :

125 pwd
126 date
127 uname -a
128 cd
The numbers displayed on the left of the command are command numbers and can be used to re-execute the command corresponding to it.To view the history without command number -n option is used : #history -n

To display the last 5 commands used along with the current command :
#history -5
To display the list in reverse order:
#history -r
To display most recent pwd command to the most recent uptime command, enter the following:
#history pwd uptimeNote: The Korn shell stores the command history in file specified by the HISTFILE variable. The default is the ~/.sh_history file. By default shell stores most recent 128 commands.

Note: The history command is alias for the command “fc -l”.

The ‘r’ command :
The r command is an alias in Korn Shell that enables us to repeat a command.
/export/home/immamThis can be used to re-execute the commands from history.

126 pwd
127 cd
128 uname -a
#r 126
The ‘r’ command can also be used to re-execute a command beginning with a particular character, or string of charactersExample:
# r p
In the above example the ‘r’ command is used to re-run the most recent occurrence of the command starting with p.
#r ps
ps -ef
o/p of ps -ef command
In the above example the ‘r’ command is used to re-run the most recent command starting with ps.
We can also edit the previously run command according to our use. The following example shows that :
#r c
cd ~/dir1
#r dir1=dir
cd ~/dir
In this example the cd command has re-run but the argument passed to it has been changed to dir from dir1.

Note: The r command is alias for the command ” fc -e – “.

Editing the previously executed commands using vi-editor :
We can also edit the previously executed command under history using vi-editor. To do so, we need to enable shell history editing by using any one of the following commands :
#set -o vi
#export EDITOR=/bin/vi
#export VISUAL=/bin/viTo verify whether this feature is turned on, use the following command :
#set -o | grep -w vi
vi                on

Once it is on you can start editing the command history as follows :
1. Execute the history command: #history
2. Press Esc key and start using the vi editing options.
3. To run a modified command, press enter/return key.

File Name Completion : 
Suppose you are trying to list files under the directory “/directoryforlisting“. This is too big to type. There is a short method to list this directory.
Type ls d and then press Esc and then \ (backslash) key. The shell completes the file name and will display :
#ls directoryforlisting/We can also request to display all the file name beginning with ‘d’ by pressing Esc and = key sequentially.

Two points to be noted here :
1. The key sequence presented above works only in the vi mode of the command line editing.
2. The sequence in which the key is pressed is important.

Command Redirection:
There are two redirection commands:
1. The greater than (>) sign metacharacter
2. The less than (<) sign metacharacter
Both the above mentioned mentioned commands are implied by pipe (|) character.The File Descriptors:
Each process works with shell descriptor. The file descriptor determines where the input to command originates and where the output and error messages are sent.

File Descriptor Number
File Description Abbreviation
0 stdin Standard Command input
1 stdout Standard Command output
2 stderr Standard Command error
All command that process file content read from the standard input and write to standard output.Redirecting the standard Input:
command < filename or command 0<filename
The above command the “command” takes the input from “filename” instead of keyboard.

Redirecting the standard Output:
command > filename or command 1>filename
#ls -l ~/dir1 > dirlist
The above command redirects the output to a file ‘dirlist’ instead of displaying it over the terminal.
command >> filename
#ls -l ~/dir1 >> dirlist
The above example appends the output to the file ‘dirlist’.

Redirecting the Standard Error:
command > filename 2> <filename that will save error>
command> filename 2>&1
The first example will redirect the error to the file name specified at the end.
The second example will redirect the error to the input file itself.

The Pipe character :
The pipe character is used to redirect the output of a command as input to the another command.
Syntax: command | command
# ps -ef | grep nfsd
In the above example the output of ps -ef command is send as input to grep command.
#who | wc -l

User Initialization Files Administration :
In this section we will see initialization files of Bourne, Korn and C shell.
Initialization files at Login
System wide Initialization File
Primary user Initialization File Read at Login
User Initialization Files Read When a New Shell is Started
Shell Pathname
Bourne /etc/profile $HOME/.profile /bin/sh
Korn /etc/profile $HOME/.profile $HOME/.kshrc /bin/ksh
C /etc/.login $HOME/.cshrc $HOME/.cshrc /bin/csh
Bourne Shell Initialization file:
The .profile file in the user home directory is an initialization file which which shell executes when the user logs in. It can be used to a) customize the terminal settings & environment variables b)instruct system to initiate an application.

Korn Shell Initialization file: It has two initialization file :
1. The ~/.profile: The .profile file in the user home directory is an initialization file which which shell executes when the user logs in. It can be used to a) customize the terminal settings & environment variables b)instruct system to initiate an application.
2. The ~/.kshrc: It contains shell variables and aliases. The system executes it every time the user logs in and when a ksh sub-shell is started. It is used to define Korn shell specific settings. To use this file ENV variable must be defined in .profile file.Following settings can be configured in /.kshrc file :
Shell prompt definations (PS1 & PS2)
Alias Definitions
Shell functions
History Variables
Shell option ( set -o option)
The changes made in these files are applicable only when the user logs in again. To make the changes effective immediately, source the ~/.profile and ~/.kshrc file using the dot(.) command:
#. ~/.profile
#. ~/.kshrc
Note: The /etc/profile file is a separate system wide file that system administrator maintains to set up tasks for every user who logs in.

Shell Initialization file: It has two initialization file :
1. The ~/.cshrc file : The . cshrc file in the user home directory is an initialization file which which shell executes when the user logs in. It can be used to a) customize the terminal settings & environment variables b)instruct system to initiate an application.

Following settings can be configured in .cshrc file :
Shell prompt definations (PS1 & PS2)
Alias Definitions
Shell functions
History Variables
Shell option ( set -o option)
2. The ~/.login file: It has same functionality as .cshrc file and has been retained for legacy reasons.
Note: The /etc/.login file is a separate system wide file that system administrator maintains to set up tasks for every user who logs in.
The changes made in these files are applicable only when the user logs in again. To make the changes effective immediately, source the ~/.cshrc and ~/.login file using the source command:
#source ~/.cshrc
#source ~/.login
The ~/.dtprofile file : It resides in the user home directory and determines generic and customized settings for the desktop environment.The variable setting in this file can overwrite the default desktop settings. This file is created when the user first time logs into the desktop environment.
Important: When a user logins to the desktop environment, the shell reads .dtprofile, .profile and .kshrsc file sequentially. If the DTSOURCEPROFILE variable under .dtprofle is not ture or does not exists, the .profile file is not read by the shell.
The shell reads .profile and .kshrsc file when user opens console window.
The shell reads .kshrsc file when user opens terminal window.Configuring the $HOME/.profile file:
It can be configured to instruct the login process to execute the initialization file referenced by ENV variable.
To configure that we need to add the following into the $HOME/.profile file:
export ENV

Configuring the $HOME/.kshrc file :
This file contains korn shell specific setting.To configure PS1 variable, we need to add the following into the $HOME/.kshrc file:
PS1=””hostname’ $”
export PS1

Advanced Shell Functionality:

In this module we will learn four important aspects of Korn shell.
Managing Jobs in  Korn  Shell:
A job is a process that the shell can manage. Each job has a process id and it can be managed and controlled from the shell.
The following table illustrates the job control commands:
jobs List all jobs that are currently running or stopped in the background
bg %<jobID> Runs the specified job in background
fg %<jobID> Brings the  specified job in foreground
Ctrl+Z Stops the foreground job and places it in the background as a stopped job
stop %<jobID> Stops a job running in background

Note: When a job is placed either in foreground or background, the job restarts.
Alias Utility in Korn Shell :
Aliases in Korn shell can be used to abbreviate the commands for the ease of usage.
we are frequently using the listing command: ls -ltr. We can create alias for this command as follows:
#alias list=’ls -ltr’
Now when we type the ‘list’ over shell prompt and hit return, it replaces the ‘list’ with the command ‘ls -ltr’ and executes it.
Syntax : alias <alias name>=’command string’
1. There should not be any space on the either side of the ‘=’ sign.
2. The command string mustbe quoted if it includes any options, metacharacters, or spaces.
3. Each command in a single alias must be separated with a semicolon.e.g.:#alias info=’uname -a; date’The Korn shell has predefines aliases as well which can be listed by using ‘alias’ command:
stop=’kill -STOP’
suspend=’kill -STOP $$’
Removing Aliases
Syntax: unalias <alias name>
#unalias list

Korn Shell functions :

Function is a group of commands organized together as a separate routine. Using a function involves two steps :

1. Define the function: 
function <function name> { command;…command; }
A space must appear after the first brace and before the       closing brace.
#function HighFS{ du -ak| sort -n| tail -10; }
The above example defines a function to check the top 10 files using most of the space under current working directory.

2. Invoke the function :
If we want to run the above defined function, we just need to call it by its name.
6264    ./VRTSvcs/conf/config
6411    ./VRTSvcs/conf
6510    ./VRTSvcs
11312   ./gconf/schemas
14079   ./gconf/gconf.xml.defaults/schemas/apps
16740   ./gconf/gconf.xml.defaults/schemas
17534   ./gconf/gconf.xml.defaults
28851   ./gconf
40224   ./svc
87835   .

Note: If a function and an alias are defined by the same name, alias takes precedence.

To view the list of all functions :
#typeset -f -> This will display functions as well as their definitions.
#typeset +f -> This will display functions name only.

Configuring the Shell Environment variable:

The shell secondary prompt sting is stored in the PS2 shell variable, and it can be customized as follows:
#PS2=”Secondary Shell Prompt”
#echo PS2
Secondary Shell Prompt
To display the secondary shell prompt in every shell, it must be included in the user’s Korn Shell initialization file(.kshrc file)

Setting Korn Shell options :
Korn Shell options are boolean (on or off). Following is the Syntax:
To turn on an option:
#set -o option_nameTo turn off an option:
#set +o option_name

To display current options:
# set -o

#set -o noclobber
#set -o | grep noclobber
noclobber      onThe above example sets the noclobber option. When this option is set, shell refuses to redirect the standard output to a file and displays error message on the screen.

#df -h > DiskUsage
#vmstat > DiskUsage
ksh: DiskUsage: file already exists
To deactivate the noclobber option :
#set +o noclobber

Shell Scripts:

It is a text file that has series of command executed one by one. There are different shell available in Solaris. To ensure that the correct shell is used to run the script, it should begin with the characters #! followed immediately by the absolute pathname of the shell.


Comments: It provides information about the script files/commands. The text inside the comment is not executed. The comment starts with character ‘#’.
lets write our first shell script :
#cat MyFirstScript
ls -ltr #This is used to list the files/directories
Running a Shell Script :
The shell executes the script line by line. It does not compile the script and keep it in binary form. So, In order to run a script, a user must have read and execute permission.
The above example runs the script in sub-shell. If we want to run the script as if the commands in it were ran in same shell, the dot(.) command is used as follows:
#. ./MyFirstScriptPassing Value to the shell script:
We can pass value to the shell script using the pre-defined variables $1, $2 and so on. These variables are called Positional Parameters. When the user run the shell script, the first word after the script name is stored in $1, second in $2 and so on.
#cat welcome
echo $1 $2
#welcome immam test
immam test

In the above example when we ran the script welcome, the two words after it ravi and ranjan was stored in $1 and $2 respectively.

Note: There is a limitation in Bourne shell. It accepts only a single number after $ sign. So if we are trying to access the 10th argument $10, it will result in the value of $1 followed by (0).
In order to overcome this problem, shift command is used.

Shift Command:
It enables to shift the value of positional parameter values back by one position i.e. the value of $2 parameter is assigned to $1, and $3 to $2, and so on.

Checking Exit status:
All commands under Solaris returns an exit status. The value ‘0’ indicates success and non-zero value ranging from 1-255 represents failure. The exit status of the last command run under foreground is held in ? special shell variable.

# ps -ef | grep nfsd
root  6525 22601   0 05:55:01 pts/11      0:00 grep nfsd
# echo ?
In the above example there is no nfsd process running, hence 1 is returned.

Using the test Command:
It is used for testing conditions. It can be used to verify many conditions, including:
Variable contents
File Access permissions
File types
Syntax : #test expression or #[ expression ]

The test builtin command returns 0 (True) or 1 (False), depending on the evaluation of an expression, expr.
Syntax:test expr or [ expr ]

We can examine the return value by displaying $?;
We can use the return value with && and ||; or we can test it using the various conditional constructs.

We can compare arithmetic values using one of the following:

Option Tests for Arithmetical Values
-eq equal to
-ne not equal to
-lt less than
-le less than or equal to
-gt greater than
-ge greater than or equal to

We can compare strings for equality, inequality etc. Following table lists the various options that can be used to compare strings:

Tests for strings
= equal to. 
e.g #test “string1” = “string2”
!= not equal to.  
e.g #test “string1” = “string2”
 < less than.  
e.g #test “ab” \< “cd”
> greater than.  
e.g #test  “ab” \> “cd” “
-z for a null string.  
e.g #test -z “string1” 
-n returns True if a string is not empty. 
e.g. #test -n “string1”

Note: the < and > operators are also used by the shell for redirection, so we must escape them using \< or \>.

Example : 

Lets test that the value of variable $LOGNAME is ravi.
#echo $LOGNAME
# test “LOGNAME” = “immam”
#echo $?

#[ “LOGNAME” = “immam” ]
#echo $?

Lets test if read permissions on the /immam
#ls -l /immam
-rw-r–r– 1 root sys 290 Jan 10 01:10 /immam
#test -r /immam
#echo $?

#[ -r /immam]
#echo $?

Lets test if /var is a directory
#test -d /var
#echo $?

#[ -d /var ]
#echo $?

Executing Conditional Commands : 
In this section we will see the following three conditional commands:
1. Using If command: It checks for the exit status of the command and if exist status is (0), then the statement are run other wise statement under else is executed.
#if command1
>execute command2
>execute command3

The shell also provides two constructs that enable us to run the command based on the success or failure of the preceding command.
The constructs are &&(and) and ||(or).
#mkdir /immam && /syed
This command creates directory /immam only if /syed is created.

#mkdir /immam|| /syed
This command creates directory /immam even if /syed fails to create.

2. Using while command: It enables to repeat a command or group of command till the condition returns (0).
#while command1

3. Using case command: It compares a single value against other values and runs a command or commands when a match is found.
#case value in



The special shell variable :

? This contains the return value of the last command
# This contains the number of arguments passed to the script
* It contains the value of all command line argument

Using VI Editor (Visual Editor)

January 17th, 2021, posted in Linux OS, Solaris

VI Editor (Visual Editor)

You must be familiar with notepad in windows which is used to edit a file. Like-wise we have VI editor in UNIX, LINUX & SOLARIS OS used widely for editing files.
However, Unlike notepad it is little tricky to use. I wish the VI editor would have been developed by Bill gates rather than Bill Joy.
Anyways, guys we don’t have any other option rather than getting aware of all these commands so that we become proficient in working with the VI Editor.

Understanding different modes in VI Editor:
There are three different modes in VI editors:
1. Command Mode
2. Insert/input Mode
3. EX mode

By default when you will open the VI editor, it will be in command mode. In the following sections we will see:
1. How to switch from one mode to another?
2. What are the different VI Commands that we can use in these modes.

Command Mode : 
This is default mode of the VI editor. In this mode we can delete, change, copy and move text.

VI Navigation Commands:

j(or down arrow) To move the cursor to the next line (move down) 
k(or up arrow) To move the cursor to the previous line (move up) 
h(or left arrow)  To move left one character
l(or right arrow) To move right one character
H To move the cursor to current page beginning of the first line.
G To move the cursor to current page beginning of the last line.
b To move the cursor previous word first character
e To move the cursor next word last character
w To move the cursor to next word first character
^ Go to beginning of line 
0 Go to beginning of line
$ Go to the end of the line
CTRL+F forward 1 screen
CTRL+B backward 1 screen
CTRL+D down (forward) 1/2 screen
CTRL+U up (backward) 1/2 screen

Copy & Paste:

Key Use
y+w  To copy rest of the word from current cursor position. 
n+y+w  To copy n number of words from the current cursor position.
y+y To copy a line
n+y+y To copy n lines
p(lowerCase) To paste a copied words/lines after the current position of the cursor
P(uppercase) To paste a copied words/lines before  the current position of the cursor


x deletes a single character 
n+X  To delete n number of characters from the cursor position in a line.
d+w To delete rest of a word from current cursor position
n+d+w  To delete n  number of words from the cursor position in a line
d$ Delete rest of line from current cursor position
D Delete rest of line from current cursor position
d+d To delete an entire line
n+d+d To delete n lines from current cursor position

Few More Important Command Mode VI commands:

u Undo changes (only one time) 
U Undo all changes to the current line 
~ To change the case of the letter
ZZ Saves the changes and quits the vi editor 

Input or Insert Mode: In this mode we can insert text into the file. We can enter the insert mode by pressing following keys in command mode:

i Inserts the text before the cursor 
I Inserts the text at the beginning of the line 
o Opens a new blank line below the cursor
O Opens a new blank line above the cursor
a Appends text after the cursor
A Appends the text after the line
r replace the single character with another character 
R replace a entire line
Esc To return to command mode

 Last line mode or Collan Mode : This is used for advance editing commands. To access the last line mode enter “:” while in command mode.

: To get to collan mode(This need to be entered every time a user wants to use collan mode command)
:+set nu Shows line numbers
:+set nonu Hides line numbers
:+enter+n  Moves the cursor to the n line
:+/keyword  To move the cursor to the line starting with the specific keyword
:+n+d Deletes nth line
:+5,10d Delete line from 5th line to 10th line
:+7 co 32 Copies 7th line and paste in 32nd line
:+10,20 co 35 Copies lines from 10th line to 20th line and paste it from 35th line

:+%s/old_text/new_text/g  Searches old string and replaces with the new string
:+q+! Quits vi editor without saving
:+w Saves the file with changes by writing to the disk
:+w+q Save and exit the vi editor
:+w+q+! Save and quit the VI Editor forcefully.
1,$s/$/” -type=Text_to_be_appended Append text at the end of the line

Using VI editor Command:

vi options <file name>
The options are discussed below:
-r : To recover a file from system crash while editing.
-R : To open a file in read only mode.


Viewing Files in Read Only Mode:
view <file name>
This is also used to open the file in read only mode. To exit type ‘:q‘ command.


Automatic Customization of a VI session:
1. Create a file in the user’s home directory with the name .exrc
2. enter the set variables without preceding colon
3. Enter each command in one line.
VI reads the .exrc file each time the user opens the vi session.
#cd ~
#touch .exrc
#echo “set nu”>.exrc
#cat .exrc
set nu
In the above example we have used set line number command. So whenever the user opens the vi session, line number is displayed.
I know its nearly impossible to keep all the above commands in mind, even I don’t have, but as we keep practicing, we will be knowing most of them.

Working With Directories And Files in Solaris

January 10th, 2021, posted in Solaris

Working with Files and DirectoriesAdd A User From The Command Line In Solaris,Add A User From The Command Line In Solaris 10,Add A User From The Command Line, In Solaris10 ,Add A User ,The Command Line In Solaris10,The Command Line In Solaris,solaris 10,

Working with Files and Directories is very basic thing which we dont want to miss while learning Solaris 10. Lets check few very basic commands.

To display the current working directory:

pwd command: It displays the current working directory.


To display contents of a  directory:

ls command (Listing Command): It displays all files and directories under the specified directory.
Syntax: ls -options <DirName>|<FileName>
The options are discussed as follows:

p It lists all the files & directories. The directory names are succeeded by the symbol ‘/’
F It lists all files along with their type. The symbols ‘/’, ‘*’, (None), ‘@’ at the end of file name represents directory, executable, Plain text or ASCII file & symbolic link respectively
a It lists all the files & directories name including hidden files
l It lists detailed information about files & directories
t It displays all the files & directories in descending order of their modified time.
r It displays all the files & directories in reverse alphabetical order
R It displays all the files & directories & sub-directories in recursive order
i It displays the inode number of  files & directories
tr It displays all the files & directories in the ascending order of their last modified date
Analysis of output of ls -l command:
ls -l → It list all the files and directories long list with the permission and other information. The output looks as follows:
FileType & Permissions LinkCount UID GID Size Last ModifiedDate & ModifiedTime <File/Directory Name>
Following table explains the output:
FileType ‘-‘ for file & ‘d’ for directory
Permissions Permissions are in order of Owner, Group & Other
LinkCount Number of links to the file
UID Owner’s User ID
GID Group’s ID
Size Size of the file/directory
Last ModifiedDate & ModifiedTime Last Modified Date & Time of the file/directory
<File/Directory Name> File/Directory name
# ls -l
total 6
-rw-r–r–   1 root     root        136 May  6  2010 local.cshrc
-rw-r–r–   1 root     root        167 May  6  2010 local.login
-rw-r–r–   1 root     root        184 May  6  2010 local.profile

Understanding permissions:

Following table explains the permission entry:

No permission/denied
r read permission
w write permission
x execute permission

File Command: It is used to determine the file type. The output of file command can be “text”, “data” or “binary”.
Syntax: file <file name>
# file data
data: English text

Changing Directories: ‘cd’ commad is used to change directories.
Syntax: cd <dir name>
If cd command is used without any option it changes the directory from current working directory to user’s home directory.

Example: Let the user be ‘ravi’ and current working directory is /var/adm/messages#pwd
#/export/home/raviThere is also a different way to navigate to the user’s home directory :
#cd ~ravi
#cd ~raju
#cd ~ravi/dir1
/export/home/ravi/dir1In the above examples, the ‘~’ character is the abbreviation that represents the absolute path of the user’s home directory. However this functionality is not available in all shells.There are few other path name abbreviations which we can use as well. These are listed below :
.  → current working directory
.. → Parent directory or directory above the current working  directory.
So if we want to go to the parent directory of the current working directory following command is used:
#cd ..We can also navigate multiple levels up in directory using cd, .. and /.
Example: If you want to move two levels up the current working directory, we will use the command :
#cd ../..
#cd ../..
#cd ..

Viewing the files:

cat command: It displays the entire content of the file without pausing.
Syntax: cat <file name>
#file data
data: English text
#cat data
This is an example for demonstrating the cat command.
Warning: The cat command should not be used to open a binary file as it will freeze the terminal window and it has to be closed. So check the file type using ‘file’ command, if you are not sure about it.more command: It is used to view the content of a long text file in the manner of one screen at a time.
Syntax: more <file name>The few scrolling options used with more command are as follows :

Scrolling Keys
Space Bar Moves forward one screen
Return Scrolls one line at a time
b Moves back one screen
h Displays a help menu of features
/string searches forward for a pattern
n finds the next occurrence of the pattern
q quits and returns to shell prompt

Head and Tail command in UNIX/LINUX/SOLARIS:
head command: It displays the first 10 lines of a file by default. The number of lines to be displayed can be changed using the option -n. The syntax for the head command is as follows:
Syntax: head -n <file name>
This displays the first n lines of the file.

tail command: It displays the last 10 lines of a file by default. The number of lines to be displayed can be changed using the options -n or +n.
#tail -n <file name>
#tail +n <file name>
The -n option displays the n lines from the end of the file.
The +n option displays the file from line n to the end of the file.

Displaying line, word and character count:
wc command: It is used to display the number of lines, words and characters in a given file.
Syntax: wc -options <file name>

The following option can be used with wc command:

l Counts number of lines
w Counts number of words
m Counts number of characters
c Counts number of bytes
#cat data
This is an example for demonstrating the cat command.
#wc -w data

Copying Files: 

cp command: It can be used to copy file/files.
Syntax:cp -option(s) surce(s) destination
The options for the cp command are discussed below :
i Prevents the accidental overwriting of existing files or directories
r Includes the contents of a directory, including the contents of all sub-directories, when you copy a directory
#cp file1 file2 dir1
In the above example file1 and file2 are copies to dir1.

Moving & renaming files and directories: 

mv command: It can be used to

1. Move files and directories within the directory hierarchy :
Example: We want to move file1 and file2 under the directory /export/home/ravi to /var

#mv file1 file2 /var

2. Rename existing files and directories.
Example: we want to rename file1 under /export/home/ravi to file2.

#mv file1 file2

The mv command does not affect the contents of the files or directories being moved or renamed.

We can use -i option with the mv command to prevent the accidental overwriting of the file.

Creating files and directories :

touch Command : It is used to create an empty file. We can create multiple file using this command.
Syntax: touch <files name>
Example: #touch file1 files2 file3

mkdir command : It is used to create directories.
Syntax: mkdir -option <dir name>

When the <dir name> includes a pah name, option -p is used to create all non-existing parent directory.

#mkdir -p /export/home/ravi/test/test1

Removing Files and Directories :

rm command: It is used permanently remove files/directories.

 Syntax: rm -option <file name>/<dir name>

The -i option is used to prompt user for confirmation before the deletion of files/directories.

Example: We want to remove file1 and file2 from the home directory of user ravi.
#cd ~ravi
#rm file1 file2
Note: The removal of a directory is slightly different. If the directory is not empty and you are trying to delete it, you will not be able to do so. You need to use -r option to remove the directory with files and sub-directories.
Example: We want to delete a directory test under user ravi home directory and it contains file and sub-directories.
#rm test
rm: test is a directory
#rm -r test


To remove an empty directory:
Syntax: rmdir <directory name>

Links (Soft Link and Hard Link) : This section has been covered under section :Solaris File System. Please refer to it.

Searching Files, Directories & its contents:

Using the grep command : The grep is very useful and widely used command.
lets take an example where we want to see if the process statd is running of not. Following command is used :
#ps -ef | grep statd

# ps -ef | grep statd
daemon  2557     1   0   Jul 07 ?           0:00 /usr/lib/nfs/statd
root 10649  1795   0 05:29:39 pts/4       0:00 grep statd
Syntax: grep options filenames.
The options used are discussed below :

i Searches both uppercase and lowercase characters
l Lists the name of files with matching lines
n Precedes each line with the relative line number in the file
v Inverts the search to display lines that do not match pattern
c Counts the lines that contain pattern
w Searches for the expression as acomplete word, ignoring those matches that are sub strings of larger words

Lets see few examples:
Suppose we want to search for all lines that contain the keyword root in /etc/group file and view their line numbers, we use following option :
# grep -n root /etc/group

To search for all the lines that does not contain the keyword root:
# grep -v root /etc/group

To search for the names of the files that contains the keyword root in /etc directory :
# cd /etc
# grep -l root group passwd hosts

To count the number of lines containing the pattern root in the /etc/group file:
# grep -c root group

Using regular expression Metacharacters with grep command:

Metachar Purpose Example Result
^ Begining of line Anchor ‘^test’ Matches all lines begining with test
$ End of line anchor ‘test$’ Matches all the lines ending with test
. Matches one char ‘t..t’ Matches all the line starting and ending with t and 2 char between them
* Matches the preceding item 0 or more times ‘[a-s]*’ Matches all lines starting with lowercase a-s
[] Matches one character in the pattern ‘[Tt]est’ Matches lines containing test ot Test
[^] Matches one character not in pattern ‘[^a-s]est’ Matches lines that do not contain “a” though “s” and followed by est
Using egrep command : 

With egrep we can search one or more files for a pattern using extended regular expression metacharacters.

Following table describes the Extended Regular Expression Metacharacters :
+ Matches one of more preceding chars ‘[a-z]+est’ Matches one or more lowercase letters followed by est(for example chest, pest, best, test, crest etc
x|y Matches either x or y ‘printer|scanner’ Matches for either expression
(|) Groups characters ‘(1|2)+’ or ‘test(s|ing)’ Matches for one or more occurrence.
Syntax: egrep -options pattern filenames
#egrep ‘[a-z]+day’ /ravi/testdays
In the above example, we searched for the letter ending with day in the file /ravi/testdays#egrep ‘(vacation |sick)’ leave’ /ravi/leavedata
vacation leave on 7th march
sick leave on 8th march
In the above example we are displaying sick leave and vacation leave from file /ravi/leavedataUsing fgrep command :
It searches for all the character regardless of it being metacharacter as we have seen in case of grep and egrep commands.
Syntax: fgrep options string filenames
#fgrep ‘$?*’ /ravi/test
this is for testing fgrep command $?*
#Using Find command :
This command is used to locate files and directories. You can relate it with windows search in terms of functionality.
Syntax: find pathnames expressions actionsPathname: The absolute or relative path from where the search begins.Expressions: The search criteria is mentioned here. We will discuss search criteria below in details.

-name filename Finds the file matching.
-size [+|-]n Finds files that are larger than +n, smaller than -n, or exactly n.
-atime [+|-]n Find files that have been accessed more than +n days, less than -n or exactly n days ago.
-mtime [+|-]n Find files that have been modified more than +n days, less than -n or exactly n days ago.
-user loginID Finds all files that are owned by the loginID name.
-type Finds a file type : f for file, d for directory.
-perm Find files that have certain access permission bits.

Action: Action required after all the files have been found. By default it displays all the matching pathnames

-exec command {} \; Runs the specified command on each file located.
-ok commadn {} \:
Requires confirmation before the find command applies the command to each file located.
-print Prints the search result
-ls Displays the current pathname and associated stats : inode number, size in kb, protection mode, no. of hard links and the user.
-user loginID Finds all files that are owned by the loginID name.
-type Finds a file type : f for file, d for directory.
-perm Find files that have certain access permission bits.

#touch findtest
#cat >> findtest
This is for test.
#find ~ -name findtest -exec cat {} \;
This is for test.
The above examples searches for the file : findtest and displays its content. We can also use ‘ok’ option instead of exec. This will prompt for confirmation before displaying the contents of file findtest.

If we want to find files larger than 10 blocks (1 block = 512bytes) starting from /ravi directory, following command is used :
#find /ravi -size +10

If we want to see all files that have not been modified in the last two days in the directory /ravi, we use :
#find /ravi -mtime +2

Printing Files:

lp comand : This command is located in /usr/bin directory. It is used to submit the print request to the printer.
/usr/bin/lp <file name>

/usr/bin/lp -d <printer name > <file name>

The options for the lp command are discussed below :
d It is used to specify the desired printer. It is not required if default printer is used
o It is used to specify that the banner page should not be printed
n Print the number of copies specified
m It send email after the print job is complete
lpstat command : It displays the status of the printer queue.  The Syntax for this command is as follows:
lpstat -option <printer name>
The options for the lpstat command are discussed below :
p Displays the status of all printers
o Displays the status of all output printers
d Displays the default system printer
t Displays the complete status information of all printers
s Display the status summary of all printers
a Displays which printers are accepting request
The output of the lpstat command is in the following format :
<request ID> <user ID> <File Size> <Date & Time> <status>
Cancel command : It is used to cancel the print request.
cancel <request ID>
cancel -u <user name>
Note: We can use lpstat command to get the request ID.

How To Update EBS XML Publisher Temporary Directory

January 5th, 2021, posted in Oracle EBS Application, Oracle Queries
SQL> select value from apps.XDO_CONFIG_VALUES WHERE  property_code = 'SYSTEM_TEMP_DIR';

SQL> update apps.XDO_CONFIG_VALUES set value='/u01/share/temp' WHERE  property_code = 'SYSTEM_TEMP_DIR';
1 row updated.

SQL> commit;
Commit complete.

SQL> select value from apps.XDO_CONFIG_VALUES WHERE  property_code = 'SYSTEM_TEMP_DIR';

How To Find the EBS XML Publisher Temporary Directory Via SQL? (Doc ID 1189723.1)