Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
for f in *; do mv "$f" "${f#??}"; done
# rename file cutting 2 leading chars
# usage
# [sh] rf2 dir
my_dir=$1
for file in $my_dir/*; do
# new file name
new_file=`cut -b 3- $file`
echo "renaming file=$file -> new_file=$new_file"
mv $file $my_dir/$new_file
done
That works for me in Bash and (M)Ksh with all kind of blanks ( including newlines ( \n ) ). And I do not see where could be a problem as [tt]*[/tt] is expanded by the same process which executes the [tt]for[/tt]. Problems used to occur only when data is pass from one process to another like [tt]for f in `ls`; do[/tt].PHV said:stefanwagner, your suggestion don't play well with blanks in filenames due to the for:
for f in [0-9][0-9]*; do mv "$f" "${f#??}"; done
There is absolutely no recursion. Search in your shell's man page for "expansion". There are many types of expansions, like parameter expansion ( ${f#??} ) and pathname expansion ( [0-9][0-9]* ). ( Some shells may use abit different terminology. )licarse said:Where can I read more about this recursive logic in order to start testing more expressions?
Well, almost :licarse said:for f in ' \*'; do mv "$f" "${f#?}"; done
Am I right?
for f in ' '*; do mv "$f" "${f#?}"; done
[gray]# or[/gray]
for f in \ *; do mv "$f" "${f#?}"; done