Linux / UNIX Tech Support Forum
This is a discussion on Save every fifth file within the Shell scripting forums, part of the Development/Scripting category; Hi ! Never done any scripting in Linux , so here is my problem. I need to have a script ...
|
|||||||
| Shell scripting You can discuss the shell scripting, request shell scripts and scripting techniques |
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
Hi !
Never done any scripting in Linux , so here is my problem. I need to have a script that saves every fifth file in a directory, but deletes the other ones. A bonus would be if the calling of the script would 'set' the value of which files that I want to save (fifth , tenth , second ......) Sounds like an easy one for you here |
| Sponsored Links | ||
|
|
|
|||
|
Nice one !
I had to change it a little bit so it saves every fifth , not deletes every fifth as it did in your script One problem that I still have is that when it creates the list it processes , the list is not sorted correct. Is there anyway to use the SORT command when using the FIND command in your script ? \Mats |
|
|||
|
It works...
I also added so that only files that starts with Sqr is processed. ThanX rockdalinux !!! here is the script as of now : #!/bin/bash OUT="/tmp/list.$$" c=0 pos=$1 # file position dir=$2 # directory name [ $# -ne 2 ] && exit 1 || : find ${dir} -name Sqr\* -type f | sort -o $OUT while read line do (( c++ )) if [ $c -eq $pos ]; then echo "Keeping $line at $c pos..." # echo "/bin/rm $line" c=0 # reset else echo "Deleting $line at $c pos..." echo "/bin/rm $line" /bin/rm $line fi done < $OUT /bin/rm $OUT |
![]() |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) |
|
| Thread Tools | |
| Display Modes | |
|
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| shell script to search specific file from txt file inside zip file and extract it | aasif.shaikh | Shell scripting | 2 | 31-05-2008 06:44 PM |
| Read arguments from a file and pass them to binary file | AHJ | Shell scripting | 1 | 31-10-2007 06:04 PM |
| wget url marked 'save target-as' | sasuhaib | The Hangout | 0 | 14-09-2007 11:17 AM |
| How to save history of a hung terminal | ricc | Linux software | 2 | 20-06-2006 12:21 AM |