stupid unix question

Ask a Question related to Mac Applications & Software, Design and Development.

  1. #1

    Default Re: stupid unix question

    Joon <spoot@spacemoose.com.invalid> wrote:
    > let's say I have 5000 files that lack both extensions and type/creator
    > for whatever reason. I know that they are JPEGs. I need to either add
    > an extension or the type/creator stuff. I'd rather have the extension
    > for windoze compatibility and batch processing for printing and
    > prepress.
    > what is the syntax of (I guess) the "mv" command to add a .jpg
    > extension to all of them, assuming the file names are all eight digits
    > e.g. "0010051" and that I have cd'd to the correct directory?
    > someone told me I'd need to write a shell script to do this, and my
    > blood froze. dammit Jim, I'm a print geek, not a sysadmin.
    Well... it does require such shell constructs as a loop, so some sort of
    shell script is necessary. But never fear! It is three lines and you
    don't even have to write a file / execute it. Just type it straight into
    the shell.

    I'm assuming tcsh here, which is the default in Jaguar. If you use bash
    or something else, there's going to be some differences. '%' is your
    shell prompt, 'foreach ->' is a mini prompt the shell also provides.

    % foreach i (*)
    foreach -> mv "$i" "$i.jpg"
    foreach -> end

    Make sure you are in the correct directory when you run this because the *
    grabs all files in the current directory.
    --
    *--------------------------------------------------------*
    | ^Nothing is foolproof to a sufficiently talented fool^ |
    | Heath Raftery, HRSoftWorks _\|/_ |
    *______________________________________m_('.')_m__ _______*
    Heath Raftery Guest

  2. Similar Questions and Discussions

    1. Stupid Question
      For as long as I've been doing Elements, I'm embarassed to ask. I've created an oval shaped image. I want to insert it into a web page as an oval...
    2. Stupid question.
      I've worked with cfdirectory in the past but it mainly within the scope of deleting/creating a directory or get the name of files within a specific...
    3. OK. I'm asking a stupid question
      I created a multi-frame movie to use as my website. It has five buttons on it which I added the Get URL action to. When I publish it, and then open...
    4. Stupid C# question Please help!
      I'm used to writing my code in VBscript but I have to do this project in C#. I've written some functions on my ASP.Net page and I'm getting an...
    5. Is this a stupid question?
      I'm looking for the command to direct a user to a new URL. For example, in ASP, when you created a dropdown box, the item selected could open a...
  3. #2

    Default Re: stupid unix question

    In article <170720032303369803%spoot@spacemoose.com.invalid >,
    Joon <spoot@spacemoose.com.invalid> wrote:
    > let's say I have 5000 files that lack both extensions and type/creator
    > for whatever reason. I know that they are JPEGs. I need to either add
    > an extension or the type/creator stuff. I'd rather have the extension
    > for windoze compatibility and batch processing for printing and
    > prepress.
    >
    > what is the syntax of (I guess) the "mv" command to add a .jpg
    > extension to all of them, assuming the file names are all eight digits
    > e.g. "0010051" and that I have cd'd to the correct directory?
    >
    > someone told me I'd need to write a shell script to do this, and my
    > blood froze. dammit Jim, I'm a print geek, not a sysadmin.
    Instead of messing with Unix commands and scripts, try Renamer4Mac.
    It's a freeware GUI app that makes it easy to rename a bunch of files --
    adding an extension, or numbering them sequentially, or doing a search &
    replace on the filenames, etc. It'll even show you what the new
    filenames will be *before* it renames them, so you can make sure you get
    what you want.

    <http://www.power4mac.com/>
    Wayne C. Morris Guest

  4. #3

    Default Re: stupid unix question

    There's an Applescript included with X called "Add Pre-Suffix.scpt" that
    does the job fast and easy. I use it all the time, no need to resort to
    Shell commands.

    I've uploaded a copy:
    [url]http://home.earthlink.net/~w6zno/Add%20Pre-Suffix.scpt.sit[/url]

    -- Gnarlie


    Entity Joon spoke thus:
    > let's say I have 5000 files that lack both extensions and type/creator
    > for whatever reason. I know that they are JPEGs. I need to either add
    > an extension or the type/creator stuff. I'd rather have the extension
    > for windoze compatibility and batch processing for printing and
    > prepress.
    >
    > what is the syntax of (I guess) the "mv" command to add a .jpg
    > extension to all of them, assuming the file names are all eight digits
    > e.g. "0010051" and that I have cd'd to the correct directory?
    >
    > someone told me I'd need to write a shell script to do this, and my
    > blood froze. dammit Jim, I'm a print geek, not a sysadmin.
    >
    > j thank &deity; drag n drop to the terminal sets the working directory
    > b.

    Gnarlodious Guest

  5. #4

    Default Re: stupid unix question

    Jeremy <jeremy@exit109.com> wrote:
    > Matt McLeod <matt@boggle.org> wrote:
    >> Here's a one-liner with no shell loop:
    >>
    >> find . -exec mv {} {}.jpg \;
    >>
    >> As always, more than one way to do it. :)
    > I use a shell function in zsh, which will replace an existing extension
    > if one is there:
    > chext () {
    > local file newext
    > newext=$1
    > shift
    > for file in $argv
    > do
    > mv $file $(echo $file(:r)).${newext#.}
    > done
    > }
    > Call as: chext .jpg *
    Will that work in most shells with 5000 files? I'd be expecting a 'argument
    list too long' error. Or is that up to the command to decide?

    Heath

    --
    *--------------------------------------------------------*
    | ^Nothing is foolproof to a sufficiently talented fool^ |
    | Heath Raftery, HRSoftWorks _\|/_ |
    *______________________________________m_('.')_m__ _______*
    Heath Raftery Guest

  6. #5

    Default Re: stupid unix question

    Heath Raftery <hraftery@myrealbox.com> wrote:
    >> chext () {
    >> local file newext
    >> newext=$1
    >> shift
    >> for file in $argv
    >> do
    >> mv $file $(echo $file(:r)).${newext#.}
    >> done
    >> }
    >>
    >> Call as: chext .jpg *
    >
    > Will that work in most shells with 5000 files? I'd be expecting a 'argument
    > list too long' error. Or is that up to the command to decide?
    No, argument list length is up to the shell, not the command. The above is
    written for zsh, and will probably not work in any other shell.

    If there are too many files, the workaround would be to call it multiple times,
    each with a subset of the files.

    --
    Jeremy | [email]jeremy@exit109.com[/email]
    Jeremy Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139