• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 229
  • Last Modified:

bash scripting question

i have a script that copies an archive from another folder on the server cp /pub/file.tgz .
how do i make so that if the file, is already there but unpacked, the script would check if the file exists
and automatically notify the person running the command, and ask for a new folder creation, and then the process to move to the new folder created
1 Solution
if [ -e $file ] ; then
  echo file exists
  read -p 'new folder:' folder
John KawakamiCommented:
Do you know the contents of the file before you unpack it?
if fear you must build a list of the files in the tar check if all are there and then ask:
list=`tar tfz $folder/file.tgz`
for i in $list; do
if [ -e $file ] ; then
  echo file exists
  read -p 'new folder:' folder
cd $folder
cp /pub/file.tgz .
 tar xfz file.tgz
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now