Hacker News new | past | comments | ask | show | jobs | submit login

I think this indicates a huge difference between Microsoft/UNIX mindsets. Microsoft allowed

   rename *.txt *.bak
To do this, the "rename" command had to understand how to parse the asterisk character while being familiar with the contents of the directory. However, creating a new replacement "rename" command is difficult, as well as creating new commands that can parse wildcards.

In the Unix environment, the shell expands the asterisk to all files that matches that pattern, and then passes these files to the "rename" command, who never sees the asterisk. Therefore it's trivial to create a new "rename' utility because it doesn't need to parse wildcards. However, renaming all .txt to .bak is awkward in a UNIX system.




It may be awkward but it's no use to ruin a perfect system for just one usecase. For what it's worth, zsh provides a capable renamer tool called zmv. An example:

    zmv -W '*.txt' '*.markdown'
And of course there are tools like rename(1) that work regardless of the shell used.


    find --name *.txt --exec mv {} {}.bak\;
That's imperfect because find doesn't provide a nice way to do the pattern-replacement but it's a pretty simple pattern.

If this use case were important, it's simple enough to write a purpose-built program that generated command-line argument pairs according to a spec.


I would probably do

   find -name '*.txt' -exec bash -c 'mv -nv "$0" "${0/.txt/.bak}"' {} \;
That's not at all user-friendly, but these are supposed to be programmer tools... If you want user-friendly file operations on UNIX command line, use midnight commander. It can do mass rename, etc.


By the way: the Perl-based rename utility allows for similarly convenient file name transformations:

http://search.cpan.org/~rmbarker/File-Rename-0.06/rename.PL




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: