Help with command in ksh script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with command in ksh script
# 1  
Old 02-10-2012
Help with command in ksh script

I want my script to check directories and files within the directories older than 7days lold and remove them but the script only removes the directories older than 7 days.

Code:
find home/prod/clt/nal/inb -mtime +7 -exec rm -rf {} \;

The inb contains multiple directories that contain multiple files.
I'm not sure why the find command does not work as I intended.Smilie
# 2  
Old 02-10-2012
find is recursive, so your rm doesn't have to be.

You shouldn't depend on the modification time of the directory anyway, since I think that relates to when files were created/deleted, not when files inside it were modified.

So search for files only find /path -type f and rm without the -r.

If you really need to, you can do another pass to remove empty directories afterwards.
This User Gave Thanks to Corona688 For This Post:
# 3  
Old 02-10-2012
Another thing you can try is to add the -depth switch. It'll force the find comand to test files before directories. The effect being that if a directory contains files that do not meet the criteria, then the files that do will be removed, but the directory will not.

From the man page:

Code:
-depth Process each directory's contents before the directory itself.

Hope this helps.
This User Gave Thanks to in2nix4life For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help with ksh Script not resolving '@' in ls command

Hi all, We've been trying to find a way to get a command to work within a ksh with no success. We are attempting to list various files with different hlq's like this ls $FileDir/dir/subdir/${triggers} The $FileDir is set in the script. The $triggers resolves to... (11 Replies)
Discussion started by: Grueben
11 Replies

2. Shell Programming and Scripting

ksh script find command not printing any results

Hello, Hitting a wall on this one. When at the command prompt it works fine: # find /home/testuser -name 'PAINT*canvasON.txt' /home/testuser/PAINT_canvasON.txt # pwd /home/testuser # ls -l PAINT*canvasON.txt -rw-r--r-- 1 root user 23 Feb 07 02:58 PAINT_canvasON.txt... (2 Replies)
Discussion started by: seekryts15
2 Replies

3. Shell Programming and Scripting

KSH Script to Execute command from specific column in file

Hi Unix Experts,Team I have a file (say comand_file.prm), The file has a command specified in column 6 (say "./execute_script.sh"). I want to execute this command in my script. I am writing a KSH script to achieve this. Could you please assist me with this. (6 Replies)
Discussion started by: Jeevanm
6 Replies

4. Shell Programming and Scripting

AIX .ksh script freezes when using the mail -s command

Hello I am trying to send an email when a .KSH script is run on an AIX Machine. This email will only include a subject line that is made up of variables from within the script, and is as follows: CURRENT_DATE=`date +%Y%m%d` TIME=`date` ADMIN="myname@domain.com" date block () { ... (4 Replies)
Discussion started by: jimbojames
4 Replies

5. UNIX for Advanced & Expert Users

Running ksh script from command line

Hi. I have a ksh script I want to run, but I'm connecting through a telnet and I don't want to FTP the scripts itself. is there a way of running the script from command line ? like ksh "The script itself..." Thanks, Ramon (4 Replies)
Discussion started by: mellowcandle
4 Replies

6. Shell Programming and Scripting

problem with KSH script: command line args

Hi I am executing a KSH script by passing command line arguments example: Red Green Dark Red Blue when I am splitting the arguments by using " "(Space) as delimiter But the colour Dark Red is a single parameter. But it is getting splitted in between How to avoid this. Please help Also... (4 Replies)
Discussion started by: hemanth424
4 Replies

7. Shell Programming and Scripting

KSH script: piping passes command-line arguments

Dear forum I have the following small script: #!/bin/ksh echo -e "abba-o" | awk -F '-' '{ print $2 }' | cut -b 1It needs to be ksh.. in bash I don't have this problem. If I run this on opensuse 10.2 I get this as output: e If I run this on suse enterprise 10 sp2 then I get this: o ... (1 Reply)
Discussion started by: gemtry
1 Replies

8. Shell Programming and Scripting

ssh command in ksh script encounters permission error

I've created a script and copied it to another server and try to execute it at the same time but I'm getting a permission error. I'm logged on as root and I gave the file 777 permission when I created it, but I can't run it remotely via ssh command because of permission issue. Any ideas? ... (5 Replies)
Discussion started by: pdtak
5 Replies

9. Shell Programming and Scripting

Command taken away from ksh script

Hi, Any help or suggestions would be most appreciated. I am having problems in the latter end of this ksh script where I will be checking two files. If they exist do nothing otherwise I need to reinitialize the database which resides on o/s Aix 5.3. The problem I am facing is when the reinit... (2 Replies)
Discussion started by: hgjdv
2 Replies

10. Shell Programming and Scripting

#!/usr/bin/ksh Command Interpreter in a sh script

Hi, I have a developer that is trying to start a script with sh "scriptname". In the script, he is specifying #!/usr/bin/ksh as the command interpreter. For some reason sh is ignoring the #!/usr/bin/ksh. We are running Solaris 8. Does anyone have any ideas what could be causing this? Here... (3 Replies)
Discussion started by: ckeith79
3 Replies
Login or Register to Ask a Question