Note that there are some explanatory texts on larger screens.

plurals
  1. POBash script: Copies image files from source dir to destination dir and adds an extra suffix on files with same file name
    primarykey
    data
    text
    <p>I have this script that copies image files from source directory to destination directory. There are some image files in the source directory that have the same name but different file size. This script also compares the two files with the same name using a <strong>stat</strong> command. Now, I want to add a string suffix e.g. IMG0897.DUP.JPG before the file extension to the files with the same file name that are going to be copied over to the destination folder. At the moment, my script adds the file size of the file to the file name. </p> <p>I need help on how to add a string of text of my own rather than the size of the file. Here's my script:</p> <pre><code>#!/bin/sh SEARCH="IMG_*.JPG" SOURCE= $1 DEST=$2 test $# -ne 2 &amp;&amp; echo Usage : phar image_path archive_path if [ ! -e $1 ] then echo Source folder does not exist fi if [ ! -e $2 ] then mkdir $2/ fi # Execute the script. if [ "${SEARCH%% *}" = "$SEARCH" ]; then command="find \"$1\" -name \"$SEARCH\"" else command="find \"$1\" -name \"${SEARCH%% *}\""$(for i in ${SEARCH#* }; do echo -n " -o -name \"$i\""; done) fi # Run the main loop. eval "$command" | while read file; do bn=$(basename "$file") bc=$(stat -c%s "$file") if [ -f "${2}/$bn" ] &amp;&amp; [ "$bc" -ne $(stat -c%s "${2}/$bn") ]; then bn="$bn.$bc" fi if [ -f "${2}/$bn" ]; then echo "File ${2}/$bn already exists." else echo "Copying $file to $2/$bn" cp -a "$file" "$2/$bn" fi done exit 0 else echo "Error : Can't find $1 or $2" exit 1 fi </code></pre>
    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.
    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