shell script to find and copy the files creted in the year 2006 to another directory


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting shell script to find and copy the files creted in the year 2006 to another directory
# 1  
Old 04-01-2008
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  
Old 04-01-2008
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  
Old 04-01-2008
Code:
ls -l | awk '$8==2006{print $NF}' | xargs -i cp "{}" /destination

works on the current directory only. I leave the rest to you.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script to find the GB files in /tmp directory in remote server

Hi, i need help on shell scripting. Main intention of the script is step 1: ssh to remote server Step 2: cd /tmp in remote server Step 3: in tmp i want to grep only files and directories which are in GB sizes All the servers list file is - tmpsrv.txt vi tmpsrv.txt ... (17 Replies)
Discussion started by: kumar85shiv
17 Replies

2. Shell Programming and Scripting

Shell script to find and replace contents of files in directory

Hi all This is my first post. Please bear with me with all my mistakes. I started learning shell since couple of days now and this might be quite basic for all, i want to search for files in a directory containing specific string and replace it with new string. The code i wrote is quite bulky... (2 Replies)
Discussion started by: theprogrammer
2 Replies

3. Shell Programming and Scripting

Find and copy these files to particular directory

RedHat Enterprise Linux 5.4 I have some files with the extension .cdp in several directories in various mountpoints(filesystems) . I would like to find and copy all these files into a single directory /u03/diagnore/data. How can I do this ? (3 Replies)
Discussion started by: kraljic
3 Replies

4. Linux

Find MSWord doc Files by Year and then Copy

I need to be able to find all *.doc files by year last modified and then perform an action such as copy to folder: /documents/2011 the 'find' command seems to show the path but not the full file details, which includes the date modified as the ls command does. I got this far with ls, but have... (2 Replies)
Discussion started by: jamarsh
2 Replies

5. Shell Programming and Scripting

Need a shell script which takes two inputs and copy the files from one directory to other

Hi, I am using solari 10 OS which is having bash shell. I need a shell script which takes user home directory and name of the file or directory as a input and based on that copy the files accordingly to the other directory. example:I hava a machine1 which is having some files in a... (8 Replies)
Discussion started by: muraliinfy04
8 Replies

6. Shell Programming and Scripting

Script to Poll Directory and Copy files

Hi all, I'm looking for a script to poll a specified directory and copy new files to another location. The script should only copy new files so, I based on mtime I guess? Can anyone point me in the right direction of a script which could do this? My scripting skills aren't too bad, but... (1 Reply)
Discussion started by: JayC89
1 Replies

7. Shell Programming and Scripting

Delete all the files and subdirectories for the year 2006

Hi I have lot of files and subdirectories inside a directory which are created in the years 2006, 2007, 2008, 2009 and 2010. I want to delete all the files and subdirectories belonging to the year 2006 alone. How can I do that ? (5 Replies)
Discussion started by: samsungsamsung
5 Replies

8. UNIX for Dummies Questions & Answers

How to find and copy files from one directory to another

Ok i have three directories Destination - /u/dir1 (has subdirectories dir2 which also has subdirectory dir3) Source1 - /u/test/files/dir1/dir2/dir3 Source2 - /u/out/images/dir1/dir2/dir3 What i would like to do is copy everything from Source1 and Source2 into the Destination directory.... (3 Replies)
Discussion started by: ziggy25
3 Replies

9. UNIX for Dummies Questions & Answers

Find & Copy Selected files to another Directory

I am wanting to find files within a directory that are over a certain number of days old and copy them to another directory. And unfortunately not having much luck.......is someone able to help. Would also like to add that there are literally thousands of files that I am wanting to copy in one... (3 Replies)
Discussion started by: hellfyre
3 Replies

10. Shell Programming and Scripting

find files and copy into a directory

hi all, can u please help me in finding all ksh file in directory and including all subdirectories and then copy those files into another directory. thanks in advance -bali (4 Replies)
Discussion started by: balireddy_77
4 Replies
Login or Register to Ask a Question