shell to script to remove directory


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting shell to script to remove directory
# 1  
Old 09-18-2011
shell to script to remove directory

Hello All

I want to delete the directory in my tree structure . all the filenames like this

dd-mm-yyyy

Example

30-01-2011
31-01-2011
01-02-2011

I want to grep the latest last four days created directorey by not using the find command . how do i do that ?
# 2  
Old 09-18-2011
test below code without " |sh" first

Code:
day=$(date -d " -4 days"  +%Y%m%d)
ls *2011 |awk -v d=$day -F "-" '$3 $2 $1 < d {print "rm", $0}'  |sh

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. Programming

Cant remove directory on bash script

hi all, this is my script and as you can see in the screenshot i attach its not deleting the directory in the source folder #!/bin/bash cd /vol/cha-work/_ARCHIVE/to_be_archived/audio/robert_test temp=/mnt/robert_test/temp dest=/vol/cha-archive/audio echo "is this archive for an... (2 Replies)
Discussion started by: robertkwild
2 Replies

3. Shell Programming and Scripting

Moving Files one directory to another directory shell script

Hi, Could you please assist how to move the gz files which are older than the 90 days from one folder to another folder ,before that it need to check the file system named "nfs" if size is less than 90 or not. If size is above 90 then it shouldn't perform file move and exit the script throwing... (4 Replies)
Discussion started by: venkat918
4 Replies

4. 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

5. UNIX for Dummies Questions & Answers

Script to remove zip files from a directory

Hi Folks, There is a job which generates a .zip files every day at /usr/app/generated directory , now please advise for the script that will delete this zip files permanently.but while deleting it should make sure that it will not delete the last two days recently generated zip files and this... (1 Reply)
Discussion started by: punpun66
1 Replies

6. UNIX for Dummies Questions & Answers

Shell input to remove every second file in a directory

Hey guys, I am looking for simple shell script, so i can remove every second file in a directory. For example in any given directory there are 10.000 files: 0001.jpg 0002.jpg 0003.jpg 0004.jpg 0005.jpg 0006.jpg 0007.jpg 0008.jpg .... 1111.jpg 1112.jpg etc. After running the... (5 Replies)
Discussion started by: alpha_mouse
5 Replies

7. Shell Programming and Scripting

An Issue with the script which used to remove a file from the current directory.

Hello forum members, I am writing a script to two tasks. 1: displaying the list of the files in the current directory. 2: removing the specifed file from the list. I have written a sample script ,so can u please verfiy and correct. echo Enter list of files ls *.txt read textfile rm -f... (3 Replies)
Discussion started by: sivaranga001
3 Replies

8. Shell Programming and Scripting

Remove shell script and its directory

Hi, I have shell script which is located in /opt/Test/test.sh code in test.sh is as follows #!/bin/sh rm -rf /opt/Test exit 0 when I tried to execute the above script from its location, it shows the following error rm: Cannot remove any directory in the path of the... (2 Replies)
Discussion started by: raghu.amilineni
2 Replies

9. Shell Programming and Scripting

remove directory x seconds after script completes

Hi guys, I am working with a script within a Mac OS X package installer. The package installer will run the bash script once the files have been copied/installed. I have a little trouble with the last line of my script causing the package installer to crash once in a while and I have narrowed it... (1 Reply)
Discussion started by: tret
1 Replies

10. Shell Programming and Scripting

Script to remove all empty files within the directory structure?

Hi I need to write a shell script which basically searches for all the empty files within the directory structure, lists them before asking the user to confirm if they would like to delete them. If the user deletes the file then a notice would appear confirming the file is deleted. I've be... (5 Replies)
Discussion started by: cat123
5 Replies
Login or Register to Ask a Question