[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: truncate until delimiter

* 2010-02-28 15:13 (+0100), Vadkan Jozsef wrote:

> I just want to modify the names of some files, but I can't do it if
> they have their full path "in their names"..

Maybe basename and dirname commands could help?

    $ basename /foo/bar/file.txt

    $ dirname /foo/bar/file.txt

So, if you need to rename files with a shell script you could do
something like this:

    for f in "$@"; do
            base=$(basename -- "$f")
            dir=$(dirname -- "$f")
            new="whatever-$base" # Some magic to create new name
            mv -- "$f" "$dir/$new"

The you can have full paths in "$@" and the script handles them just

Feel free to Cc me your replies if you want to make sure I'll notice

Reply to: