Monday, February 22, 2016

Add text at the beginning of a line in vim

The substitute command can be used to insert (or replace) text. Some examples:

:s/^/new text / Insert "new text " at the beginning of the line.
:s/$/ new text/ Append " new text" to the end of the line.
:s/green/bright &/g Replace each "green" with "bright green" in the line.
By default, each command operates on the current line. If you visually select some text before entering the command, it will operate on each line in the visual selection. See Search and replace for details.
Or you can insert a range immediately after the colon, for instance :.-5,$s/ etc. to substitute from 5 lines above the cursor to the end of the file.

:s/^/test /  ----insert "test" at the beginning of each line.
:%s/^/test / --- insert "test" at the end of each line .

Saturday, February 6, 2016

Delete Files Older Than x Days on Linux

find /path/to/files* -mtime +5 -exec rm {} \;
ex: find /opt/test/patch/* -mtime +7 -exec rm {} \;

The first argument is the path to the files. This can be a path, a directory, or a wildcard as in the example above. I would recommend using the full path, and make sure that you run the command without the exec rm to make sure you are getting the right results.
The second argument, -mtime, is used to specify the number of days old that the file is. If you enter +5, it will find files older than 5 days.
The third argument, -exec, allows you to pass in a command such as rm. The {} \; at the end is required to end the command.

How to convert PPK file to ssh remote server in ubuntu


1.sudo apt-get install putty
2.puttygen private.ppk -o private-key -O private-openssh (Where “private.ppk” is the PuTTY .ppk file to convert, and “private-key” is the name of the converted key file.)
3.ssh -i private-key username@remote-server-ip
Now, you can easily access the remote server using the openssh standard private key:

refurl: https://rbgeek.wordpress.com/2012/11/14/how-to-convert-ppk-file-to-ssh-remote-server-in-ubuntu/