Create Year directory, date subdirectory and archive the file
Hi,
After checking all the UNIX threads, I am able to come up with a solution so far. I am working on a shell script where it moves the files to a certain directory. The conditions to check are
1) Check if the file exists in the current directory.
2) Check if the destination directory exists.
3) If the destination directory exists, then create a Year sub directory under it. If the Year sub directory already exists, then skip to the next step.
4) If the Year sub directory exists, then check if the Date sub directory exists. If it exists, move the file else create the sub directory and move it.
I did work on the script and it is erroring out. I was wondering if this is the right way to do it or is there is a better way to do it.
Well, there are a few things in Your script that I find a bit strange. Do You want to call this script for each file You want to process? Why do You want nanoseconds if they are always static? Don't You just want to check for existence of a file? And there are a few other syntax errors as well (for example DIR is not defined) and some things will work with absolute paths but not relative.
Anyway, strip off some stuff (to make it shorter) and get to the essence of if, try the following. Unless it is important to know if a directory exist or not, just create it when You need it. An example:
Hi there,
Here is what I currently have and trying to come up with a logic to automatically append logs to a respective year file. The log files might get generated everyday or any other day, irrespective of which I want to copy all of the logs for that year into one file /tmp/<year>.log and then... (4 Replies)
Hi all,
i have a folder, with tons of files containing as following,
on /my/folder/jobs/
some_name_2016-01-17-22-38-58_some name_0_0.zip.done
some_name_2016-01-17-22-40-30_some name_0_0.zip.done
some_name_2016-01-17-22-48-50_some name_0_0.zip.done
and these can be lots of similar files,... (6 Replies)
Hi All,
My directory structure is like
Directory1
SubDirectory1
SubDirectory2
SubDirectory3
I have main directories and subdirectories underneath. I want to write a shell script where I will be passing file name as a parameter, Now I want to find all the files in Directory1... (19 Replies)
Hi Everyone!
Looking for some help with a script that will take all files in any given root folder (which are not already in a folder) and put them into separate folders with the name of each given file.
Any ideas?
Thank you! (1 Reply)
Suppose i have a word "mail".
I have to search this word in all files inside a directory and it's sub-directories.
It will also search in all hidden directory and sub-directories.
If it finds this word in any file it will list that file.
How can i do this with perl/ruby/awk/sed/bash or... (9 Replies)
Hi ,
I am trying to write something to find the size of particular type of files in a directory & it's subdirectory and sum the size .. These types of file are found at directory level or its subdirectories level ..
#!/bin/ksh
FNAME='.pdf'
S_PATH=/abc/def/xyz
find $S_PATH -exec ls -lad... (4 Replies)
hi all,
here is the description to my problem.
input parameters: $date1 & $date2
based on the range i need to select the archived files from the archived directory and moved them in to working directory.
can u please help me in writing the code to select the multiple files based on the... (3 Replies)
I am adding some individual files to a tar archive and would like them to be added to the archive without any directory hierarchy, even though the files themselves exist in levels of hierarchy. Unfortunately, tar seems to always preserve the directory hierarchy when it adds the files.
Here is... (2 Replies)
Hi,
I have written one script to calculate total space of all file in one directory, ignoring subdirectory, it works fine.
Now, I've been trying to calculate all files which includes files in any subdirectories.
I use recursive function to do this, but it can work only if there is only one... (4 Replies)