Need help for writing shell script

Discussion in 'Programming/Scripts' started by erez, May 24, 2006.

  1. erez

    erez New Member

    I need some help in writing a shell script, it basically need to delete all my older files , the file name structure is like that :


    · song – constant prefix.
    · 100000732 – 9 digits unique key [per msisdn]
    · 200506114528 – time stamp [DDMMYYHHMISS format]

    The unique key is the same for each play list of specific msisdn.
    The only thing that changes is the timestamp.

    so i need for each unique key (there are more then one) the news file will remain

    Can anyone help me?

  2. EvanCarroll

    EvanCarroll New Member HowtoForge Supporter

    Do you need it in shell? Or can it be scripted in a real language.
  3. erez

    erez New Member

    i need it in a shell
  4. g33k

    g33k New Member HowtoForge Supporter

    >> so i need for each unique key (there are more then one) the news file will remain

    I don't get what exactly you want to do..May be you could have been more clear !!

    Well the following script extracts each field (key and date-time) from the file name..

    ext=".3gp"	#put the file extension here
    for f in *.3gp	#repeats of for each file in the directory	
    	#extract the filename without extension
    	base=`basename $f $ext`
    	echo $base
    	#extract the prefix
    	pref=`echo $base | cut -c 5-13 -`
    	echo $pref
    	#extract date and time
    	dtime=`echo $base | cut -c 14-25 -`
    	echo $dtime
  5. flim

    flim New Member

    I assume you want to remove unused stuff older than X days. Instead of checking the timestamp within the filenames you could just do something like this:

    find /my/directory -name song*3gp -ctime 50 -print| rm -f

    which would delete everything min 50 days old

    You can test that it picks the right files with something like:
    find /my/directory -name song*3gp -ctime 50 -print| ls -l

  6. FosterWest

    FosterWest New Member


Share This Page