Wednesday, March 21, 2012

UNIX commands

#########
List details of user in unix, with more details compared with listusers
adquery user -CpP <username>


#########
search and replace string in vi mode (editor)
Type in the whole thing, where String1 is the string to be replaced, and string2 is the new string.
:%s#<string1>#<string2>#g


#########
FIND

Find a specific string inside a folder and subfolders:
1. This one displays the file name and the line which contains the string:
find . -exec grep "<String>" '{}' \; -print

2. This one returns a cleaner result, with only the filename and location is returned:
find . -type f|xargs grep -ls "<string>"

#########
The FOR loop - Give a variable a default value so it will never be null
##contents below from http://www.ooblick.com/text/sh/

Quasi-variable constructs
The ${VAR} construct is actually a special case of a more general class of constructs:
${VAR:-expression}
Use default value: if VAR is set and non-null, expands to $VAR. Otherwise, expands to expression.
${VAR:=expression}
Set default value: if VAR is set and non-null, expands to $VAR. Otherwise, sets VAR to expression and expands to expression.
${VAR:?[expression]}
If VAR is set and non-null, expands to $VAR. Otherwise, prints expression to standard error and exits with a non-zero exit status.
${VAR:+expression}
If VAR is set and non-null, expands to the empty string. Otherwise, expands to expression.
${#VAR}
Expands to the length of $VAR.

No comments:

Post a Comment