Solved

Script Error: mv: invalid option --1

Posted on 2004-10-08
6
690 Views
Last Modified: 2012-06-27
The script changes the extention on file names. It is as follows:

for i in 'ls *.aaa | cut -f1 -d '; do
   mv $i.aaa $i.bbb;
done

getting an error when run

mv: invalid option --1
0
Comment
Question by:DBDevOne
  • 3
  • 2
6 Comments
 
LVL 23

Expert Comment

by:brettmjohnson
ID: 12261430
Your cut command delimiter is wrong.  I think you wanted -d .
Your script will also fail if a filename contains spaces or multiple
filename extensions.

I recently wrote this script for a client that was transitioning from
Linux to Mac OS X (which lacks the Linux 'rename' command):


#!/bin/bash
# This Bash shell script emulates the linux 'rename (1)' command
# The "usage" man page help  was shamelessly stolen from Linux.
# 04 Aug 2004  Brett Johnson  

# Must have at least three args: fromtext, totext, file...
if [ $# -lt 3 ] ; then
  cat <<END
NAME
        rename - bulk rename files

SYNOPSIS
        rename fromtext totext files...

DESCRIPTION
        rename will rename the specified files by replacing the
        first occurrence of fromtext in their name with totext.

        For example, given the files foo1, ..., foo9, foo10, ..., foo278,
        the commands

          rename foo foo0 foo?
          rename foo foo0 foo??

        will turn them into foo001, ..., foo009, foo010, ..., foo278.

        And

          rename .htm .html *.htm

        will fix the extension of your html files.

END

else
  fromtext=$1
  totext=$2
  shift 2

  for f in "$@" ; do mv $f ${f/$fromtext/$totext} ; done
fi
0
 

Author Comment

by:DBDevOne
ID: 12261550
Thanks for teh comment. This is my first script. There are no spaces or multiple extentions. How would I modify my script to eliminate the error?
0
 
LVL 40

Expert Comment

by:jlevie
ID: 12261641
A better way would be:

for f in *.aaa; do
  mv $f `basename $f .aaa`.bbb
done
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:DBDevOne
ID: 12261767
What is basename? Can you list and example?
0
 
LVL 40

Accepted Solution

by:
jlevie earned 500 total points
ID: 12262058
From 'man basename':

basename - strip directory and suffix from filenames

DESCRIPTION
       Print  NAME  with  any leading directory components removed.  If speci-
       fied, also remove a trailing SUFFIX.

My example uses its ability to strip a specified SUFFIX (.aaa) from a file name. By executing the command in a subshell `basename $f .aaa` I get the portion of the filename up to the suffix returned to which I append .bbb. So `basename this-is-the-file.aaa .aaa` would return this-is-the-file and
`basename this-is-the-file.aaa .aaa`.bbb would yield this-is-the-file.bbb.

Make sense?
0
 

Author Comment

by:DBDevOne
ID: 12267100
Thank you for your answers. Brett, I am sure yours was great too, I chose jlevie's because it helped me find the cause of the error I got.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
idM Identity Management in Red Hat 6 - setting up 9 263
usage of %{name} in rpm spec file 4 49
Problem to run file 9 103
Cron jobs 12 121
Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now