Problem moving (and copying) files with wildcard

Today I was approached by my colleague to help him rename files that have a starting character of hyphen "-".  I tried double quotes and single quote but it is not working.  Odd that I haven't encountered this for my last 3 years in Unix/Linux.

mv: invalid option -- 2
Try `mv --help' for more information.

Good thing I have searched around and find about the use of "./".  So I am posting it here.

# ls
-13:36:37.tgz  -13:36:56.tgz  -13:37:02.tgz
-13:36:53.tgz  -13:36:59.tgz  -13:37:05.tgz

Files have been generated via script, I just wonder what went wrong with that.  So I needed to rename it with hostname as its prefix.

# ls | while read i; do echo $i; mv ./$i `hostname`-`date +%Y%j%N`.tar.gz; done; ls -l
total 312
-rw-r--r-- 1 root root 17988 Jul 13 13:30 bucmes001.global.hosting.net-2017194000141000.tar.gz
-rw-r--r-- 1 root root 55112 Jul 13 13:30 bucmes001.global.hosting.net-2017194002990000.tar.gz
-rw-r--r-- 1 root root 59228 Jul 13 13:30 bucmes001.global.hosting.net-2017194005274000.tar.gz
-rw-r--r-- 1 root root 58821 Jul 13 13:30 bucmes001.global.hosting.net-2017194007552000.tar.gz
-rw-r--r-- 1 root root 59889 Jul 13 13:30 bucmes001.global.hosting.net-2017194010266000.tar.gz
-rw-r--r-- 1 root root 38151 Jul 13 13:30 bucmes001.global.hosting.net-2017194996296000.tar.gz

So everything works now!

No comments:

Post a Comment