Shell scripting

Im trying to write a shell script which will help me to copy files from one directory to another satisfying some conditions.

  • It should first check if there is any folder with the name of the file (yes, i said folder ). And if yes, then it should check whether the folder is having any files in it. If the condition is true, move on to the next file. Else delete the folder and copy the file.
  • If the first condition is false (checking the file name with folder name), copying should be done.

Might be an easy case for majority of you guys, im a newbie and im facing issues with the proper scripting.

Welcome arjun1891,

I have a few to questions pose in response first:-

  • Is this homework/assignment? There are specific forums for these.
  • What have you tried so far?
  • What output/errors do you get?
  • What OS and version are you using?
  • What are your preferred tools? (C, shell, perl, awk, etc.)
  • What logical process have you considered? (to help steer us to follow what you are trying to achieve)
  • By folder, do you mean directory? A folder is usually a Windows or other GUI term for the same thing.

Most importantly, What have you tried so far?

There are probably many ways to achieve most tasks, so giving us an idea of your style and thoughts will help us guide you to an answer most suitable to you so you can adjust it to suit your needs in future.

We're all here to learn and getting the relevant information will help us all.

Kind regards,
Robin

  • Yes, its an assignment.
  • I'm new to scripting and i have tried using for loop and if conditions but i don't think without a proper guidance i could implement the logic fully.

I'm using centos7 (headless) and im working with shell scripting. Im sorry i used the term folder. Its directory. We are taking about files and directories.

Thanks and regards,
arjun

Wlecome
Please repost in adequate forum:

Special rules apply there, please read them and post in conformance, thanls

this thread is closed

2 Likes