Sponsored Content
Top Forums Shell Programming and Scripting Find command excluding directories and some files Post 302990988 by jcdole on Saturday 4th of February 2017 11:57:49 AM
Old 02-04-2017
Find command excluding directories and some files

hello.
I try to print a list of files but excluding some directories and some files.
I would like to write a command for :
find "from_dir" "ignore dir1, dir2, ..." "ignore file1, file2,...." "where file are older than 2017-02-03T06:00:00"

Note that "DO_IT" is a local function in the script and is exported like this
Code:
function DO_IT () {
    MY_PATH1="$1"
    if [[  ! -d "$MY_PATH1" ]] ; then
        echo "doing : $MY_PATH1"
    fi
}
export -f DO_IT

The first part run with success :
Code:
find /home/tux_user -type d \( -path /home/tux_user/.mozilla -o -path /home/tux_user/.cache -o -path  /home/tux_user/.local/share/RecentDocuments  -o -path  /home/tux_user/.local/share/kscreen  \) -prune -o -newermt '2017-02-03T06:00:00' -exec bash -c 'DO_IT "$0" '  {} \;

Now I want to exclude some files.
So I have add this part of code inside the find command
Code:
-o \( ! -name ".direct*" ! -name ".Xauthor*"  ! -name ".xsession-erro*"  ! -name "*.xsession-errors-:*"  ! -name ".bash_histor*"   \)

The command is now :
Code:
find /home/tux_user -type d \( -path /home/tux_user/.mozilla -o -path /home/tux_user/.cache -o -path  /home/tux_user/.local/share/RecentDocuments  -o -path  /home/tux_user/.local/share/kscreen  \) -prune -o \( ! -name ".direct*" ! -name ".Xauthor*"  ! -name ".xsession-erro*"  ! -name "*.xsession-errors-:*"  ! -name ".bash_histor*"   \) -o  -newermt '2017-02-03T06:00:00' -exec bash -c 'CHERCHE "$0" '  {} \;

But the specific files are still there (".direct*" ".Xauthor*" ".xsession-erro*" "*.xsession-errors-:*" ".bash_histor*").

Any help is welcome
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

find excluding the hidden files

Hi , I am trying to use the find command with delete in a directory . Even though i use a wil character search the find command is checking the hidden files which inturn results in error . Can i avoid look that into the hidden files ?? I am using HP unix . find /cv1/ -name "ite*"... (3 Replies)
Discussion started by: arunkumar_mca
3 Replies

2. UNIX for Dummies Questions & Answers

Find Files in a Directory Excluding Subdirectories

Hi, I have a filename Location.txt in a directory /abc. Similar name file is present in its subdirectory /abc/xyz. I want to find the file which is present only in /abc and not in /abc/xyz. Please any1 of u can provide a quick suggestion. Its very urgent. Thanks, Amol (2 Replies)
Discussion started by: Amol_Dicholkar
2 Replies

3. UNIX for Dummies Questions & Answers

Excluding directories with find

How do I exclude directories with the find command on Solaris? I want to skip the directories /proc and /shared. find / -nouser -print This shows me all files and directories that don't have an owner but I need to skip /shared and /proc. I've been able to get it to work on Linux... (3 Replies)
Discussion started by: x96riley3
3 Replies

4. UNIX for Dummies Questions & Answers

Copy Directories excluding files

Hi guys, I want to copy folder and sub folders only. I don't want the files. If i use cp -r command it will copy entirely with files. Could any one suggest me. Thanks in advance (1 Reply)
Discussion started by: karthik82
1 Replies

5. UNIX for Dummies Questions & Answers

List directories and sub directories recursively excluding files

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)
Discussion started by: pointers
3 Replies

6. AIX

find command to list all the 777 files and directories owned by root user

Hi I'm logged in to an AIX box now and we need to do an audit on this box. cbssapr01:# pwd / Which command will show all the files and directories owned by root user with permissions as 777 ? (8 Replies)
Discussion started by: newtoaixos
8 Replies

7. Shell Programming and Scripting

Copy files/directories excluding multiple paterns

my directory structure is like below: basedir\ p.txt q.htm r.java b\ abc.htm xyz.java c\ p.htm q.java rst.txt my requirement is i want to copy all the files and directories... (0 Replies)
Discussion started by: ajayyadavmca
0 Replies

8. Shell Programming and Scripting

Excluding directories from a find

I've looked at a few similar threads, but I can't bridge from those examples to what I'm working on, so I'm hoping someone can help. I want to extend the following statement find $PathToCheck -type f \( -not -iwholename "$ScriptDir/*" \) -exec md5sum "{}" \;>$NewSigs to exclude several... (9 Replies)
Discussion started by: nixie
9 Replies

9. Shell Programming and Scripting

Find command to search files in a directory excluding subdirectories

Hi Forum, I am using the below command to find files older than x days in a directory excluding subdirectories. From the previous forums I got to know that prune command helps us not to descend in subdirectories. Though I am using it here, not getting the desired result. cd $dir... (8 Replies)
Discussion started by: jhilmil
8 Replies

10. UNIX for Advanced & Expert Users

Find all files in the current directory excluding hidden files and directories

Find all files in the current directory only excluding hidden directories and files. For the below command, though it's not deleting hidden files.. it is traversing through the hidden directories and listing normal which should be avoided. `find . \( ! -name ".*" -prune \) -mtime +${n_days}... (7 Replies)
Discussion started by: ksailesh1
7 Replies
Wanted(3pm)						User Contributed Perl Documentation					       Wanted(3pm)

NAME
File::Find::Wanted - More obvious wrapper around File::Find VERSION
Version 1.00 SYNOPSIS
File::Find is a great module, except that it doesn't actually find anything. Its "find()" function walks a directory tree and calls a callback function. Unfortunately, the callback function is deceptively called "wanted", which implies that it should return a boolean saying whether you want the file. That's not how it works. Most of the time you call "find()", you just want to build a list of files. There are other modules that do this for you, most notably Richard Clamp's great File::Find::Rule, but in many cases, it's overkill, and you need to learn a new syntax. With the "find_wanted" function, you supply a callback sub and a list of starting directories, but the sub actually should return a boolean saying whether you want the file in your list or not. To get a list of all files ending in .jpg: my @files = find_wanted( sub { -f && /.jpg$/ }, $dir ); For a list of all directories that are not CVS or .svn: my @files = find_wanted( sub { -d && !/^(CVS|.svn)$/ }, $dir ) ); It's easy, direct, and simple. WHY DO THIS
? The cynical may say "that's just the same as doing this": my @files; find( sub { push @files, $File::Find::name if -f && /.jpg$/ }, $dir ); Sure it is, but File::Find::Wanted makes it more obvious, and saves a line of code. That's worth it to me. I'd like it if find_wanted() made its way into the File::Find distro, but for now, this will do. FUNCTIONS
find_wanted( &wanted, @directories ) Descends through @directories, calling the wanted function as it finds each file. The function returns a list of all the files and directories for which the wanted function returned a true value. This is just a wrapper around "File::Find::find()". See File::Find for details on how to modify its behavior. COPYRIGHT &; LICENSE Copyright 2005-2012 Andy Lester. This program is free software; you can redistribute it and/or modify it under the terms of the Artistic License v2.0. perl v5.14.2 2012-06-08 Wanted(3pm)
All times are GMT -4. The time now is 04:35 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy