Friday, March 26, 2010

ls --color Decorating Directory Listing

The change the colours for your directory listing
Edit file: /etc/DIR_COLORS, copy the only changed ones in ~/.dircolors.

Next login, you get it.

file: /etc/DIR_COLORS
# 00=none 01=bold 04=underscore 05=blink 07=reverse 08=concealed
# Text color codes:
# 30=black 31=red 32=green 33=yellow 34=blue 35=magenta 36=cyan 37=white
# Background color codes:
# 40=black 41=red 42=green 43=yellow 44=blue 45=magenta 46=cyan 47=white
#NORMAL 00 # no color code at all
#FILE 00 # normal file, use no color at all
RESET 0 # reset to "normal" color
DIR 01;34 # directory
LINK 01;36 # symbolic link (If you set this to 'target' instead of a
# numerical value, the color is as for the file pointed to.)

Monday, March 1, 2010

FTP GET remote file timestamp

Check the remote server file time
login to ftp server
ftp servername
do
ls -ltr

will show list of files say we have
ftp> ls -ltr

227 Entering Passive Mode (10,146,172,50,66,132)
150 Here comes the directory listing.
-rw-r--r-- 1 50005 50005 5250 Mar 01 08:15 tech-talk
226 Directory send OK.


use modtime filename to check the file modified timestamp, ftp always shows in GMT time

ftp> modtime tech-talk

tech-talk 03/01/2010 08:15:00 GMT

Wednesday, February 17, 2010

ternary operator

$ test 1 -eq 1 && echo true || echo false
true

$ test 1 -eq 2 && echo true || echo false
false

&& -- operator will execute the second command only if the previous command ran successfully (exit status=0)

|| -- operator will execute the second command only if the previous command failed (exit status=1)

Tuesday, February 16, 2010

Total no. of ocurrence of word in file

We are searching the word phrase in the file rfc2119.txt

tr will split the space in newline and grep will search for the word in be beginning or end of the line and does not have any alphanumeric character around the word.


File: http://www.faqs.org/rfcs/rfc2119.txt
cat rfc2119.txt |tr '[[:space:]]' '\n' |grep -E "(^|\W)phrase(\W|$)" |wc -l

o/p: 5

Thursday, February 11, 2010

dc: base16 to base10

dc is a reverse-polish desk calculator

echo "2i 100 p"|dc
says: 100 is of base2 give o/p in base 10

echo "16i 100 p"|dc
says: 100 is of base16 give o/p in base 10

echo "16o 10i 100 p"|dc -- read 100 in base10 and o/p in base16
echo "2o 10i 100 p"|dc -- read 100 in base10 and o/p in base2

Friday, February 5, 2010

cp

cp * copies in ascii order
mkdir l; echo hello>b; echo ding> a
cp * will copy files a b to directory l,
if l is removed, a is copied to b

bash expansion

* -- is expanded in ascii
say you create files touch {e,b,a,t,f}
and you list it; it will list a b e f t
same thing happens if you do cp or mv