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

Tuesday, June 4, 2013

Using 'find' to list files with multiple suffixes

I'm going through another data cleanup session in a (very) old work directory tree. I found myself examining/compressing/removing files with a recurring set of suffixes. The 'find' command can make this all a lot less painful.

Here's the command for matching a single suffix:

But editing this command-line to match the next suffix of interest becomes tedious very quickly. Thankfully, you can chain together file tests like so (note the grouping):

Then acting on these files is easy - just update the -exec action to what you want (e.g. "-exec bzip2 {} \;" - you probably want to use xargs or "-exec bzip2 {} +" for this to reduce the number of command invocations)

An interesting note here is that the following command isn't executed as you might expect. The 'ls' command is only executed on the *.tsv files due to the way the expression is evaluated: from left to right with the implicit '-and' between the second '-name' and '-exec' exec having higher precedence than the '-or' between the two '-name' tests..

Wednesday, April 10, 2013

Finding (and fixing) files with undesirable permissions

I use a few programs that create files that are not group read/writable; this is an issue when working in a group environment (especially with Knime where important files are locked this way which prevents other users from even opening your workspaces). Here's a find command that'll locate these files: This command executes 'ls -lh' on each of the files to show the current permissions (would probably be more efficient to push into xargs to run ls on multiple files at once). The next find command will update the permissions on those files: Of course, you can just run chmod recursively (chmod -R g+rw *), but this isn't always what you want.

Thursday, June 18, 2009

using find to catch up on what's changed

I came back from a two week vacation and needed to find out what had been updated/added/changed in that time in some shared project dirs. "find" was my friend. The following command gives a list of all files changed within the last two weeks.

find . -ctime -14
'-ctime -14' will be true for all files/dirs that have been changed in the last 14*24 hours. You can alter the behaviour by changing the modifier on the numerical input:

+n for greater than n,
-n for less than n,
n for exactly n.