shell - Prepend text to beginning of file names -


i prepend string of text beginning of each file in directory. string uniwisc.

when run script:

#!/bin/sh  url="ftp://rammftp.cira.colostate.edu/lindsey/spc/ir/"  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/ \;  f in /awips2/edex/data/uniwisc/*;          f="$(basename $f)"     mv "$f" "uniwisc.$f"     done;  find /awips2/edex/data/uniwisc/ -type f -mmin -6 -exec mv {} /awips2/edex/data/manual/ \; exit 0 

i error mv: cannot stat '<filenames>' "no such file or directory.

there number of different ways can that.

using paramater expansion, built bash shell:

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

using rename command:

rename 's!^!uniwisc.!' * 

using basename, codegnome suggested:

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

i going write more methods, there lot of them , don't change significantly. personally, i'd use rename command in situation.


Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -