1

How could I rename a bunch of dotfiles and add the leading dot in the same command? I see people writing:

ln -s vimrc .vimrc
ln -s gitconfig .gitconfig

But I would like something like this:

ln -s {vimrc,gitconfig} ~/.$1

1 Answers1

1

Using for loop:

for f in vimrc gitconfig; do ln -s  $f .$f ; done

If you have the filename list in a file:

for f in `cat filename_list.txt`; do mv $f .$f ; done
falsetru
  • 357,413
  • 63
  • 732
  • 636
  • Thanks! Could you please explain to me what is wrong with my idea? Ideally I would like to avoid spending time on a similar error next time. –  Nov 09 '14 at 03:48
  • 1
    @mm2703, `ln -s {vimrc,gitconfig} ~/.$1` will be expanded to `ln -s vimrc gitconfig ~/.$1` (specifying multiple targets) only works if the link is directory. And `$1` is not defined. It will be replaced with the first comamnd line argument in the shell script, but with empty string not in shell script. – falsetru Nov 09 '14 at 03:52