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.
@BW-userx......I tried your code and while I did not get any errors, it did not create a folder named with the current date and did not move the file I specified
@BW-userx......I tried your code and while I did not get any errors, it did not create a folder named with the current date and did not move the file I specified
now would be a good time to start posting your code. while telling us your steps in setting it up and running it. all of the wheres and what fors.
I can't believe this is this hard. I tried all code provided and I either got an error or no errors but nothing was created nor moved. I do these steps in command line and get no errors:
1. cd //
2. cd dir1/dir2/foldertomakenewfolder......................folder I want to create a folder named the current date
3. mkdir $(date +%Y%m%d)...............make the directory named the current date locally
A folder was created, being named the current date BUT when trying to do this in a script(which should be like doing it in command line) I get an error. Weird!!!
I can't believe this is this hard. I tried all code provided and I either got an error or no errors but nothing was created nor moved. I do these steps in command line and get no errors:
1. cd //
2. cd dir1/dir2/foldertomakenewfolder folder I want to create a folder named the current date
3. mkdir $(date +%Y%m%d)
A folder was created, being named the current date BUT when trying to do this in a script(which should be like doing it in command line) I get an error. Weird!!!
you need to give better explanations to what you are doing , code and steps taken to run code. showing your work. as if we were actually there watching what you are doing, so this side can better understand what is going on.
I really can't put it any easier than what I gave in my above post..........shouldn't what I do in command line be inserted in a script and executed without error?
I really can't put it any easier than what I gave in my above post..........shouldn't what I do in command line be inserted in a script and executed without error?
what does your code look like now?
did you do this to your file first before you ran it?
Code:
chmod +x filename
./filename
then copy paste your output in your terminal into your next post along with your code in your bash file.
exit <------ I did this to change to the user that has permissions to create a directory
cd //
cd dir1/dir2/dir3/dir4/dir5/audits
mkdir $(date +%Y%m%d)
ok let takes a sip of coffee, and sit back and relax for a second.
why did you change permissions to the files you are looking for?
why are you still doing this command line when @TenTenths and I gave you code to create a BASH script to use?
I can't believe this is this hard. I tried all code provided and I either got an error or no errors but nothing was created nor moved. I do these steps in command line and get no errors:
1. cd //
2. cd dir1/dir2/foldertomakenewfolder......................folder I want to create a folder named the current date
3. mkdir $(date +%Y%m%d)...............make the directory named the current date locally
A folder was created, being named the current date BUT when trying to do this in a script(which should be like doing it in command line) I get an error. Weird!!!
What Error? Exactly.
Are these files always in the same location?
One I have no idea where the files are kept, I have no idea of whatever it is your using to create them. No one needs to know that but you.
ok taking from your first post.
Quote:
I need to be able, from command line to create a folder with just the current date, then copy a file into it. Would can I achieve this? I'm putting this into a script so that this will be done daily. Making the directory in the current folder is not a problem, but copying a file using the 'mv' command into a folder with the current date is.
you want to run a BASH script that creates a directory using the date created as its name. then moving files into said directory. the file types you are wanting to move where discovered later on in the thread, them being of the type, .xlsx
somewhere in this thread I learn you want to only move files
Quote:
I could've sworn I have seen a command that uses -1, meaning less than a day old to use to copy the file into a directory less than a day old but I don't remember it
so to summarize:
have script:
1. create a directory with current date.
2 move .xlsx that are less than one day old files wherever they are into freshly created directory.
steps needed.
1. created dated directory
2. find files that meet criteria.
3. move files into freshly created directory.
Code needed for a BASH sctipt ro be copied and pasted into a fresh file then saved under whatever the user wants to call it, example myfreshscript.
now all the user has to do after changing the paths to meet his needs is,
Code:
#chmod +x myfreshscript
first setting up a test base to make sure it is doing exactly what he wants it to do.
User must first make up dummy directory and put test files within it. Make sure the BASH script leads to that dummy directory that the files are in, then add a path to where he wants the dummy dated directory to go within the script.
cd into a completely different directory that script is in then run it
Code:
./myfreshscript
then make needed changes if any before putting it into the /etc/cron.daily directory using root to do so. then double checking to be sure it is still executable.
@BW-userx.. excellent post, quoting me like a politician LOL!!!! Naw, seriously it is a great post covering everything I asked for. Only instead of all files ending in '.xlsx', I just defined a file which shouldn't harm any of your code. I created a separate BASH script, copied and pasted your code, defined the paths(which I checked several times to be sure they are right), ran the script. No errors BUT no directory created
You will not believe this..oh your code IS correct. I copied and pasted each line of your code in the command line and MANUALLY ran each line.it does EXACTLY what I need it to do. Why in the world will it not run in a script???? This is crazy!!! Yes, the file permissions has been changed to make it an executable
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.