0

Team,
Presently i have some 20 files which i need to copy and store in the common directory.

below is the example:
script name: dir.sh
cp /tmp/abc /home/abc/xyz
cp /tmp/def /home/abc/xyz
cp /tmp/hij /home/abc/xyz

The above script is run, it copies the source files on the destination directory(xyz), wanted to make it more interesting.
a)it should prompt me if the directory exist/else create it
b)cp command should be taken as input file, so that incase i have more changes i can directly make changes to the file where all copy commands are stored
c)maintain the copy files on the basis of the date when it was copied,so that it could enable me delete only those files which are older by 3 days old.

Have prepared for the file creation(a), need assistance on the others(i.e b & c)

read sd
if [ ! -d "/home/abc/$sd" ] && mkdir "/home/abc/$sd"; then
 echo "That directory does not exists,new directory was created"
 else
      echo "Directory present"
fi

Regards
Whizkid

2
Contributors
1
Reply
10
Views
1 Year
Discussion Span
Last Post by cfajohnson
0
cpfile=$HOME/bin/cpfile
dest=/home/abc
for file in /tmp/*
do
  printf 'cp "%s" "%s"\n'  "$file" "$dest"
done > "$cpfile"

Use find to list files older than 3 days:

find "$dest" -type f -mtime +3

Edited by cfajohnson

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.