Sunday, January 26, 2014

to view only directories in Unix


If you have ever wanted to show a list of subdirectories underneath the current directory while at the terminal prompt, there’s a simple command that can help.
Simply run the following command from the bash terminal prompt, which filters the file listing to only show folders:

ls -l | grep ^d
Since typing that whole command every time you want to show a list of directories might get a little tiring, you can use the alias feature to assign it to something you can more easily remember:
alias lsd="ls -l | grep ^d"
Now when you type “lsd” at the prompt, you will see a list containing only the directories, which can be very useful when you are trying to navigate through a messy set of folders.

Sunday, January 19, 2014

Some useful VI editor commands


J – to join two lines
Deletion
dl – single character, dw – Single word, dd – single line, d$ – to the end of the line
Editing
i – insert mode, A – append to the end of the line, o – insert in next line
Misc
:set list – to see special characters
:%s/str1/str2/g – search and replace

Sunday, January 12, 2014

Some useful variables in Unix


$$ = The PID number of the process executing the shell.
$? = Exit status variable.
$0 = The name of the command you used to call a program.
$1 = The first argument on the command line.
$2 = The second argument on the command line.
$n = The nth argument on the command line.
$* = All the arguments on the command line.
$# The number of command line arguments.

Sunday, January 5, 2014

Read password from shell script


Since you don't want password to be not displayed on terminal you need to disable echo before reading password. Once password is read you need to enable it again.

#————————————————————
#  Read Password
#————————————————————
/usr/ucb/echo -n “Please Enter Password For User ${SUSER}: “
stty -echo
read SPSWD
stty echo
clear

Latest Posts