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

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.2 2012-10-11 CPANPLUS::Shell(3pm)
All times are GMT -4. The time now is 03:10 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy