Note that there are some explanatory texts on larger screens.

plurals
  1. POBASH - Renaming pictures based on file type
    primarykey
    data
    text
    <p>I'm a bit frustrated here with trying to get what seems like a simple bash script to run properly. I believe this is due to very long file names, or spaces within the file.</p> <p>In short, I'm trying to pull data from the file command, and rename pictures in a directory to their proper file type as some seem to be mis labeled. For example a .png file is actually a .jpg file. Which results in some image viewers not displaying them. Here is the script i'm using.</p> <pre><code>#!/bin/bash for NAME in $(ls); do if [ "$(file $NAME|grep GIF)" ]; then echo "Renaming ${NAME} to ${NAME%.*}.gif" mv ${NAME} ${NAME%.*}.gif elif [ "$(file $NAME|grep JPG)" ]; then echo "Renaming ${NAME} to ${NAME%.*}.jpg" mv ${NAME} ${NAME%.*}.jpg elif [ "$(file $NAME|grep PNG)" ]; then echo "Renaming ${NAME} to ${NAME%.*}.png" mv ${NAME} ${NAME%.*}.png else echo "No Change For ${NAME}" fi done </code></pre> <p>The echo at the end was just to see why it was failing, this is what I see:</p> <pre><code>No Change For 20097489744.jpeg No Change For 24902583463 </code></pre> <p>Then it just hangs, why? Because I believe that file contains spaces... I looked around a bit on mass renaming all the files in the directory by just incrementing the file names up, IE: 1.jpg 2.png 3.gif however EVERYTHING I have found online was not to increment a file rename job, but rather to remove numbers from the name and things like it.. So, I've hit a wall, short of renaming 130K files by hand (Not going to happen! lol)</p> <p>I''d highly appreciate any input from the brainiacs out there!</p> <p>Thanks and happy holidays!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload