tag archive: bash

findr: a GNU/Unix ‘find’ helper

I’ve been more aggressive lately about creating helper scripts and aliases for common tasks, and I liked this find helper enough to want to share it. I find that I often do filename searches like this:

find -iname “*some_word*”

That’s not so bad to type, but why not make it even easier for my, and maybe your common usage? We might prefer to do something like this:

findr some_word

And assume that we’re looking for a case-insensitive, substring match. And since we love regular expressions, we can work with find’s regex options:

–regextype posix-egrep -iregex

Which is just begging for a helper to do the work for us in standard situations.

Before we look at the script and some examples, here are a few more considerations for our findr command:

With the -iregex option, the match is against the whole path, so we’ll wrap the supplied regex search term with dot-stars (.*) to loosen things up. We probably want to limit our match to the last item …

tar up directories only

To create a tar file containing only a dir structure in GNU/Linux, this seems to work nicely:

tar -cvf filename.tar --after-date YYMMDD *

Where YYMMDD is a date newer than all files in the dir(s) being tarred up. Picking a date in the future should do the job. Tar will include all the directories and none of the files.

(That same behavior is the reason I went to the trouble of creating a cpafter program to copy files created after a certain date — I didn’t want all those empty dirs included.)

Subversion (SVN) GNOME Nautilus Script Helpers

Update, 3 November 2007:

Found a better solution: Jason Field’s NautilusSvn. More SVN features, much better integration with Nautilus, and uses emblems to show file and directory status. There is a .deb file that installed easily on my Ubuntu 7.04/Feisty Fawn machine. And it’s free as in GPL v2. Thanks, Jason!

Use NautilusSvn instead of my meager scripts!

Update, 6 November 2007:

I wrote another post about NautilusSvn and replacement emblems.

Update, 22 February 2008:

Jason’s site has been down today. Acting as a backup, here are the files I downloaded back in November:

nautilussvn_0.9-1.deb (25 KB)
NautilusSvn_v0.9.tar.gz (25 KB)

Hopefully jasonfield.com will be back soon and then I recommend going there for the latest and greatest.

Extend the file manager with right-click popup menu options for adding, updating, and commiting SVN files, as well as viewing log and status info.

photo by SqueakyMarmot

In Windows, I haven’t used TortoiseSVN, but …

HOWTO: Rotate JPG images in GNOME’s Nautilus File Manager

Originally published 6 October 2007 in Free Software Magazine. It was pointed out in the comments there that Nautilus Extensions is another way of customizing Nautilus, and that the extension nautilus-actions should be used instead for what I’m trying to do here. I had seen Extensions mentioned as a more powerful alternative at gnome.org, but I still like scripts for this job. However, I should at least acknowledge Nautilus Extensions as another option.

I recently went looking for a way to rotate JPG images from within Nautilus, and found a nice way to do this and more. It’s not difficult to customize the right-click popup menu in Nautilus to perform custom actions on files. Here are some instructions and scripts to get you started.

I often have vertically oriented camera pictures that I want to rotate from within the file manager. Windows Explorer has a nice feature where you can multi-select pictures in …

Subversion (SVN) helper bash script to list repo dirs

Finding my way around SVN. So far I’ve created a repository to hold my WordPress theme files and miscellaneous scripts. The working directories are scattered around my home dir, and I found that I wanted a way to view the structure of the repo itself. You can do this with the svn list command:

svn list –recursive file:///path/to/your/svn/repo/dir

And you’ll get a list of all your directories and files. I thought it might be nice to only see the dirs, and then furthernice to specify the depth of dirs to browse, so I cobbled together the bash script below to accomplish this. It takes the output from svn list -R and prints only items that end with a forward slash, e.g.:

svn list -R file:///home/scarpent/src/svn | svn-dirs.sh -d 2

To produce the output:

bash/
bash/nautilus-scripts/
home-bin/
web/
web/mtf/

(I also created a script that runs svn list on my local repo and pipes to svn-dirs.sh, so I don’t have to type …

bash shell script: copy only files modifed after specified date

Or maybe you just want to tar up only directories and subdirectories, excluding files…

I’ve mentioned a few times lately that I’m working on my backup plan for GNU/Linux. I started by looking at great free software tools like Samba’s rsync and GNU Tar, and I don’t think I need to look much further than them. There is also GNU Cpio, which I haven’t really investigated yet.

I may have more to say later about my rsync and tar adventures, but for today here’s something I came up with to emulate a feature of a tool I had in Windows that I couldn’t find how to do with existing tools in GNU. The xcopy DOS command lets you recursively copy files modified after a certain date by using the /D:date option.

your questions:

Why would you want to do this? Well, one reason would be for offsite backups. I regularly store backup discs in a bank safe deposit box. I then …

Don’t remove the ‘super’ from sudo, like I did in Ubuntu

There’s a fine line between empowerment and impotence in Unix. Is that why it sounds like eunuchs?

I accidentally revoked my power to run the sudo command. Yeah, it was a dumb thing to do. With godlike power comes great responsibility, and there I was like some half-wit sticking a fork in an electrical outlet. I realize the need to be careful as root in Unix systems, and in the case of Ubuntu when running sudo, but still: oops.

Maybe I was lured to incaution by the rapid typing of commands while trying to get something working, in this case: TrueCrypt. I had set the SUID bit on it with sudo chmod u+s /usr/bin/truecrypt so that a regular user could run the program, but I was concerned about security issues.

I find that in both Windows and GNU/Linux, people are quick to suggest and try things that make the systems less secure in order to get things working. Or maybe it’s that Windows starts …