Files between two dates in UNIX


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Files between two dates in UNIX
# 8  
Old 07-02-2014
Thanks for your reply . I already added that exclusion in the command but the above mentioned command is not working.

---------- Post updated at 11:01 PM ---------- Previous update was at 10:57 PM ----------

here is the command which I used.
Code:
find . !-type d -daystart -mtime $(( -1-$(date +%j)+$(date --date '01 Jun' +%j))) ! -mtime $(( -$(date +%j)+$(date --date '30 Jun' +%j)))


Last edited by Franklin52; 07-02-2014 at 10:58 AM.. Reason: Please use code tags
# 9  
Old 07-02-2014
Again if something dosn't work please show the error returned eg:

Code:
-bash: !-type: event not found

Here you are missing a space between ! and -type
# 10  
Old 07-02-2014
sorry it is typo mistake ,I did that. Here is the command output

Code:
]find . ! -type d -daystart -mtime $(( -1-$(date +%j)+$(date --date '01 Jun' +%j))) ! -mtime $(( -$(date +%j)+$(date --date '30 Ju>
date: illegal option -- -
Usage: date [-u] [+Field Descriptors]
ksh:  -1-182+: more tokens expected

---------- Post updated at 11:13 PM ---------- Previous update was at 11:12 PM ----------

More over in the example he is not considering the year. I want to consider year also

Last edited by Franklin52; 07-02-2014 at 10:58 AM.. Reason: Please use code tags
# 11  
Old 07-02-2014
Your date command dosent support the --date option. The is a GNU extension and requires GNU date (aka linux).

You will probably have to revert to the touching of files method. You mentioned you don't have write access on the server, how about /tmp usually all users can write files there?
# 12  
Old 07-02-2014
Unable to SFTP files from remote server

Code:
sftp> binary
Invalid command.
sftp> touch -t 201407020000.01 start
Invalid command.
sftp> touch -t 201407022359.59 end
Invalid command.
sftp> find . ! -type d -newer start ! -newer end -exec mget {} \;
Invalid command.
sftp> rm start end
Couldn't delete file: No such file or directory
sftp> bye


Last edited by Franklin52; 07-02-2014 at 10:58 AM.. Reason: Please use code tags
# 13  
Old 07-02-2014
Well, none of those are sftp commands. While sftp does have some commands with the same name & behaviour as unix commands, it's not a remote shell.

You'd need to use something like ssh (and maybe scp) instead.
# 14  
Old 07-02-2014
Quote:
If you were to consider the problem as a manual tasks, break it down into smaller chunks and logically work out the simplest steps you can.
What you haven't said is that you are connecting with sftp and have no other access.

I have a few questions:-
  • Can you ssh connect without a password?
  • Is an ssh session allowed to create files in /tmp?
If you can, then create a script on the remote server to do this:-
  1. Identify the files
  2. Use sftp to send the files from the remote server to your local server.
If you cannont sftp to your local server, you could code the script to:-
  1. Identify the files to be transferred
  2. Bundle them up with tar to a single file with a fixed name
  3. Disconnect the ssh session (i.e. exit the remote script)
  4. Connect with sftp from your local server and get (and delete) the fixed name file
  5. Extract the contents to your desired location


If you cannot ssh you will need three main steps (in my opinion):-
  1. Connect with sftp and get a file listing, capturing it to a local file and disconnect
  2. Locally process the list to decide which files to collect
  3. Connect again with sftp getting the files you have identified.
Does this get you any further?



Robin
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Need to Move files of different dates

Hi, Currently I'm moving the files based on date like below. "mv *20150901* backup_folder" - Limitation: can move only 1 day files to backup folder. I want to move the files of different dates like 20150901,02, 03, 04..... Is there any single command to do it. Thanks in advance!! (2 Replies)
Discussion started by: prakashs1218
2 Replies

2. Shell Programming and Scripting

Deleting the files between particular dates

Hi Please help me for the below task. In my home directory if I run ls -l command, it lists all the files, here I want to delete files created from January 2014 to Aug 2014...but I need to keep the files which are created after September 01 2014. Thanks Siva (3 Replies)
Discussion started by: kumar85shiv
3 Replies

3. UNIX for Advanced & Expert Users

Find all files other than first two files dates & last file date for month

Hi All, I need to find all files other than first two files dates & last file date for month and month/year wise list. lets say there are following files in directory Mar 19 2012 c.txt Mar 19 2012 cc.txt Mar 21 2012 d.txt Mar 22 2012 f.txt Mar 24 2012 h.txt Mar 25 2012 w.txt Feb 12... (16 Replies)
Discussion started by: Makarand Dodmis
16 Replies

4. AIX

Copy files for particular dates

Hi, I need to copy particular date files from one directory to another. For example, I have thousands of files in /home/usr From this I need to copy only particular date files (each date contains thousand number of files) to some directory of another server. Could anyone please help me... (3 Replies)
Discussion started by: teddy2882
3 Replies

5. Shell Programming and Scripting

Compare 2 dates in unix

I have 2 variables in my script like this $v_last_update_date1 = 08/18/2009 08:41:17 $v_last_update_date2 = 08/18/2009 08:30:17 Now I want to comapre with greater than if then go forward else error and exit out I am getting unknown test operator error Can anyone advise (1 Reply)
Discussion started by: veeru
1 Replies

6. UNIX for Dummies Questions & Answers

UNIX Dates

Hey guys. I need to manipulate the system date to move forward a day. So, if the system date was 02/14/08, I need the 'new' date to be 02/15/08 so my script will look for the date of 02/15/08. The thing is the file I will be looking for always has the date of the next day. Any ideas, ... (9 Replies)
Discussion started by: ndoggy020
9 Replies

7. UNIX for Dummies Questions & Answers

files between any two given dates

Can any one help me in getting all the files between any two given dates.. (8 Replies)
Discussion started by: thanuman
8 Replies

8. UNIX for Dummies Questions & Answers

Files and dates

Hello all. I am trying to do a file listing on a particular directory by date. I need to list the files and their directories that have a timestamp between Dec-1-2006 and Jan-1-2007. Any help would be greatly appreciated. (1 Reply)
Discussion started by: mastachef
1 Replies

9. UNIX for Dummies Questions & Answers

Need help with Unix dates

I'm very new to Unix, so forgive me for what will probably be a very quick fix. I have the following in a ksh script. Its purpose is to return yesterday's date. The $DAY part is coming back with a '2' but I need it to return as '02'. How can I do that? date '+%b %d %Y' | { read MONTH DAY... (4 Replies)
Discussion started by: ssmiths001
4 Replies

10. UNIX for Dummies Questions & Answers

Unix dates

How can I use the date function to get the following format? Nov 18 I've tried date +%b%d but I get it in this format: Nov18 with no space. (1 Reply)
Discussion started by: ssmiths001
1 Replies
Login or Register to Ask a Question