Bash Shell Shortcuts (Alt - escape in MAC)
Ctrl A - Jump to the begin of line(BOL)
Ctrl E - Jump to the end of line(EOL)
Ctrl B - Move back a char
Ctrl F - Move forward a char
Alt B - Move backward word
Alt F - Move forward word
Alt C - Capitalize the word
Alt L - Make word lowercase
Alt U - Make word uppercase
Alt D - Delete word to right
Ctrl D - Delete char from under the cursor
Alt Backspace - Delete backward from cursor
Ctrl U - Delete from cursor to BOL
Ctrl K - Delete from cursor to EOL
Ctrl C - Terminate the command
Ctrl L - Clear the screen
Ctrl R - Search the history backwards
Ctrl xx - Move between BOL and current cursor position
Ctrl Z - Suspend/ Stop the command
Alt < - Move to the first line in the history
Alt > - Move to the last line in the history
Alt ? - Show current completion list
Alt * - Insert all possible completions
Alt / - Attempt to complete filename
Alt . - Yank last argument to previous command
Alt T - swaps the last two words on curser position and before
Tab twice(TT) - all commands
ls TT - files and directories in current directory
stringTT - starting with string commands
/TT - directory with hidden
*TT - sub dirs without hidden
~TT - users from /etc/passwd
$TT - All Sys variables
@TT - Entries from "/etc/hosts"
=TT - Output like ls or dir
Wednesday, February 23, 2011
Tuesday, February 22, 2011
who logged in last since last two hours
when we have to check who have logged in last few minutes, here say two hours, or 120minutes.
who | awk -v d=`date +"%Y-%m-%d"`
-v h=`date +"%H"`
-v m=`date +"%M"`
' { split($4,wa,":");
wc=wa[1]*60+wa[2];
dc=h*60+m;
if ($3==d && dc-wc<=120 ) printf ("%s\n",$0)
}'
you can change that dc-wc<=120 -- this 120 to any minutes to check
dc - is the current system date time (Hours and minutes converted into minutes),
wc - is the date time from who command for user logged in
explained with example
$date
Tue Feb 22 09:01:05 UTC 2011
$ who
sanjeev pts/0 2011-02-22 07:54 (what.is.the.host)
jro pts/1 2011-02-21 16:43 (what.is.the.host)
beak pts/2 2011-02-22 00:49 (beak.has.the.host)
madrose pts/3 2011-02-22 07:59 (what.is.the.host)
onthepk pts/4 2011-02-22 08:00 (is.this.the.host)
anita pts/6 2011-02-22 02:35 (what.is.the.host)
$ who|awk -v d=`date +"%Y-%m-%d"` -v h=`date +"%H"` -v m=`date +"%M"` '{ split($4,wa,":"); wc=wa[1]*60+wa[2]; dc=h*60+m; if ($3==d && dc-wc<=120 ) printf ("%s\n",$0) }'
sanjeev pts/0 2011-02-22 07:54 (what.is.the.host)
madrose pts/3 2011-02-22 07:59 (what.is.the.host)
onthepk pts/4 2011-02-22 08:00 (is.this.the.host)
who | awk -v d=`date +"%Y-%m-%d"`
-v h=`date +"%H"`
-v m=`date +"%M"`
' { split($4,wa,":");
wc=wa[1]*60+wa[2];
dc=h*60+m;
if ($3==d && dc-wc<=120 ) printf ("%s\n",$0)
}'
you can change that dc-wc<=120 -- this 120 to any minutes to check
dc - is the current system date time (Hours and minutes converted into minutes),
wc - is the date time from who command for user logged in
explained with example
$date
Tue Feb 22 09:01:05 UTC 2011
$ who
sanjeev pts/0 2011-02-22 07:54 (what.is.the.host)
jro pts/1 2011-02-21 16:43 (what.is.the.host)
beak pts/2 2011-02-22 00:49 (beak.has.the.host)
madrose pts/3 2011-02-22 07:59 (what.is.the.host)
onthepk pts/4 2011-02-22 08:00 (is.this.the.host)
anita pts/6 2011-02-22 02:35 (what.is.the.host)
$ who|awk -v d=`date +"%Y-%m-%d"` -v h=`date +"%H"` -v m=`date +"%M"` '{ split($4,wa,":"); wc=wa[1]*60+wa[2]; dc=h*60+m; if ($3==d && dc-wc<=120 ) printf ("%s\n",$0) }'
sanjeev pts/0 2011-02-22 07:54 (what.is.the.host)
madrose pts/3 2011-02-22 07:59 (what.is.the.host)
onthepk pts/4 2011-02-22 08:00 (is.this.the.host)
Monday, February 21, 2011
Occurrences of words in file
Here I am trying to split the words separately on basis of non-aplhanumeric chars or dot, they are replaced by space, and xargs trims more than one spaces or enterkey to one normal space char.
You can include the chars which may be part of your word in the sed ignore block.
cat filename | sed -e 's/[^a-zA-Z0-9.]/ /g' | xargs | tr ' ' '\n' | sort | uniq -c | sort -nr -k1,2
voila you should get the most occured word on top.
This is output for the above text.
4 the
2 xargs
2 word
2 to
2 space
2 sort
2 sed
2 or
2 one
2 on
2 of
2 chars
1 zA
1 your
1 you
1 words
1 which
1 voila
1 uniq
1 trying
1 trims
1 tr
1 top.
1 they
1 than
1 split
1 spaces
1 should
1 separately
1 s
1 replaced
1 part
1 occured
1 nr
1 normal
1 non
1 n
1 most
1 more
1 may
1 include
1 in
1 ignore
1 get
1 g
1 filename
1 enterkey
1 e
1 dot
1 char.
1 cat
1 can
1 c
1 by
1 block.
1 be
1 basis
1 are
1 aplhanumeric
1 and
1 am
1 a
1 Z0
1 You
1 I
1 Here
1 9.
You can include the chars which may be part of your word in the sed ignore block.
cat filename | sed -e 's/[^a-zA-Z0-9.]/ /g' | xargs | tr ' ' '\n' | sort | uniq -c | sort -nr -k1,2
voila you should get the most occured word on top.
This is output for the above text.
4 the
2 xargs
2 word
2 to
2 space
2 sort
2 sed
2 or
2 one
2 on
2 of
2 chars
1 zA
1 your
1 you
1 words
1 which
1 voila
1 uniq
1 trying
1 trims
1 tr
1 top.
1 they
1 than
1 split
1 spaces
1 should
1 separately
1 s
1 replaced
1 part
1 occured
1 nr
1 normal
1 non
1 n
1 most
1 more
1 may
1 include
1 in
1 ignore
1 get
1 g
1 filename
1 enterkey
1 e
1 dot
1 char.
1 cat
1 can
1 c
1 by
1 block.
1 be
1 basis
1 are
1 aplhanumeric
1 and
1 am
1 a
1 Z0
1 You
1 I
1 Here
1 9.
Subscribe to:
Posts (Atom)