Issue
I need to do some testing for that I want to make a temporary Directory in the Dev instance of my Unix server (Redhat Linux 6.9(64-bit)) and copy the files in that directory on which i want to perform testing.
Solution
The following script should do what you described:
#! /bin/bash
read -p 'enter name of new folder: ' dir
if [ -e "$dir" ]; then
echo 'A folder with the specified name already exists. Choose a different name.'
else
mkdir "$dir"
while read -r ; do
mystring="${REPLY:2}"
mystring="$(sed 's/\//_/g' <<<"$mystring")"
cp "$REPLY" "$dir/$mystring"
done < <(find / -mtime +30 -name '*.log' -type f)
fi
Where you can adjust the find
command at the bottom to your needs:
+30
denotes files older than 30 days and/
specifies the search directory you want to use to search for your log-files.
Here I assumed you want to search for log-files in the root directory /
.
Answered By - avermaet