Showing posts with label find. Show all posts
Showing posts with label find. Show all posts

Thursday, September 10, 2009

Find and replace within vi

Yes, vi is cryptic. But this command is useful for performing find and replace functions within the vi editor. First, hit ESC (escape), and the colon key (:) to get to the ex shell. Then enter:

%s/searchString/replaceString/g

An example will be:

:%s/WindowsNT/RedHatLinux/g

Wednesday, June 17, 2009

Remove old files

If you don't use logrotate to remove or archive old logs, here is a way to remove old logs using the -ctime directive within the bash command find.

/usr/bin/find /var/log/tomcat -name *.tgz -ctime +15 | xargs rm -rf

Wednesday, May 6, 2009

vi find and replace

To perform a find and replace with all entries of a file, enter the colon to invoke ex from vi. Then, from there, enter

:%s/find_string/replace_string/g

For example:

%s/oldHostname/newHostname/g

There are many other ways to do this, but I prefer this method. This is one of the reasons that vi stands for "Voodoo for Intellectuals."

Friday, December 5, 2008

Rename files which match specific criteria

This renames all files within the current working directory from .exe to .exeold. This is useful if you are trying to rename any file extension from one to another.

for file in *.exe ; do mv $file `echo $file | sed 's/\(.*\.\)exe/\1exeold/'` ; done

Tuesday, March 11, 2008

Align and clean printer heads for a Lexmark printer

If you have a Lexmark printer within Linux, it may be difficult to align or clean the printer heads as these utilities are nonexistent within cups. I have a Lexmark z645 printer. The workaround is to use the lpr utilities to get the job done. With some modification, this should work for most printers, not just Lexmark ones.

To align printer heads:
#lpr -P <printernamewithincups> -o raw <pathtoalignutility.out>

For example:
#lpr -P Lexmark_640_Series -o raw /usr/local/z600llpddk/utility/lxbcalgn.out

To clean printer heads:
#lpr -P <printernamewithincups> -o raw <pathtocleanutility.out>

For example:
#lpr -P Lexmark_640_Series -o raw /usr/local/z600llpddk/utility/lxbccln.out

The -o raw allows the job to be performed without going through MIME filters. Note that the paths may be different depending on your printer's driver. Use the command:

#find / -iname *.out to locate the correct path for the align and clean utility.