Sponsored Content
Full Discussion: Help with recursive command
Top Forums Shell Programming and Scripting Help with recursive command Post 302664891 by bluebird13 on Sunday 1st of July 2012 09:40:35 AM
Old 07-01-2012
Help with recursive command

Hi,
I need help with recursive function. This is not a part of any homework or classroom related. I am trying to learn unix and working on a question posted on site. basically i have to create a script which does what rm -r does.
my code so far:

Code:
  1 #!/bin/bash
  2
  3 function recursive () {
  4 if ! [ "$(ls -A "$1" )" ]
  5 then
  6       mv -f $1 ~/deleted
  7 else
  8            cd $1
  9            local files=$(ls -A)
 10            echo $files
 11            for f in $files
 12            do
 13
 14               if [ -d $f ]; then
 15                   removeDir
 16                else
 17                    mv -f $f ~/deleted
 18               fi
 19            done
 20 fi
 21 }
 22 recursive example

problem I face is: either files get deleted or directory gets deleted. How do i fix this.
I need to make sure that dirctory gets deleted along with the files inside it.
thanks in advance

Last edited by Scrutinizer; 07-01-2012 at 10:43 AM.. Reason: code tags instead of quote tags
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

recursive nice value

Hi all, I have a running process that will spawn a large number of perl processes. How can I set that these all get spawned with a low priority nice value? I don't mind if all perl related processes take this level. Note, the executing script is compiled and can not be altered at a code... (1 Reply)
Discussion started by: nhatch
1 Replies

2. UNIX for Advanced & Expert Users

Non recursive find command

Hi, I have question is related to find command. I want to find command should search in current folder only not recursive mode(sub-folders). I found a one way of, find . \( -name success -prune \) -o -name "Rajini*" How ever, my current folder is having lots sub-folders and am not... (7 Replies)
Discussion started by: Nagapandi
7 Replies

3. UNIX for Dummies Questions & Answers

help with recursive copy command

Hi Guys, I am experiencing a problem right now while copying a directory as well as its subdirectories to my target directory. I know this is a very simple UNIX command using cp -R source directory target directory. but unfortunatley while doing this an error comes up on the command line saying... (2 Replies)
Discussion started by: Knowledge_Xfer
2 Replies

4. UNIX for Dummies Questions & Answers

Recursive Permissions???

Is there anyway that I can change permissions on a directory and all its sub-directories and files using one single "chmod" command?? (5 Replies)
Discussion started by: the_red_dove
5 Replies

5. Shell Programming and Scripting

Command to sort directories after a recursive find

find -type d -name "TC_*" | sort That's what I have so far... it finds the appropriate directories and then sorts them. But, when it comes to nested subdirectories, it only sorts relative to the first subdirectory. I want it to sort based on the directory at the end of the path. Does anyone know... (3 Replies)
Discussion started by: crimsondarkn
3 Replies

6. Shell Programming and Scripting

Command running for all recursive files

hi, I have installed ACL(access control list) in my ubuntu box in order to know which all are the users having permissions to read and write the files; If u run the command like; $getfacl /root/ It will give following output: # file: root/ # owner: root # group: root user::rwx... (2 Replies)
Discussion started by: ajaypadvi
2 Replies

7. Solaris

date command, loop/recursive

is it possible to use output of one date command as input of another? I would like to know the date of Monday two weeks ago. so, the idea is that one date command subtracts two weeks, and the other finds the Monday. (2 Replies)
Discussion started by: orange47
2 Replies

8. UNIX for Dummies Questions & Answers

Non Recursive Find Command

Hello Unix Gurus, I am using the following find commands: 1) find Input_Path -name '*.' -exec mv -f {} Outputpath \; 2) find Inputpath -name '*.' -exec cp {} Outputpath \; 3) find Somepath -name '*.' Now the problem is my Unix version does not support maxdepth Option for find... (7 Replies)
Discussion started by: pchegoor
7 Replies

9. UNIX for Dummies Questions & Answers

Help needed - find command for recursive search

Hi All I have a requirement to find the file that are most latest to be modified in each directory. Can somebody help with the command please? E.g of the problem. The directory A is having sub directory which are having subdirectory an so on. I need a command which will find the... (2 Replies)
Discussion started by: sudeep.id
2 Replies

10. Solaris

Command failed for target 'check-recursive' error

Sorry if this is the wrong place for this. I haven't done UNIX Admin in a long time and am trying to update the utilities on a Solaris server so that I can get Apache 2.4.25 installed. I am finding a lot of utilities that are just too far out of date and some versions are no longer supported. So... (0 Replies)
Discussion started by: PJ_Namias
0 Replies
SSI_Parser(3)						User Contributed Perl Documentation					     SSI_Parser(3)

NAME
CGI::SSI_Parser - Implement SSI for Perl CGI SYNOPSIS
use CGI::SSI_Parser; $CGI::SSI_Parser::recursive = 1; fssi($filename); sssi($string); DESCRIPTION
CGI::SSI_Parser is used in CGI scripts for parsing SSI directives in files or string variables, and fully implements the functionality of apache's mod_include module. It is an alternative to famous Apache::SSI modules, but it doesn't require mod_perl. This is an advantage to those who are using public hosting services. There is a disadvantage, however - the module consumes much memory, and I don't recommend using it on heavy-loaded sites (currently it's being used on a site with 10000 hits, and I consider this as a limit). I hope to get rid of this disadvantage by the time the release comes out (currently it's beta). SSI Directives This module supports the same directives as mod_include. For methods listed below but not documented, please see mod_include's online docu- mentation at http://httpd.apache.org/docs/mod/mod_include.html . o config o echo This directive is not fully supported in current version. o exec o fsize o flastmod o include o printenv o set This directive is not supported in current version. o perl This directive is not supported in current version. o if o elif o else o endif These four directives are not supported in current version. Outline Usage First you need to load the CGI::SSI_Parser module: use CGI::SSI_Parser; You need to specify the following when processing of all nested directives is needed (default value - 0): $CGI::SSI_Parser::recursive = 1; To parse file or string you need to use: fssi($filename); sssi($string); The result is printed to STDOUT. TO DO
Full implementation of all SSI directives. Optimize memory consumption. AUTHOR
Vadim Y. Ponomarenko, vp@istc.kiev.ua SEE ALSO
mod_include, perl(1). perl v5.8.0 2001-01-06 SSI_Parser(3)
All times are GMT -4. The time now is 08:38 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy