The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Urgent !!! Shell script to copy files to VSS devalin Shell Programming and Scripting 1 08-20-2007 06:16 AM
find files and copy into a directory balireddy_77 Shell Programming and Scripting 4 04-27-2007 03:38 AM
shell script: deleting files from a directory onlyc Shell Programming and Scripting 1 07-09-2006 06:41 AM
shell script to find files naren_samba2005 Shell Programming and Scripting 2 10-21-2005 05:06 AM
find files with a perticular year of access pradeepmacha UNIX for Advanced & Expert Users 3 07-12-2005 03:31 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-01-2008
manas6 manas6 is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 27
shell script to find and copy the files creted in the year 2006 to another directory

Hi All,

I am new to UNIX. I will be thankful if some one helps me.
I have to write a shell script for one of the requirement.

I have files created from Jan 2006 to March 2008.
My requirement is to write a script in such a way that
1) To find and copy(not Moving) the files created in the year 2006 to another directory(xyz). The shell should automatically create the directory in the currect path.
2) Then the compress the folder(xyz), which contains all the files created in the year 2006.


Thanks in advance.

Regards
manas
  #2 (permalink)  
Old 04-01-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
The regular solution would be find but it's a bit unwieldy, and it is better at relative age (more than 1 year old, etc) than at finding all files from a particular year. I would whip up a quick Perl script for finding the files; the rest should be trivial enough to leave as an exercise for you.

Code:
perl -e 'for $file (<*>) {
  next unless -f $file;
  my @s = stat($file);
  my @d = localtime($s[10]);
  print "$file\n" if $d[5] == 106; } # 1900 + 206 = 2006'
  #3 (permalink)  
Old 04-01-2008
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,508
Code:
ls -l | awk '$8==2006{print $NF}' | xargs -i cp "{}" /destination
works on the current directory only. I leave the rest to you.
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 05:50 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0