Tag Archives: cli

UNIX find writeable files – more creative

In a follow-up to my previous post, I got tired of typing things.  And so I came up with this script:



# Put arguments into an array

# If no arguments, set firt value to current dir.
if [ -z "${args[0]}" ]; then

# Loop over supplied paths and find writeable files
for arg in $args; do

  find $arg -type f -perm /u=w  | grep -v "\.class" | grep -v tmp-bin | \
grep -v aTest | grep -v fixToStuff | grep -v build/ | grep -v gensrc/ | \
grep -v Reference | grep -v "~" | grep -v "classes" | grep -v "buildtree"



My only detail to sort out was exactly how to refer to $@.  Apparently if you quote it (being exactly “$@”) that takes all the arguments as a single string.  Unquoted, it takes them separately and gets what I’m looking for.

As you can see, I also have a lot of cruft I don’t want to see in my results, so I use good ol’ “grep -v” to weed it out.  Yes, I know there is a way to use egrep to make that all one command, but for some reason it doesn’t always want to play nicely for me.  So in a classic “eff it, let the script deal with it” I just chain some pipes.  I think if I had thousands of files to sort through, this would suck.  But I don’t, so it doesn’t.

UNIX find writable files

Way back when, I posted about using find and grep.  I have learned a couple of things since then.

1) find your critiera | xargs grep your grep criteria … is nicer to your processor, memory, and quickly returning the results.

2) finding writable files.  This has been particularly useful when using a really backwards SCS that doesn’t integrate nicely, cleanly, or usable with an IDE.

My command:  find . -type f -perm /u=w

So simple. So elegant. So simply says “find all files in this directory, recursively, that are writable by the user/owner”. The one confusing thing I had about this was /u instead of /o. I figured “owner, group, world”, but it is actually “user, group, other(s)”.

Anyway, this has improved my programming life.  Yeah, I’m gonna say it… take that, Windows.

diff in ‘nix environments

After a long silence… he surfaces!  I have a couple of things to say, but I’m going to start with a very simple pleasure: diff.  First, let me clarify that I generally love the command line.  But in a world of many different pieces that all have different importance, I have come to appreciate what GUI tools have to offer.  I find the compare functionality in something like eclipse to be handy in an efficiency++ way.  So when I go back to the command line for something like this, it is because nothing else can truly replace it… like the beauty that is vi.  ;D

The short story is this:  diff -w -B -y -W 200 {file1} {file2}

Now some of you are reading that and saying, “No kidding.  Welcome to the real world.”  The rest of you may be saying “gonk… gonk… goo gonk.”  So to quote the help on diff:

  • -w:  ignore all white space (like tab expansions and changes to white space)
  • -B:  ignore changes whose lines are all blank (just in case the above is finicky)
  • -y:  output in two columns
  • -W 200:  make the output 200 columns wide (this permits both files to be displayed in full width, with room, assuming 80 char width)

I have yet to find a graphical diff tool that can manage that so nicely.  The side-by-side output is very clean and I can redirect it to a file if I want to.  Smooth, simple, elegant.  And if there’s a way to improve on this, I hope a casual passerby will comment!


M4A Music Files, Linux, and Amarok

By choice, these files have some issues under Ubuntu.  There is “something” about the origins of M4A that disagree with the Ubuntu (and Debian) mission statement/s.  So, some manual steps need to be taken to get proper playback.

If I remember correctly, Amarok 1.4.9 did not play M4A files at all.  This appears to have been fixed under 1.4.10.  That is nice.  However, the tags are not read correctly, nor can they be updated — that is not so nice.  So, to get Amarok to read these tags, some manual compilation is necessary.

It is actually not as hard as it sounds once all of the necessary information is aggregated from “umpteen” different sources.  I’m strongly tempted to simply put together a shell script to do this.  I wouldn’t be able to verify it on all systems, but with adequate embedded comments, the ambitious person would be enabled to coerce it to work on their system, assuming it needed coercion.

(1)  Downloading the sources from the Amarok site and using the command-line is essential.

(2) The commands end up being quite easy.   It assumes (a) the source has been downloaded, (b) the source has been extracted (tar xvfj amarok-1.4.10.tar.bz2) into a directory, and (c) you are in said directory.

$ sudo apt-get build-dep amarok
$ sudo apt-get install libmp4v2-dev libfaad-dev libavcodec1d libavutil1d libfaac0 libgsm1 liblame0 libpostproc1d libxine1-ffmpeg libxvidcore4 libfaad0 libmp4v2-0 libmpeg4ip-0 libmpeg4ip-dev
$ ./configure --enable-mysql --enable-postgresql --with-libmtp --with-libgpod --with-mp4v2
===  Amarok - PLUGINS  ========================================================
= The following extra functionality will NOT be included:
=   - NMM-engine
=   - Helix-engine
=   - yauap-engine
=   - Rio Karma Support
= The following extra functionality will be included:
=   + xine-engine
=   + libvisual Support
=   + MySql Support
=   + Postgresql Support
=   + Konqueror Sidebar
=   + MusicBrainz Support
=   + MP4/AAC Tag Write Support
=   + iPod Support
=   + iRiver iFP Support
=   + Creative Nomad Jukebox Support
=   + MTP Device Support
=   + DAAP Music Sharing Support
Good - your configure finished. Start make now
$ make
$ sudo make install

Note these lines, the presence of the “+” is very important:

=   + MP4/AAC Tag Write Support
=   + iPod Support

No plus, no functionality.

This worked under Kubuntu 8.10.1 using KDE 3.5.10.  This does not work under Kubuntu 9.04 using KDE 4.2.2.  I am going to wait for Amarok 2.2 to come out and see what improvements have happened.  My compelling reason to do this at this point would be to get my “smart playlists” back along with better M4A support.  Amarock 2 has M4A support (though buggy in 2.1.x) playlists and dynamic playlists, but they seem to have not understood the value of smart playlists and how the way they worked in KDE 3.5.x / Amarok 1.4.x was good.  I understand “radical new version, radical new features”, but I consider the absence of these a deal-breaker at this point.

I hope to update this post later when I get a successful compile of Amarok 1.4.10 under Kubuntu 9.04.