Sponsored Content
Top Forums Shell Programming and Scripting Shell script to delete specify directory Post 302917870 by ibad_urs on Friday 19th of September 2014 03:17:27 AM
Old 09-19-2014
Shell script to delete specify directory

I have the following directories under "0.0.0.0"
Code:
/scratch/builds/snapshotBuilds/0.0.0.0
drwxr-xr-x+  tested-571
drwxr-xr-x+  tested-576
drwxr-xr-x+  tested-597
drwxr-xr-x+  600
drwxr-xr-x+  601
drwxr-xr-x+  602
drwxr-xr-x+  603
drwxr-xr-x+  tested-604
drwxr-xr-x+  tested-605
drwxr-xr-x+  tested-606
drwxr-xr-x+  tested-608
drwxr-xr-x+  613
drwxr-xr-x+  tested-614
drwxr-xr-x+  617
drwxr-xr-x+  618
drwxr-xr-x+  619
drwxr-xr-x+  620
drwxr-xr-x+  621
drwxr-xr-x+  622
drwxr-xr-x+  623
drwxr-xr-x+  624
drwxr-xr-x+  631
drwxr-xr-x+  632
drwxr-xr-x+  635

And Here is my requirement, please help me to write a shell script i.e.
from the above list, i want to rename directory 621 to tested-621 and the shell script should KEEP (dont not delete) builds 620, tested-621 and 622 and delete rest of the directories before 620 and after 621 (tested-621). Please note, I want to keep all the directories that are starting with tested-xxxx

Could you please help?

---------- Post updated at 12:47 PM ---------- Previous update was at 12:35 PM ----------

I found the following command in the forum:
Code:
find . -type d | awk '!/\.\/tested*/' | xargs -p rm -rf

But this will keep all the directories that are starting with tested* and delete rest all the directories. But, i want to keep all the tested* directories plus keep build+1 and build -1. For example, under "0.0.0.0" directory say build 50 is renamed to tested-50 then Your script should KEEP build 49, tested-50, 51.

Last edited by vbe; 09-19-2014 at 07:32 AM..
 

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(3perl)					 Perl Programmers Reference Guide				    CPANPLUS::Shell(3perl)

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.14.2 2014-09-29 CPANPLUS::Shell(3perl)
All times are GMT -4. The time now is 08:22 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy