Entries Tagged as ''

vi Search and Replace

It’s sad to say I don’t use the vi search & replace enough to have it ingrained where it should be, so here’s to open documentation:

Adding the “how to” search for those who might need it:

Note: Search wraps around at end of file

To search STR forward: /STR
To search STR backwards: ?STR

To repeat the search: n
To repeat search in opposite direction: N ([SHIFT]-n)

Replace
Replace: Same as with sed, Replace OLD with NEW:

First occurrence on current line: :s/OLD/NEW
Globally (all) on current line: :s/OLD/NEW/g
Between two line numbers #,#: :#,#s/OLD/NEW/g
Every occurrence in file: :%s/OLD/NEW/g

Remove Files By Inode Number (Linux/UNIX/Mac OS X)

Recently I needed to delete some pesky files that at some point managed to get created. The problem with these ‘pesky’ files is that they don’t have file-friendly names. One of the files was named “!” (no quotes), and another was “-20080605.log”

I know I could remove them by using the rm command prefixing the unacceptable characters with “\” but I also recall a method to remove files by their inode number.

$ rm \!; rm -20080606.log;

For a refresher, a quick google gave me this resourceful site.

In summary:

1. Get the inode number of the file you want…

$ ls -li

Output:

2396291 -rw-rw-r– 1 user user 35 2008-06-05 09:37 -20080605.log

The inode number is 2396291.

2. Delete the file using the inode number found from step 1.

$ find . -inum 2396291 -exec rm -i {} \;

Free 30 day trial period at CovenantMedia.com

For the churches and ministries out there, ConvenantMedia.com has announced it has officially opened its virtual doors!

Need a website you can actually use and looks great? What about a site you can manage from the web, add pages, emails, services and more with ease and no programming what so ever? ConvenantMedia.com has taken the emerging server technologies and combined its experience with church community websites to bring you a complete web package that anyone can use. For a limited time, CovenantMeda.com is also offering zero setup fees when you sign up.