Skip to main content
add parameter substitution option
Source Link

If you don't need the username in the final filename, would

for i in /path/to/users/*/userinfo.csv ; do
  mv $i /path/to/users/userinfo-$RANDOM.csv
done

do the trick for your use-case ?

If not, you can also use bash's parameter substitution:

for i in /path/to/users/*/userinfo.csv ; do
  mv $i /path/to/users/${i//\/-}
done

This will replace all / with - in the variable $i (path+filename). So you'll end up with, for example:

/path/to/users/path-to-users-john-userinfo.csv
/path/to/users/path-to-users-jack-userinfo.csv

If you don't need the username in the final filename, would

for i in /path/to/users/*/userinfo.csv ; do
  mv $i /path/to/users/userinfo-$RANDOM.csv
done

do the trick for your use-case ?

If you don't need the username in the final filename, would

for i in /path/to/users/*/userinfo.csv ; do
  mv $i /path/to/users/userinfo-$RANDOM.csv
done

do the trick for your use-case ?

If not, you can also use bash's parameter substitution:

for i in /path/to/users/*/userinfo.csv ; do
  mv $i /path/to/users/${i//\/-}
done

This will replace all / with - in the variable $i (path+filename). So you'll end up with, for example:

/path/to/users/path-to-users-john-userinfo.csv
/path/to/users/path-to-users-jack-userinfo.csv
Source Link

If you don't need the username in the final filename, would

for i in /path/to/users/*/userinfo.csv ; do
  mv $i /path/to/users/userinfo-$RANDOM.csv
done

do the trick for your use-case ?