Solved

Script Error: mv: invalid option --1

Posted on 2004-10-08
6
673 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
Comment Utility
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
Comment Utility
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
Comment Utility
A better way would be:

for f in *.aaa; do
  mv $f `basename $f .aaa`.bbb
done
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:DBDevOne
Comment Utility
What is basename? Can you list and example?
0
 
LVL 40

Accepted Solution

by:
jlevie earned 500 total points
Comment Utility
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
Comment Utility
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

771 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