Prepend text to beginning of file names

I would like to prepend a string of text to the beginning of each file in a directory. The string is uniwisc.

When I run the script:



wget -r -nd --no-parent -nc -P /awips2/edex/data/goes14/ $url

find /awips2/edex/data/goes14/ -type f -exec cp {} /awips2/edex/data/uniwisc/ \;

for f in /awips2/edex/data/uniwisc/*; 
    f="$(basename $f)"
    mv "$f" "uniwisc.$f"

find /awips2/edex/data/uniwisc/ -type f -mmin -6 -exec mv {} /awips2/edex/data/manual/ \;
exit 0

I get the error mv: cannot stat '<filenames>' "No such file or directory.


There are a number of different ways that you can do that.

Using paramater expansion, which is built into the bash shell:

for f in <dir path>/*; do
    mv "$f" "${f%/*}/uniwisc.${f##*/}"

Using the rename command:

rename 's!^!uniwisc.!' *

Using the basename, as CodeGnome suggested:

for f in <dir path>/*; do
    mv "$f" "$(dirname "$f")/uniwisc.$(basename "$f")"

I was going to write more methods, but there are a lot of them and they don't change significantly. Personally, I'd use the rename command in that situation.

Need Your Help

Qt5 fails to load module tslib because

qt5 embedded-linux

I'm running into an odd problem on an embedded device. When I run qt5

How do i implement ‘sign in with google’ on my site?

login gmail cross-domain openid google-oauth

On my site I would like to allow users to sign in with a google account. I plan to use openid but I would like to allow signing in with google because it has more benefits. I've noticed in the past...