A way to list directories that contain specific files.
Hi everyone
My issue is this, I need to list all the sub directories in a directory that contains files that have the extension *.log, *.dat and *.out . After reviewing the output i need to delete those directories i do not need. I am running Solaris 10 in a bash shell. I have a script that I believe will list the directories that I was hoping someone here could verify the syntax but I still need a way to delete them without having to do rm -R for each one.
ABC= name of directory
Thanks in advance
Moderator's Comments:
Please use code tags
Last edited by jim mcnamara; 01-13-2015 at 12:04 PM..
Reason: forgot the include script
Hello,
I would like to list the files from all directories that has been modified more than 1 month ago, and whose name is like '*risk*log'.
I think a script like this should work :
ls -R | find -name '*risk*.log' -mtime 30 -type f
But it tells me "no file found" though I can see some.
... (4 Replies)
Hello, this is probably another really simple tasks for most of you gurus, however I am trying to make a script which takes an input, greps a specific file for that input, prints back to screen the results (which are directory names) and then be able to use the directory names to move files.... (1 Reply)
Hi,
Please help me, how to get all the direcotries, its sub directories and its sub directories recursively, need to exclude all the files in the process.
I wanted to disply using a unix command all the directories recursively excluding files.
I tried 'ls -FR' but that display files as... (3 Replies)
I would like to transfer all files ending with .log from /tmp and to /tmp/archive (using find )
The directory structure looks like :-
/tmp
a.log
b.log
c.log
/abcd
d.log
e.log
When I tried the following command , it movies all the log files... (8 Replies)
Can anyone come up with a unix command that lists
all the files, directories and sub-directories in the current directory
except a folder called log.?
Thank you in advance. (7 Replies)
Hi,
I have to find specific files only in the current directory...not in the sub directories.
But when I use Find command ... it searches all the files in the current directory as well as in the subdirectories. I am using AIX-UNIX machine.Please help..
I am using the below command. And i am... (2 Replies)
Here is my dir structure:
/tmp/dave/myappend.txt
/tmp/dave/dir1/test.txt
/tmp/dave/dir2/test.txt
/tmp/dave/dir3/test.txt
/tmp/dave/dir4/test.txt
I want to append the contents of myappend.txt to the end of each file with the name "test.txt" in all dirs in /tmp/dave/
I have tried this:... (2 Replies)
I have been running a program mseed2sac using the following command
cd IV
find . -type f -exec /swadmin/mseed2sac '{}' \;
The problem is that I end up with a lot of files in directory IV.
Instead I would like to select the designator HHZ, create a
directory IV.SAC and all the files output... (11 Replies)
Hello,
I'm a first time poster looking for help in scripting a task in my daily routine. I am new in unix but i am attracted to its use as a mac user.
Bear with me...
I have several files (20) that I manually drag via the mouse into several named directories over a network. I've used rsync... (14 Replies)
Discussion started by: SonnyClark
14 Replies
LEARN ABOUT REDHAT
file::path
File::Path(3pm) Perl Programmers Reference Guide File::Path(3pm)NAME
File::Path - create or remove directory trees
SYNOPSIS
use File::Path;
mkpath(['/foo/bar/baz', 'blurfl/quux'], 1, 0711);
rmtree(['foo/bar/baz', 'blurfl/quux'], 1, 1);
DESCRIPTION
The "mkpath" function provides a convenient way to create directories, even if your "mkdir" kernel call won't create more than one level of
directory at a time. "mkpath" takes three arguments:
o the name of the path to create, or a reference to a list of paths to create,
o a boolean value, which if TRUE will cause "mkpath" to print the name of each directory as it is created (defaults to FALSE), and
o the numeric mode to use when creating the directories (defaults to 0777)
It returns a list of all directories (including intermediates, determined using the Unix '/' separator) created.
If a system error prevents a directory from being created, then the "mkpath" function throws a fatal error with "Carp::croak". This error
can be trapped with an "eval" block:
eval { mkpath($dir) };
if ($@) {
print "Couldn't create $dir: $@";
}
Similarly, the "rmtree" function provides a convenient way to delete a subtree from the directory structure, much like the Unix command "rm
-r". "rmtree" takes three arguments:
o the root of the subtree to delete, or a reference to a list of roots. All of the files and directories below each root, as well as the
roots themselves, will be deleted.
o a boolean value, which if TRUE will cause "rmtree" to print a message each time it examines a file, giving the name of the file, and
indicating whether it's using "rmdir" or "unlink" to remove it, or that it's skipping it. (defaults to FALSE)
o a boolean value, which if TRUE will cause "rmtree" to skip any files to which you do not have delete access (if running under VMS) or
write access (if running under another OS). This will change in the future when a criterion for 'delete permission' under OSs other
than VMS is settled. (defaults to FALSE)
It returns the number of files successfully deleted. Symlinks are simply deleted and not followed.
NOTE: If the third parameter is not TRUE, "rmtree" is unsecure in the face of failure or interruption. Files and directories which were
not deleted may be left with permissions reset to allow world read and write access. Note also that the occurrence of errors in rmtree can
be determined only by trapping diagnostic messages using $SIG{__WARN__}; it is not apparent from the return value. Therefore, you must be
extremely careful about using "rmtree($foo,$bar,0" in situations where security is an issue.
AUTHORS
Tim Bunce <Tim.Bunce@ig.co.uk> and Charles Bailey <bailey@newman.upenn.edu>
perl v5.8.0 2002-06-01 File::Path(3pm)