apropos <text>
/usr/share/doc
https://autohotkey.com/docs/misc/RegEx-QuickRef.htm
ls file[0-9] | xargs paste
cat garbage | while read line
do
echo $line | grep -o -b "from\|to"
done
cat output | grep -v "\/" | awk '{ print $1 }'
grep -E "^[ \t]*int[ \t]+\w[ \t]*\(*" *.c
float=3.3446
printf "%.2f \n" $float
echo "redirect this STDOUT to STDERR" 1>&2
ls $0 some-text 2> stderr
declare -l lc_string="...\nAb\n..."
echo -e lower [$lc_string]
declare -i var1=99
(( var0=var1<98?9:21))
echo var0=$var0
${#string}
rm gshsks
echo exit[$?]
find . -mtime -1
find . -maxdepth 1 -type d -exec ls -ld '{}' +
tar -cvf /tmp/backup.tar --exclude="log" --exclude="*.tmp" .
local VAR=abc
echo VAR=$VAR
echo all args [$@]
read expression
echo "scale=3;$expression"|bc
for i in `seq 1 3`;
do
echo i [$i]
done
sort wordlist | nl | head -3
sort -k 2 names
ps -A | tail -5 | cut -b 1-5
for i in {1..99}
do
mod=`expr $i % 2`
if [ $mod -ne 0 ]; then
echo $i
fi
done
ls -l | grep -v "^total" | awk '{ print $5 }' | while read output
do
echo output [$output]
done
var="Hi"
cat <<EOF > /tmp/aFile
echo $var
exit 0
EOF
while (( "$#" )); do
echo arg [$1]
shift
done
trap catch INT
catch()
{
echo
echo Got Ctrl-C
exit 1
}
disk_space()
{
space=`df -h | tr -s ' ' | grep -v "^File" | cut -f 5 -d ' ' | tr -d '%' | tail -1`
echo space[$space]
case $space in
[1-9])
message="all good"
;;
[1]*)
message="1 or more"
;;
*)
message="other"
;;
esac
echo message [$message]
}
tree()
{
i=0
while [ $i -lt $size ]
do
j=0
# loop round all chars in line
num_blanks=$((size-1-i))
line=""
while [ $j -lt $size ]
do
ch="x"
if [ $j -ge $num_blanks ]; then
ch="*"
fi
line="${line}${ch}"
j=$((j+1))
done
echo [${line}] | tr -d '[' | tr -d ']' | tr x ' '
i=$((i+1))
done
}
echo Enter size
read size
tree $size
ROOTUID=0
usage()
{
echo You must be root to run this script
exit 1
}
if [ "$UID" != "$ROOTUID" ]; then
usage
fi
case "$1" in
[0-9]*)
LINES=$1
;;
*)
LINES=50
;;
esac
echo LINES=$LINES
echo Enter 3 colours
read -a colours
echo colours... ${colours[0]} ${colours[1]} ${colours[2]}
names=("1" "4" "2" "2" "3")
echo ${names[@]}
len=${#names[@]}
i=0
while [ $i -lt $len ]
do
if [ "${names[$i]}" != "${names[$i+1]}" ]; then
echo not pair "${names[$i]}" "${names[$i+1]}"
fi
i=$(($i+2))
done
do_sum()
{
echo enter array size
read size
count=0; sum=0
while [ $count -lt $size ]
do
read num
sum=$((sum+num))
count=$((count+1))
done
return $sum
}
do_sum
echo ret=$?
parseNums()
{
nums=("${@}")
sorted=`echo ${nums[@]} |tr " " "\n"|sort -n|tr "\n" " "`
sortedArray=(${sorted// / })
echo sortedArray="[${sortedArray[@]}]"
len=${#sortedArray[@]}
i=0
while [ $i -lt $len ]
do
i=$(($i+1))
if [ $i -lt $len ]; then
echo ${sortedArray[$i-1]} ${sortedArray[$i]}
fi
done
}
declare -a nums_in=("-1" "2" "1" "0")
echo nums="${nums_in[@]}"
parseNums "${nums_in[@]}"
lonely()
{
names=("${@}")
len=${#names[@]}
i=0
while [ $i -lt $len ]
do
if [ "${names[$i]}" != "${names[$i+1]}" ]; then
return ${names[$i]}
fi
i=$(($i+2))
done
}
echo enter array size
read size
declare -a names_in
count=0
while [ $count -lt $size ]
do
read num
names_in[$count]=$num
count=$((count+1))
done
lonely "${names_in[@]}"
echo lonely=$?
userPasswd()
{
envs=("${@}")
len=${#envs[@]}
i=0
while [ $i -lt $len ]
do
if [[ ${envs[$i]} =~ ^user=[a-zA-Z0-9]* ]]; then
user=`echo "${envs[$i]}" | cut -d '=' -f 2`
fi
if [[ "${envs[$i]}" =~ "pass" ]]; then
pass=`echo "${envs[$i]}" | cut -d '=' -f 2`
fi
i=$(($i+1))
done
userPasswdReturn="${user}:${pass}"
}
declare -a envs_in=("a=b" "user=joe" "pass=secret")
userPasswd "${envs_in[@]}"
echo userPasswdReturn=$userPasswdReturn
parseLog()
{
log=("${@}")
len=${#log[@]}
i=0
while [ $i -lt $len ]
do
if [[ ${log[$i]} =~ [0-9]\.[0-9]\.[0-9]\.[0-9] ]]; then
ind[$i]="true"
else
ind[$i]="false"
fi
i=$(($i+1))
done
}
declare -a log_in=("line1" "ip address is 10.0.2.15" "mac addr = 08:00:27:12:96:98")
echo log="${log_in[@]}"
parseLog "${log_in[@]}"
echo "${ind[@]}"
sequence()
{
if [ $# -eq 1 ]
then
Num=$1
else
echo -n "Enter a Number :"
read Num
fi
f1=0
f2=1
echo "The sequence for the number $Num is : "
for (( i=0;i<=Num;i++ ))
do
echo -n "$f1 "
fn=$((f1+f2))
f1=$f2
f2=$fn
done
echo
}
sequence $1