Sponsored Content
Top Forums Shell Programming and Scripting Shell script to delete specify directory Post 302918152 by ibad_urs on Monday 22nd of September 2014 07:00:07 AM
Old 09-22-2014
Don Cragun,

Thanks for the help, but your code is removing all directories Smilie
Please find the output and FYI, I am unsing Linux 6, please advise.
Code:
bash-4.1$ ls -lrt
total 64
-rw-r--r-- 1 ibshaik dba   51 Sep 22 02:11 devicesinfo
-rw-r--r-- 1 ibshaik dba   12 Sep 22 02:26 renamebuild
-rwxr-xr-x 1 ibshaik dba 1369 Sep 22 02:27 cleanup.sh
drwxr-xr-x 2 ibshaik dba 4096 Sep 22 02:28 tested-111
drwxr-xr-x 2 ibshaik dba 4096 Sep 22 03:24 555
drwxr-xr-x 2 ibshaik dba 4096 Sep 22 03:24 444
drwxr-xr-x 2 ibshaik dba 4096 Sep 22 03:24 411
drwxr-xr-x 2 ibshaik dba 4096 Sep 22 03:24 333
drwxr-xr-x 2 ibshaik dba 4096 Sep 22 03:24 311
drwxr-xr-x 2 ibshaik dba 4096 Sep 22 03:24 222
drwxr-xr-x 2 ibshaik dba 4096 Sep 22 03:24 211
drwxr-xr-x 2 ibshaik dba 4096 Sep 22 03:24 121
drwxr-xr-x 2 ibshaik dba 4096 Sep 22 03:24 111
drwxr-xr-x 2 ibshaik dba 4096 Sep 22 03:25 0456
drwxr-xr-x 2 ibshaik dba 4096 Sep 22 03:25 0234
drwxr-xr-x 2 ibshaik dba 4096 Sep 22 03:25 0111
bash-4.1$
bash-4.1$ cat renamebuild
111 222 333
bash-4.1$ ./cleanup.sh renamebuild
awk: cmd. line:21: warning: escape sequence `\$' treated as plain `$'
+ rm -rf 111
+ rm -rf 121
+ rm -rf 211
+ rm -rf 222
+ rm -rf 311
+ rm -rf 333
+ rm -rf 411
+ rm -rf 444
+ rm -rf 555
+ printf 'File "renamebuild" not found.\n'
File "renamebuild" not found.
+ printf 'ec=2\n'
ec=2
+ exit
bash-4.1$ ls -lrt
total 28
-rw-r--r-- 1 ibshaik dba   51 Sep 22 02:11 devicesinfo
-rw-r--r-- 1 ibshaik dba   12 Sep 22 02:26 renamebuild
-rwxr-xr-x 1 ibshaik dba 1369 Sep 22 02:27 cleanup.sh
drwxr-xr-x 2 ibshaik dba 4096 Sep 22 02:28 tested-111
drwxr-xr-x 2 ibshaik dba 4096 Sep 22 03:25 0456
drwxr-xr-x 2 ibshaik dba 4096 Sep 22 03:25 0234
drwxr-xr-x 2 ibshaik dba 4096 Sep 22 03:25 0111

 

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
DBS-EDIT-PATCH(1)						Debian Build System						 DBS-EDIT-PATCH(1)

NAME
dbs-edit-patch - Edit a DBS patch SYNOPSIS
dbs-edit-patch [options] patch dbs-edit-patch -h|--help DESCRIPTION
dbs-edit-patch is script to generate or modify patches for Debian source-packages in DBS format. WARNING
dbs is deprecated, please switch to the `3.0 (quilt)' Debian source package format instead. See http://wiki.debian.org/Projects/Deb- Src3.0#FAQ for a short guide how to do it. OPTIONS
-h, --help Show summary of options. -t dir, --tmpdir=dir Directory for the temporary files, default is /tmp or if set $TMP. -s dir, --sourcedir=dir Top level directory of the debian-package source-tree, default is the present working directory. -P dir, --sourcepatchdir=dir Directory containing upstream patches. -T dir, --sourcetardir=dir Directory containing the upstream tarball. -p level, --strip=level Striplevel -p of patch (Option -p of diff(1)), accepted values are 0 and 1, default is 0. ENVIRONMENT VARIABLES
TMP Sets the directory for the temporary files, can be overridden with -t dir. debian/vars dbs-edit-patch will automatically use variables defined in the optional debian/vars file. When a file debian/vars.in exists and debian/vars either does not exist or is older than any of the following files: debian/vars.in, debian/changelog, debian/rules or debian/control, then dbs-edit-patch will try updating the vars file by running the following command make -f debian/rules -W debian/vars.in debian/vars EXAMPLES
Edit the 021_debian patch of Heimdal: ~/heimdal-0.3d> dbs-edit-patch -t/tmp 021_debian Extracting source heimdal-0.3d.tar.gz ... successful. Applying patch 001_replay ... successful. etc. Copying heimdal-0.3d to heimdal-0.3d-old ... successful. Applying patch 021_debian ... successful. Edit files under /tmp/021_debian/heimdal-0.3d as required, then put a short description into /tmp/021_debian/patch-description if desired, and finally execute /tmp/021_debian/dbs-update-patch to save the results. Technical note: dbs-edit-patch extracts all patches before 021_debian into /tmp/021_debian/heimdal-0.3d, copies the result to /tmp/021_debian/heimdal-0.3d-old, and applies the last patch 021_debian (if it exists). Also, it creates a shell script which will create the diff between the old and new directories: ~/heimdal-0.3d> ls -la /tmp/021_debian total 12 -rwxr-xr-x 1 bam users 112 Jan 31 13:31 dbs-update-patch* -rw-r--r-- 1 bam users 0 Jan 31 13:31 patch-description drwxr-xr-x 14 bam users 4096 Jan 31 13:31 heimdal-0.3d/ drwxr-xr-x 14 bam users 4096 Jan 31 13:31 heimdal-0.3d-old/ drwxr-xr-x 5 bam users 4096 Jan 31 13:31 .stampdir/ ~/heimdal-0.3d> cat /tmp/021_debian/dbs-update-patch #!/bin/sh -e cd "/tmp/021_debian" HOOK_DIR="/usr/src/heimdal/debian/dbs-hooks" test -d "$HOOK_DIR" && run-parts "$HOOK_DIR" --arg update-patch-prediff find -name "*.bak" -print0 | xargs -0 --no-run-if-empty rm find -name "*~" -print0 | xargs -0 --no-run-if-empty rm : > new_patch test ! -e patch-description || cp patch-description new_patch diff -ruN heimdal-0.3d-old heimdal-0.3d >> new_patch || test $? -eq 1 mv new_patch /usr/src/heimdal/debian/patches/021_debian test -d "$HOOK_DIR" && run-parts "$HOOK_DIR" --arg update-patch-postdiff SEE ALSO
diff(1), dbs(7), /usr/share/doc/dbs/ AUTHOR
DBS was written by Adam Heath, modified by Ben Collins, modified and packaged for Debian by Brian May. This manpage was generated by Andreas Metzler and modified by Robert Luberda. Debian February 15th, 2011 DBS-EDIT-PATCH(1)
All times are GMT -4. The time now is 03:51 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy