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
fdmns(4)						     Kernel Interfaces Manual							  fdmns(4)

NAME
fdmns - contains file domain names and devices DESCRIPTION
The fdmns directory ensures access to file domains by providing symbolic links to every volume in the file domain. The mkfdmn, rmvol, and addvol utilities automatically manage the fdmns directory. Each file domain is described by its own subdirectory within the fdmns direc- tory. Back up the fdmns directory structure regularly using the vdump utility or any other backup utility (dump, tar, cpio). If the contents of the fdmns directory are deleted or corrupted, restore the directory from your most recent backup tape. You must also restore the fdmns directory after installing a new version of the operating system. Always keep a hardcopy record of each file domain and its associated volumes in case a backup copy of the fdmns directory is unavailable. If you have a record, you can reconstruct the fdmns directory structure. The following is a sample fdmns directory: total 2 drwxr-x--- 2 root system 512 Nov 24 18:35 scratch/ drwxr-xr-x 2 root system 512 Nov 24 18:35 usr/ ./scratch: total 0 lrwxr-x--- 1 root system 10 Oct 23 15:13 dsk10c@ -> /dev/disk/dsk10c lrwxr-x--- 1 root system 10 Oct 24 11:33 dsk11c@ -> /dev/disk/dsk11c lrwxr-x--- 1 root system 9 Oct 13 18:29 dsk8c@ -> /dev/disk/dsk8c ./usr: total 0 lrwxr-x--- 1 root system 9 Oct 24 10:52 dsk2g@ -> /dev/disk/dsk2c lrwxr-x--- 1 root system 9 Nov 24 10:35 dsk9c@ -> /dev/disk/dsk9c RESTRICTIONS
Do not remove or modify the contents of this directory. If the fdmns file becomes corrupted, you can no longer access (or mount) any file- set in the file domains. SEE ALSO
advfs(4), vdump(8), mkfdmn(8), vrestore(8), showfdmn(8) fdmns(4)
All times are GMT -4. The time now is 09:47 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy