
test 100 –eq 200; echo $?
{Test whether 100 is equal to 200 (Where Output: 0= right, 1= wrong)}
or
test 100 = 200; echo $?
test 100 –ne 200; echo $?
(-ne = not equal to)
or
test 100 != 200; echo $?
test Hello Worlds != Hello World; echo $?
test 100 –lt 200; echo $?
(-lt = less than)
test 100 –gt 200; echo $?
(-gt= greater than)
test 100 –le 200; echo $?
(-le= less than or equal to)
test 100 –ge 200; echo $?
(-ge= greater than or equal to)
-eq |
equal to |
-ne |
not equal to |
str1= str2 |
string str1 is equal to str2 |
str1 != str2 |
string str1 is not equal to str2 |
-gt |
greater than |
-lt |
less than |
-ge |
greater than equal to |
-le |
less than equal to |
-n str |
string str is not a null string (the length of the String1 variable is nonzero) |
str |
same as above |
-z str |
{the length of the String1 variable is 0 (zero)} |
test 100 –lt 200; echo $? |
-lt = less than |
test 100 –gt 200; echo $? |
-gt= greater than |
test 100 –le 200; echo $? |
-le= less than or equal to |
test 100 –ge 200; echo $? |
-ge= greater than or equal to |
test file1 -nt file2; echo $? |
-nt= newer than |
test file1 -ot file2; echo $? |
-ot= older than |
test -e abc; echo $? |
-e= whether abc (file or directory) exist or not (1=no, 0=yes) |
test -f abc; echo $? |
-f= whether abc is a file or not (1=no, 0=yes) |
ls –l /var/lib/mysql/mysql.sock
srwxrwxrwx 1 mysql mysql 0 Oct 8 19:54 /var/lib/mysql/mysql.sock
(the first letter <s> denote it’s a socket)
test -S /var/lib/mysql/mysql.sock; echo $?
{Result = 0 (yes)}
test -s file; echo $?
[-s=whether it’s a zero file or not {a file with no content (zero size)}]
file1 (written something) result = 1
file2 {written nothing (0 size)} result=0
(don’t take it wrong, it’s true)
Note: man test
cat file1
(shows)
abc
xyz
123
dfk
tac file1
(display just reverse)
abc
xyz
123
dfk
which mkdir
(show the location of command)
touch file1
(create an empty file)
vim file1
(lets add something in it and save and exit and after sometime use touch)
touch file1
(now touch doesn’t overwrite but update its access and modified time)
sleep 5
(sleeps for 5 sec)
usleep 5
(sleeps for 5 micro sec)
usleep 2000000
(= sleep 2)
which time
time sleep 5
(time command run after 5 sec)
ps –aux | grep bash
top
watch tail /var/log/messages
date -r file1
(shows the last modification date & time of file1)
date –r abc +%s
(last modified date in sec)
date +%s
(current date in sec)
Note:
(the difference between these two results how many seconds ago that file/dir was modified)
date +%d
[display the day of month (1-31)]
date +%d-%T
[shows date – (dash) time, You can also use $, # or other symbol instead of -]
date +%d-%T-%b
(shows date-time-month)
date +%F
[show 2011-04-30, (current date)]
touch `date +%F`.log
[create a file 2011-04-30.log, ` is the key (` ~)]
echo “Program Succeeded” >> `date +%F`.log
[create a file 2011-04-30.log, that contain Program Succeeded]
man expr
expr 10 + 10
(display 20)
expr 10 \* 5
(shows 50, since * is a special character it should be escaped)
expr 10 / 2
(display 5)
expr Wali = Wali
(display 1, mean true in Boolean)
expr Wali = wali
(display 0, means false in Boolean)
expr length “wali alam”
(display 9, length of wali alam = 9 character)
expr substr mdwalialam 1 3
(display mdw, first 3 character)
expr substr mdwalialam 2 5
(display dwali, 2nd 5 character)
expr substr mdwalialam 4 7
(display alialam, 4th 7 character)
var1=mdwalialam
expr substr $var1 2 5
(display dwali, 2nd 5 character)
expr length $var1
(display 10)
time ping localhost
(run the command, also shows how long it takes to run)
i=1; echo $i
(display 1)
i=`expr $i + 1`; echo $i
(display 2, as 1 is added with the previous result, ( ` near 1 key)





