bash script to organize files and cleanup files I have been working on a bash script for a while now to organize my movie files.  I can do it by hand, but at the time I was taking a bash scripting class and thought I would like to use it to create this project.  I don't know if there is a better way of doing it or not, but I would like you to take a look at my script and give me feedback on it.  I believe it works, but I haven't put it through the paces yet.

#!/bin/bash

MovieList="points to .txt file with name of files"
DirList="points to a .txt file with the name to use to create the directory"
dest_Dir="where to put the files "
src_Dir="where to look for the files"
CreateLogFile="log file of directory created"
MoveLogFile="log file of move files"

# Will read in a list of movies and make the directories for them

createDirectory()
{
    while read -r line
    do
    if [ ! -d $dest_Dir"$line" ]
    then
            mkdir -v $dest_Dir"$line" &gt;&gt; $CreateLogFile
    else
            :
    fi
done &lt; "$DirList"
}
# end createDirectory

# After directories have been created will go and find those movies and move
# them to their proper directory

movieMovies()
{
    while read -r line
do
    find $src_Dir  -type f \( -iname "$line" ! -iname ".*" \) | xargs -I '{}' mv -v {} $dest_Dir"$line" &gt;&gt; $MoveLogFile
done &lt; "$MovieList"
}
# end of moveMovies

# Time to tidy up by going back and seeing if there is any empty directory
# and if so removing said directory

DirectoryEmpty()
{
while read -r line
do
    if [ $(ls -A $dest_Dir"$line" | wc -l) -eq 0 ]
    then
        rmdir $dest_Dir"$line" 
    else
        :
    fi
done &lt; "$DirList"
}
# end of DirectoryEmpty

# ---------------------------------Main---------------------------------------
createDirectory
moveMovies
DirectoryEmpty
# ----------------------------------End---------------------------------------
errors


typo: function named movieMovie, invoked as moveMovie


potential errors


use of $dest_Dir"$line"

you expect dest_Dir to end with a slash, but that's not validated anywhere
use "$dest_Dir/$line" instead (it's OK to have multiple slashes)

don't use ls to verify the presence/absence of files:

removeEmptyDirectory() {
    dir="$1"
    shopt -s globstar nullglob dotglob
    files=("$dir"/*)  # an array holding all the filenames
    if (( ${#files[@]} == 0 )); then
        # the directory is empty
        rmdir "$dir"
    else
        echo "warning: directory not empty: $dir" &gt;&amp;2
    fi
}


Even better, use find:

removeEmptyDirectories() {
    while read -r line; do
        find "$dest_Dir/$line" -depth 0 -empty -exec rmdir '{}' \;
    done &lt; "$DirList"
}

Double quote all your variables, everywhere, unless you have a specific reason not to.


style


clean up your indentation.  It is idiomatic to put then and do at the end of the same line as if and while (see removeEmptyDirectories() example above).
use a consistent naming convention

variables DirList, src_Dir -- use camelcase or underscores, but both?

don't need the else : branch
"line" is not a descriptive variable name.
use find -exec instead of piping to xargs.