Sponsored Content
Full Discussion: move file by year/mouth
Top Forums Shell Programming and Scripting move file by year/mouth Post 302227324 by mmm951 on Thursday 21st of August 2008 04:05:22 AM
Old 08-21-2008
I write script do this job.
any one has better advise!?

Code:
#!/bin/ksh
sdir=/tmp/mars
sedarg=s/[0-9][0-9]:[0-9][0-9]/`date +%Y`/g
mouth=0
while [ $mouth -le 11 ]
do
 mouth=`expr $mouth + 1`
 for yeardir in `ls -lt $sdir | sed -e $sedarg | grep ^- |awk '{print $8}' |uniq`
   do
	if [[ -d $sdir/$yeardir/$mouth ]] ;then
		echo $sdir/$yeardir/$mouth is exist
	else 
		mkdir -p $sdir/$yeardir/$mouth
		echo create $sdir/$yeardir/$mouth ok!!
	fi
   done
 done

#move file
ls -lt $sdir | sed -e $sedarg | grep ^- |awk '{print $6"\t"$8"\t"$NF}'  >$$.out
exec < $$.out
while read F_MOUTH F_YEAR FILE_NAME
do
  case "$F_MOUTH" in
        Jan) mv $sdir/$FILE_NAME $sdir/$F_YEAR/1;;
        Feb) mv $sdir/$FILE_NAME $sdir/$F_YEAR/2;;
        Mar) mv $sdir/$FILE_NAME $sdir/$F_YEAR/3;;
        Apr) mv $sdir/$FILE_NAME $sdir/$F_YEAR/4;;
        May) mv $sdir/$FILE_NAME $sdir/$F_YEAR/5;;
        Jun) mv $sdir/$FILE_NAME $sdir/$F_YEAR/6;;
        Jul) mv $sdir/$FILE_NAME $sdir/$F_YEAR/7;;
        Aug) mv $sdir/$FILE_NAME $sdir/$F_YEAR/8;;
        Sep) mv $sdir/$FILE_NAME $sdir/$F_YEAR/9;;
        Oct) mv $sdir/$FILE_NAME $sdir/$F_YEAR/10;;
        Nov) mv $sdir/$FILE_NAME $sdir/$F_YEAR/11;;
        Dec) mv $sdir/$FILE_NAME $sdir/$F_YEAR/12;;
  esac
done
rm $$.out


Last edited by mmm951; 08-21-2008 at 08:24 AM..
 

7 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How do i get the year of the file

When i use, 'ls -ltr' I only see the month and day (timestamp) of the file. How do i see the year also. Thanks and Regards, Ram (1 Reply)
Discussion started by: ramky79
1 Replies

2. UNIX for Dummies Questions & Answers

Move files based on year

I have a directory which has crores of files since from 2003. I want to move only the 2003 files to another directory. Please help in doing this. Thanks (1 Reply)
Discussion started by: IHK
1 Replies

3. Shell Programming and Scripting

Move files based on year of creation

Hi All, I have a directory which has crores of files since from 2003 till now. I want to move only the 2003 files to another directory. Please help. Thanks (2 Replies)
Discussion started by: IHK
2 Replies

4. UNIX for Dummies Questions & Answers

Move files based on year

Hi All, I have a directory which has crores of files since from 2003. I want to move ony the 2003 files to another directory. Please help (9 Replies)
Discussion started by: IHK
9 Replies

5. UNIX for Dummies Questions & Answers

move all 2008 year's file to destination directory

I am trying to move file created/modified in 2008 year to <new directory>. But trapped badly in Xargs {}. Looks like mv is not getting destination file properly. It assumes source file s to be destination directory n gives me erroir. "Target must be a directory" Run- #/home/mktrisk: find... (4 Replies)
Discussion started by: kedar.mehta
4 Replies

6. Shell Programming and Scripting

File created year

Hi I need to get the File creation date (MM,DD,YYYY) using ls -ltr am getting only Month and Day only, I need year also when the file is modified. Thanks (3 Replies)
Discussion started by: KiranKumarKarre
3 Replies

7. Red Hat

Move files of a certain year to other directory

Hi all, I have a massive amount of recording files in .WAV format stored in a directory, files dating back to 2006. It is a huge amount of files as Linux cannot even do a listing of it all, it states: "argument list too long" What I would like to do is the following: Find all the files of... (6 Replies)
Discussion started by: codenjanod
6 Replies
asn1_parser2tree(3)						     libtasn1						       asn1_parser2tree(3)

NAME
asn1_parser2tree - function used to start the parse algorithm. SYNOPSIS
#include <libtasn1.h> asn1_retCode asn1_parser2tree(const char * file_name, ASN1_TYPE * definitions, char * errorDescription); ARGUMENTS
const char * file_name specify the path and the name of file that contains ASN.1 declarations. ASN1_TYPE * definitions return the pointer to the structure created from "file_name" ASN.1 declarations. char * errorDescription return the error description or an empty string if success. DESCRIPTION
Creates the structures needed to manage the definitions included in *FILE_NAME file. RETURNS
ASN1_SUCCESS The file has a correct syntax and every identifier is known. ASN1_ELEMENT_NOT_EMPTY *POINTER not ASN1_TYPE_EMPTY. ASN1_FILE_NOT_FOUND An error occured while opening FILE_NAME. ASN1_SYNTAX_ERROR The syntax is not correct. ASN1_IDENTIFIER_NOT_FOUND In the file there is an identifier that is not defined. ASN1_NAME_TOO_LONG In the file there is an identifier whith more than ASN1_MAX_NAME_SIZE characters. COPYRIGHT
Copyright (C) 2006, 2007, 2008, 2009 Free Software Foundation, Inc.. Copying and distribution of this file, with or without modification, are permitted in any medium without royalty provided the copyright notice and this notice are preserved. SEE ALSO
The full documentation for libtasn1 is maintained as a Texinfo manual. If the info and libtasn1 programs are properly installed at your site, the command info libtasn1 should give you access to the complete manual. libtasn1 2.2 asn1_parser2tree(3)
All times are GMT -4. The time now is 05:44 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy