CREATING TRASH
Sometimes unwittingly we may delete
some important files and realise it
later. To avoid such a situation,
you can use this following idea.
Create a small bash script containing
the line
mv $1 ~/trash/
Save this file in your home say
".srm" (safe rm) and in your
".bashrc" enter this line:
alias rm='~/.srm'
Now whenever you delete any files
it will go to "trash" directory
instead of deletion. You will
have to create a "trash" directory
in your home directory.
Saturday, April 15, 2006
Thursday, April 13, 2006
BASH SHELL OPTION
BASH SHELL OPTION
If you are using bash shell. There is
a way to cd a particular directory
even if you spelled incorrectly on the
command line. Set the shell option to:
shopt -s cdspell
eg:-
Suppose you want to cd to "cd /tmp"
and you have miss typed to "cd /pmp"
still it will cd to "cd /tmp".
This setting will be very usefull if
you have a long named directory.
If you are using bash shell. There is
a way to cd a particular directory
even if you spelled incorrectly on the
command line. Set the shell option to:
shopt -s cdspell
eg:-
Suppose you want to cd to "cd /tmp"
and you have miss typed to "cd /pmp"
still it will cd to "cd /tmp".
This setting will be very usefull if
you have a long named directory.
Wednesday, April 12, 2006
NFS BETWEEN SOLARIS & LINUX
NFS BETWEEN SOLARIS & LINUX
If you receive error messages such
as "unknown version" when attempting to
mount a Linux based NFS server from
Solaris, you probably have an
incompatibility between the NFS versions
running on both of them. Linux uses
version 2, while Solaris uses version 3.
In order to get the machines to
communicate, you have to use the vers
option on the Solaris machine as follows:
mount -o vers=2 nfsserver:/remotedir /localdir
If you receive error messages such
as "unknown version" when attempting to
mount a Linux based NFS server from
Solaris, you probably have an
incompatibility between the NFS versions
running on both of them. Linux uses
version 2, while Solaris uses version 3.
In order to get the machines to
communicate, you have to use the vers
option on the Solaris machine as follows:
mount -o vers=2 nfsserver:/remotedir /localdir
Tuesday, April 11, 2006
MAINTAINING LOG AND TMP FILE
MAINTAINING LOG AND TMP FILE
If you need to maintain an
application that generate
a lot of logfiles or tmp
files with running numbers
as part of the filename and
uses a common extension.
These two command together
will help to maintain it
for a window of time.
It compress those files that
are more than 24hrs and
have it remove after 120hrs.
You need to put it in
daily cron.
find $LOGDIR -name '*.ext' -mtime +0 -exec compress {} \;
find $LOGDIR -name '*.Z' -mtime +5 -exec rm -f {} \;
You can change the time to
suit your needs and use
wherever compressing utility
you have to save space.
If you need to maintain
directories created by
application here are help;
find $LOGDIR -type d -mtime +0 -exec compress -r {} \;
find $LOGDIR -type d -mtime +5 -exec rm -f {}
The compression is to save
space while waiting to be
deleted. Application
developers may need to read
these files/directories so
keep those files/directories
for a certain amount of time
before deleting.
If you need to maintain an
application that generate
a lot of logfiles or tmp
files with running numbers
as part of the filename and
uses a common extension.
These two command together
will help to maintain it
for a window of time.
It compress those files that
are more than 24hrs and
have it remove after 120hrs.
You need to put it in
daily cron.
find $LOGDIR -name '*.ext' -mtime +0 -exec compress {} \;
find $LOGDIR -name '*.Z' -mtime +5 -exec rm -f {} \;
You can change the time to
suit your needs and use
wherever compressing utility
you have to save space.
If you need to maintain
directories created by
application here are help;
find $LOGDIR -type d -mtime +0 -exec compress -r {} \;
find $LOGDIR -type d -mtime +5 -exec rm -f {}
The compression is to save
space while waiting to be
deleted. Application
developers may need to read
these files/directories so
keep those files/directories
for a certain amount of time
before deleting.
EXTRACT CORRUPTED TAR FILE
EXTRACT CORRUPTED TAR FILE
In many case if there is a corrupted tar file,
the following command can be used in an attempt
to extract the file:
% cat [tar-filename] | tar -xvf -
NOTE: Where "-" is the STDOUT
In many case if there is a corrupted tar file,
the following command can be used in an attempt
to extract the file:
% cat [tar-filename] | tar -xvf -
NOTE: Where "-" is the STDOUT
Sunday, April 02, 2006
EFFICIENT COMMANDS
EFFICIENT COMMANDS
I cringe anytime I see someone code
inefficiently. Here are three of the
most common mistakes, followed by a
better way to do the same thing.
Bad: cat somefile | grep something
Better: grep something somefile
Why: You're running one program (grep) instead of two (cat and grep).
Bad: ps -ef | grep something | grep -v grep
Better: ps -ef | grep [s]omething
Why: You're running two commands (grep) instead of three (ps
and two greps).
Bad: cat /dev/null > somefile
Better: > somefile
Why: You're running a command (cat) with I/O redirection,
instead of just redirection.
Although the bad way will have the
same result, the good way is far
faster. This may seem trivial, but
the benefits will really show when
dealing with large files or loops.
I cringe anytime I see someone code
inefficiently. Here are three of the
most common mistakes, followed by a
better way to do the same thing.
Bad: cat somefile | grep something
Better: grep something somefile
Why: You're running one program (grep) instead of two (cat and grep).
Bad: ps -ef | grep something | grep -v grep
Better: ps -ef | grep [s]omething
Why: You're running two commands (grep) instead of three (ps
and two greps).
Bad: cat /dev/null > somefile
Better: > somefile
Why: You're running a command (cat) with I/O redirection,
instead of just redirection.
Although the bad way will have the
same result, the good way is far
faster. This may seem trivial, but
the benefits will really show when
dealing with large files or loops.
Saturday, April 01, 2006
Removing Blank Line using SED
I SED BLANK
Using sed, you can remove blank lines, and
lines that contain only whitespace, from a
file using the following:
sed -e '/^[ ]*$/d' InputFile >OutputFile
Within the single quotes ('), the forward
slashes (/) delimit the regular expression
that will be interpreted by sed. The "d"
before the closing single quote, tells sed
to delete any lines that match the regular
expression.
Within the regular expression, the caret
(^) matches the beginning of a line.
The []* matches zero to many occurrences of
the character list between the open bracket
([) and the close bracket (]) (in the above
regular expression, you must insert a space
and a tab between the brackets). The dollar
sign ($) matches the end of a line.
These three constructs together match any
blank line or any line that contains only
spaces and tabs (in any combination).
Since the standard operation of sed is to
echo lines to stdout, all lines except blank
lines (or lines that only contain whitespace)
will be sent to OutputFile.
Using sed, you can remove blank lines, and
lines that contain only whitespace, from a
file using the following:
sed -e '/^[ ]*$/d' InputFile >OutputFile
Within the single quotes ('), the forward
slashes (/) delimit the regular expression
that will be interpreted by sed. The "d"
before the closing single quote, tells sed
to delete any lines that match the regular
expression.
Within the regular expression, the caret
(^) matches the beginning of a line.
The []* matches zero to many occurrences of
the character list between the open bracket
([) and the close bracket (]) (in the above
regular expression, you must insert a space
and a tab between the brackets). The dollar
sign ($) matches the end of a line.
These three constructs together match any
blank line or any line that contains only
spaces and tabs (in any combination).
Since the standard operation of sed is to
echo lines to stdout, all lines except blank
lines (or lines that only contain whitespace)
will be sent to OutputFile.
Subscribe to:
Comments (Atom)