#!/bin/bash echo Enter a Directory Name: read if [ -d "$1" ]; then find "$1" -type f -size 0 -delete find "$1" *.tmp -type f -delete find "$1" *.swp -type f -delete tar -cvzf mytarfile.tgz "$1" else echo "This is not a directory" fi The script runs when I put in the directory myself using ./program.sh Desktop. If I have an empty txt, .tmp and .swp file on my desktop it removes them and makes a tar file. How can I enter a directory at the (read) line for example Documents or MyMusic. It allows me to type in something but then goes right to the else and prints "This is not a directory.
findcommands do not do what you seem to want; they delete all files (of any type) in the specified directory, and also the .tmp and .swp files in the current directory (not the specified one). I'm pretty sure you want e.g.find "$1" -name '*.swp' -type f -delete.