Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I have one question.. I have two directories.. one is /logs and other is /logs_backup.
There are 5 folders in /logs directory with the name Jan,Feb,Mar,Apr and May .. now what I want to do is
that I want to move these folders log(Jan,Feb,Mar,Apr and May) in /logs_backup directory.
I want a script in which when script will run,it will check in /logs_backup directory that whether is Jan folder is there or not? If it is there then ok and if it is not there then create a folder with name of Jan.
Same way If I'll add any new folder in /logs directory with the coming months name like Jun,Jul etc so when the scripts run next time it will check first that whether Jun folder is available in /logs_backup or not? If it is available then no need to create but when if it is not there then create folder with the same name..If anybody help me on this then I shall be very thankful to him/her.. Thanks in advance.. Ankit
I don't quite understand. You're saying "if there is a folder in /logs_backup that is called "Jan", then move the "Jan" folder from /logs to /logs_backup. Otherwise, create a folder in /logs_backup called "Jan" and move /logs/Jan to /logs_backup/Jan/Jan?
Hi All,
I have one question.. I have two directories.. one is /logs and other is /logs_backup.
There are 5 folders in /logs directory with the name Jan,Feb,Mar,Apr and May .. now what I want to do is that I want to move these folders log(Jan,Feb,Mar,Apr and May) in /logs_backup directory.
I want a script in which when script will run,it will check in /logs_backup directory that whether is Jan folder is there or not? If it is there then ok and if it is not there then create a folder with name of Jan.
Same way If I'll add any new folder in /logs directory with the coming months name like Jun,Jul etc so when the scripts run next time it will check first that whether Jun folder is available in /logs_backup or not? If it is available then no need to create but when if it is not there then create folder with the same name..If anybody help me on this then I shall be very thankful to him/her.. Thanks in advance.. Ankit
You've been registered here for two years now...writing a script should be something you can easily do. As others have said, post what you've written/tried so far, and we will HELP you, but we WILL NOT write the script FOR YOU.
There are THOUSANDS of VERY easily found bash scripting tutorials you can find with a Google search, that have examples on how to check for file/directory existing. Start there.
You've been registered here for two years now...writing a script should be something you can easily do. As others have said, post what you've written/tried so far, and we will HELP you, but we WILL NOT write the script FOR YOU.
There are THOUSANDS of VERY easily found bash scripting tutorials you can find with a Google search, that have examples on how to check for file/directory existing. Start there.
not cutting you down, but look at the total number of posts he has. not many. my guess is he registered 2 years ago and asked a few questions. he might have been away from linux in general for a long time and is now faced with a new linux question again. i for one have been using linux on and off for over a decade, yet only last year did i start to learn basic bash scripting.
this to me does sound a bit like homework though. thus my response. this could be handled via either rsync, or a simple f -! "foo" but will not know until the OP posts some kind of attempt so we have a better idea of exactly what he wants to accomplish and why.
1. please use code tags for posting code https://www.linuxquestions.org/quest...do=bbcode#code
2. there should be no space between '#' & '!/bin/bash'
3. all that does is declare/define a fn; it needs to be called to do something eg
Code:
#!/bin/bash
# optionally, add this line to debug
set -xv
# declare fn
function blah
{
.
.
.
}
# ... and call it
blah
...additionally:
4. directory creation is not anchored anywhere, meaning it will execute 'mkdir' wherever the current processes current working directory is,
5. it should explicitly set an umask to avoid perm probs,
6. one shouldn't use mixed case unless unavoidable.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.