Sponsored Content
Top Forums Shell Programming and Scripting Shell script to delete specify directory Post 302919286 by ibad_urs on Tuesday 30th of September 2014 06:26:34 AM
Old 09-30-2014
Here is the

Code:
#!/bin/bash
keep_above=1
keep_below=1
# cleanup - rename selected files and remove others
# Usage: cleanup file_to_rename...
#
# Select a list of all files in the current directory whose names start and
# end with a decimal digit (files with a leading zero in their name will be
# ignored).  Rename each file named as an operand by prefixing it with
# "tested-".  Leave other files in the range:
#    (file_to_rename - $keep_below) <= name <= (file_to_rename + $keep_above)
# for any given operand unchanged.  Remove all other selected files.

IAm=${0##*/}
if [ $# -lt 1 ]
then    printf 'Usage: %s file_to_move...\n' "$IAm" >&2
        exit 1
fi
printf '%s\n' "$@" "EndOfRenameList" [1-9]*[0-9] |
awk -v above="$keep_above" -v below="$keep_below" '
/EndOfRenameList/ {
        eval=1
        next
}
!eval { for(i = $1 - below; i <= ($1 + above); i++)
                keep[i]
                rename[$1]
        next
}
{       if($1 in rename) {
                printf("mv \"%s\" \"tested-%s\"\n", $1, $1)
                delete rename[$1]
        } else if($1 in keep)
                printf("printf \"mv \"%s\" \"0%s\", $1)
                printf("printf \"mv \"%s\" \"0%s\n\"\n", $1)
        else    printf("rm -rf \"%s\"\n", $1)
}
END {   for(i in rename) {
                printf("printf \"File \\\"%s\\\" not found.\\n\" >&2\n", i)
                printf("printf \"ec=2\\n\"\n")
        }
        printf("exit \$ec\n")
}'

 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

shell script which will delete every thing under a directory except a single sub dire

write a shell script which will delete every thing under a directory except a single sub directory (2 Replies)
Discussion started by: alokjyotibal
2 Replies

2. Shell Programming and Scripting

Sheel script to Delete a set of files from a given directory

I have a file <filestodelete> containing names of files to to be deleted from a directory <filesstore>. I want a script file which accptes the <filestodelete> and also the location of the directory(<filestore>) and deletes all files matching. Thanks in Advance.. (3 Replies)
Discussion started by: VardhiniVenkat
3 Replies

3. Shell Programming and Scripting

Linux delete script in sub-directory

Under TEMP folder, it have many sub-folder, example"0015,0016,etc" I need to discovery those file which are 2 days ago in this sub-folder , and list out to investigate, at the end delete all file in those sub folder, only keep the emptu directory. Thanks (4 Replies)
Discussion started by: android
4 Replies

4. Shell Programming and Scripting

Script to delete all something.txt~ file from a directory

There are some files in a directory like a.tx~ , b.txt~,c.txt~. I want to delete all these files inside that directory and sub directory. How can i do this? #!/bin/bash cd thatdirectory ...... rm -rf *~ ...... (7 Replies)
Discussion started by: cola
7 Replies

5. Shell Programming and Scripting

script to delete contents in a directory by date

Hi , I am trying to make a cron job to delete the contents of a directory in a linux environment.The contents created before 2 days should get deleted by this job.Here is what i have written : /usr/bin/find / -name *.log -ctime +2 -exec /bin/rm -f {} \; Is it correct....If not so,please... (9 Replies)
Discussion started by: d8011
9 Replies

6. Shell Programming and Scripting

delete only particular file in directory shell script

Hi, what function do we use to delete only particular file that we want in directory shell script for example I want only to delete test.txt in directory how to do it ? in sh Thank (1 Reply)
Discussion started by: guidely
1 Replies

7. Shell Programming and Scripting

Shell scripting-I need a script which should watch a directory for a file with specific directory

I need a script which should watch a directory for a file with specific directory. If it finds a file in directory, it should search for few specific keyword in the file. if the keyword exists, it should trim string from specific column. The file should be moved to another directory and the a... (8 Replies)
Discussion started by: akashdeepak
8 Replies

8. Shell Programming and Scripting

Script needed to delete to the list of files in a directory based on last created & delete them

Hi My directory structure is as below. dir1, dir2, dir3 I have the list of files to be deleted in the below path as below. /staging/retain_for_2years/Cleanup/log $ ls -lrt total 0 drwxr-xr-x 2 nobody nobody 256 Mar 01 16:15 01-MAR-2015_SPDBS2 drwxr-xr-x 2 root ... (2 Replies)
Discussion started by: prasadn
2 Replies

9. Shell Programming and Scripting

Shell script cannot create directory and move the file to that directory

I have a script, which is checking if file exists and move it to another directory if then mkdir -p ${LOCL_FILES_DIR}/cool_${Today}/monthly mv report_manual_alloc_rpt_A_I_ASSIGNMENT.${Today}*.csv ${LOCL_FILES_DIR}/cool_${Today}/monthly ... (9 Replies)
Discussion started by: digioleg54
9 Replies
CPANPLUS::Shell(3)					User Contributed Perl Documentation					CPANPLUS::Shell(3)

NAME
CPANPLUS::Shell - base class for CPANPLUS shells SYNOPSIS
use CPANPLUS::Shell; # load the shell indicated by your # config -- defaults to # CPANPLUS::Shell::Default use CPANPLUS::Shell qw[Classic] # load CPANPLUS::Shell::Classic; my $ui = CPANPLUS::Shell->new(); my $name = $ui->which; # Find out what shell you loaded $ui->shell; # run the ui shell DESCRIPTION
This module is the generic loading (and base class) for all "CPANPLUS" shells. Through this module you can load any installed "CPANPLUS" shell. Just about all the functionality is provided by the shell that you have loaded, and not by this class (which merely functions as a generic loading class), so please consult the documentation of your shell of choice. BUG REPORTS
Please report bugs or other issues to <bug-cpanplus@rt.cpan.org<gt>. AUTHOR
This module by Jos Boumans <kane@cpan.org>. COPYRIGHT
The CPAN++ interface (of which this module is a part of) is copyright (c) 2001 - 2007, Jos Boumans <kane@cpan.org>. All rights reserved. This library is free software; you may redistribute and/or modify it under the same terms as Perl itself. SEE ALSO
CPANPLUS::Shell::Default, CPANPLUS::Shell::Classic, cpanp perl v5.16.3 2013-05-20 CPANPLUS::Shell(3)
All times are GMT -4. The time now is 07:29 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy