Thursday, March 30, 2006

VI COPY FILE TO FILE

VI COPY FILE TO FILE

Here is how to copy the required number
of lines from one file to another in
VI editor. First use the following
key combinations in the source file.

Press ESCAPE
Press Shift "(Shift double quotes)
Press a
Press the number of lines you want to copy
press y followed by another y

Now press " : " (COLON) to get the vi prompt.
Hit e "Destination file name"
Once you enter the Destination file
go to the line where you want the lines
copied to be inserted.

Press ESCAPE.
Press SHIFT "(Double quotes).
Press a.
Press p.

The lines get copied.

FIND THOSE HIDDEN FILES

FIND THOSE HIDDEN FILES

Finding only hidden files
(starting with .) in a directory.

ls -a | grep "^\." OR
ls -a | awk '$0~/^\./ {print $0}'

Sunday, March 19, 2006

Most commonly exploited UNIX vulnerabilities?

Most commonly exploited UNIX vulnerabilities?


Poor system administration practices

Reusable/poor passwords

Flawed SUID programs (e.g., rdist, binmail)

HTTP servers and CGI application vulnerabilities

Default "+" entries in the /etc/hosts.equiv file

NFS/NIS vulverabilities sendmail program bugs

Buffer overruns (e.g., gets(), syslog())

SUID shell scripts

Saturday, March 11, 2006

ANOTHER SORT BY FILE SIZE

ANOTHER SORT BY FILE SIZE

To sort certain files in the directory and to show
the biggest file first, do

$ du -a | sort -n -r | more

GREP TEXT NOT BINARY

GREP TEXT NOT BINARY

In some directories such as /etc you have a mix of file types.
You may want to grep out a string from one of the files but
don't want to worry about the binaries, data, etc. To accomplish
this, searching only text files do this:

grep `file * | egrep 'script|text' | awk -F: '{print $1}'`

Monday, March 06, 2006

ZERO THOSE LOG FILES

ZERO THOSE LOG FILES


Some programs write to multiple
log files in a directory and
need to be zeroed out sometimes
to save diskspace. The following
ksh shell script will zero out
all files with the ".log"
extension in a directory.

--- cut here ---
for object in *.log
do
> $object
print "$object has been zeroed!"
done
--- cut here ---

Just a little time saver when
you have 100 other things to
be doing.

REMOVING BLANK LINES

REMOVING BLANK LINES

To remove blank lines from a file using sed, use the following:

sed -e '/^$/d' filetoread >filetowrite

The ^ matches the beginning of a line and the $ matches the end.
The two of them together matches a line that begins and ends with
nothing in between (blank line).
The d just says delete the lines for which we have a match.
Since the standard operation of sed is to print every line,
all lines exept blank lines will be sent to filetowrite.

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.

BASH HOTKEYS

BASH HOTKEYS

Bash provides many hot keys to ease use. Like
ctrl-l -- clear screen
ctrl-r -- does a search in the previously given commands so that you don't
have to repeat long command.
ctrl-u -- clears the typing before the hotkey.
ctrl-a -- takes you to the begining of the command you are currently typing.
ctrl-e -- takes you to the end of the command you are currently typing in.
esc-b -- takes you back by one word while typing a command.
ctrl-c -- kills the current command or process.
ctrl-d -- kills the shell.
ctrl-h -- deletes one letter at a time from the command you are typing in.
ctrl-z -- puts the currently running process in background, the process
can be brought back to run state by using fg command.
esc-p -- like ctrl-r lets you search through the previously given commands.
esc-. -- gives the last command you typed.