Web Dev Blog

Looking for help with WordPress, Apache, Vim, Web Security and more. Here are a few tips.

Tag: CLI

Search for a file name and insert it into a Vi (Vim) file

Something I’ve been trying to do for years and didn’t realize it was so easy. Know when you are editing an html file and want to insert a filename for an image or other asset without leaving Vim? There’s an easy way to do that.

Just use Ctl-X Ctl-f

Completing file names *compl-filename*

*i_CTRL-X_CTRL-F*
CTRL-X CTRL-F Search for the first file name that starts with the
same characters as before the cursor. The matching
file name is inserted in front of the cursor.
Alphabetic characters and characters in 'isfname'
are used to decide which characters are included in
the file name. Note: the 'path' option is not used
here (yet).

Remove spaces from filenames on the Ubuntu Linux command line

I’ve been working on sizing a large number of images for a client to go into a WordPress photo gallery. I use a for loop to find all the files and use convert to size them to a good size for viewing on a website. The problem is the convert program doesn’t like file names with spaces in them. It seems like the easiest thing to do is remove the spaces from the file names with a Ubuntu command line script. This is easily accomplished with the rename comannd.

rename 'y/ /_/' *

This script will replace any spaces spaces in the filenames with underscores (_)