File rename error


 
Thread Tools Search this Thread
Homework and Emergencies Emergency UNIX and Linux Support File rename error
# 8  
Old 10-18-2011
Both won't work, because they protect the - from interpretation by the shell, which is not the problem. The getopt function in the mv command will still interpret the leading - as an optionlist.
Code:
$ ls
-9file.jpg
$ mv \-9file.jpg 9file.jpg
mv: illegal option -- 9
mv: illegal option -- l
mv: illegal option -- e
mv: illegal option -- .
mv: illegal option -- j
mv: illegal option -- p
mv: illegal option -- g
mv: Insufficient arguments (1)
Usage: mv [-f] [-i] f1 f2
       mv [-f] [-i] f1 ... fn d1
       mv [-f] [-i] d1 d2
$ mv '-9file.jpg' 9file.jpg
mv: illegal option -- 9
mv: illegal option -- l
mv: illegal option -- e
mv: illegal option -- .
mv: illegal option -- j
mv: illegal option -- p
mv: illegal option -- g
mv: Insufficient arguments (1)
Usage: mv [-f] [-i] f1 f2
       mv [-f] [-i] f1 ... fn d1
       mv [-f] [-i] d1 d2


Last edited by hergp; 10-18-2011 at 11:05 AM.. Reason: clarification
# 9  
Old 10-18-2011
Code:
ant:/home/vbe $ mv \-9file.jpg 9file.jpg
Usage: mv [-f] [-i] [-e warn|force|ignore] f1 f2
       mv [-f] [-i] [-e warn|force|ignore] f1 ... fn d1
       mv [-f] [-i] [-e warn|force|ignore] d1 d2
ant:/home/vbe $ mv ./\-9file.jpg 9file.jpg
ant:/home/vbe $

# 10  
Old 10-20-2011
Quote:
Originally Posted by Tommyk
as stated above - tells the command to expect options as it is a special character.
You need to remove the special meaning of this either by the backslash or by using quotes.

Code:
mv \-9file.jpg 9file.jpg
or
mv '-9file.jpg' 9file.jpg

Dash is not a special character, it does not need to be backslashed, never.

Code:
localhost kernel # echo -
-
localhost kernel # echo "-"
-
localhost kernel # echo '-'
-
localhost kernel # echo \-
-
localhost kernel #

Stick with the -- solution. It's the official Smilie
# 11  
Old 10-21-2011
Code:
 
man mv

Code:
 
A -- permits the user to mark explicitly the end of any com-
     mand  line  options, allowing mv to recognize filename argu-
     ments that begin with a -. As an aid to  BSD  migration,  mv
     will  accept  -  as a synonym for --. This migration aid may
     disappear in a future release

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash to copy file 3 times and rename based on another file

In the below bash I am trying to copy the only text file (always only one) in /home/cmccabe/Desktop/list/QC/metrics.txt and rename each of the 3 text files according to /home/cmccabe/Desktop/test/list.txt using lines 3, 4 ,5. This format (that is list.txt) is always 5 lines. Thank you :). ... (12 Replies)
Discussion started by: cmccabe
12 Replies

2. Shell Programming and Scripting

Rename specific file extension in directory with match to another file in bash

I have a specific set (all ending with .bam) of downloaded files in a directory /home/cmccabe/Desktop/NGS/API/2-15-2016. What I am trying to do is use a match to $2 in name to rename the downloaded files. To make things a more involved the date of the folder is unique and in the header of name... (1 Reply)
Discussion started by: cmccabe
1 Replies

3. UNIX for Dummies Questions & Answers

awk - Rename output file, after processing, same as input file

I have one input file ABC.txt and one output DEF.txt. After the ABC is processed and created output, I want to rename ABC.txt to ABC.orig and DEF to ABC.txt. Currently when I am doing this, it does not process the input file as it cannot read and write to the same file. How can I achieve this? ... (12 Replies)
Discussion started by: High-T
12 Replies

4. UNIX for Dummies Questions & Answers

look for specific values in a file and rename file with value found

Hi, i have a file with some data ..look for some specific value in the file and if found that value rename the file with the value found in the file.. ex.. File.txt 1236 43715825601ANDERSSON, 1236 437158256031963040120060901200609010000000 1236 43715825604123 MCCL AVE UPPER 1236 ... (11 Replies)
Discussion started by: dssyadav
11 Replies

5. UNIX for Advanced & Expert Users

How to rename a file

Hi, on AIX 6.1 I have a file : myfile.log And I want to rename it as : myfile_dateoftheday.log For example today (20 of Dec 2010) : myfile_201210.log How can I do that ? Thanks. (4 Replies)
Discussion started by: big123456
4 Replies

6. Shell Programming and Scripting

Perl script to rename file,error

#!/usr/bin/perl $FL="ch.txt"; $CFL="mytext.txt"; print "This script will rename textfiles."; mv $FL $CFL; print "Done."; perl file.pl Error: Can't locate object method "mv" via package "ch.txt" (perhaps you forgot to load "ch.txt"?) at file.pl line 7. (5 Replies)
Discussion started by: cola
5 Replies

7. Shell Programming and Scripting

A script that will move a file to a directory with the same name and then rename that file

Hello all. I am new to this forum (and somewhat new to UNIX / LINUX - I started using ubuntu 1 year ago).:b: I have the following problem that I have not been able to figure out how to take care of and I was wondering if anyone could help me out.:confused: I have all of my music stored in... (7 Replies)
Discussion started by: marcozd
7 Replies

8. UNIX for Dummies Questions & Answers

Rename file based on first 3 characters of data in file

I'm looking to determine if I can use a grep command to read file and rename the file based on the first 3 characters of the data in the file. An example is: Read FileA If the first 3 positions of the data in the file are "ITP", then rename the file as FileA_ITP, else if the first 3... (3 Replies)
Discussion started by: jchappel
3 Replies

9. UNIX for Dummies Questions & Answers

Help with multiple file rename - change case of part of file name

Hi there, I hope someone can help me with this problem : I have a directory (/var/www/file/imgprofil) which contains about 10000 JPG files. They have a naming convention thus : prefix-date-key-suffix.jpg they all have the prefix p-20050608- then AAAA is a 4 letter code the suffix is... (7 Replies)
Discussion started by: steve7
7 Replies

10. Shell Programming and Scripting

Rename error message!

Can anyone tell me why I keep on getting this error message? ../dosRename: syntax error at line 77: `end of file' unexpected I have treid everything and I just can get it to work! Here is the code: #!/bin/sh Usage() { && echo "\n$*\n" >&2 cat <<-EOD_USAGE >&2 Usage:... (4 Replies)
Discussion started by: Zeta_Acosta
4 Replies
Login or Register to Ask a Question