Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Find file with extension and excluding directory Post 303026853 by Don Cragun on Tuesday 4th of December 2018 02:12:50 AM
Old 12-04-2018
Hi nezabudka,
Note that most Solaris systems don't have the -regex, -path, and -not primaries.

Hi snowfrost88,
The find command that you're using has two groups of primaries separated by a logical OR operator (-o). The first group of primaries is just -name "*.txt". This group essentially finds all files with names ending with .txt and ignores them. The second group finds all files with names ending with .err that have been modified in the last 30 days that are not directories and that have the name ./b and moves all files that meet all of those requirements to the file named ./c (which we hope, but have not verified, is a file of type directory). Since no filename can ever contain a <slash> character, no filename can ever be selected by the -name ./b primary (and, therefore, no files will ever be moved by this command).

In addition to the problem noted above, I assume that what you're really trying to do is to move all files that have been modified within the last 30 days that either have a name ending in .txt or ending in .err that are not located in or under a directory named either b or c into the directory named c without duplicating any of the file hierarchy structure into the directory c. If that assumption is correct, you probably want something more like:
Code:
find . \( -type d \( -name b -o -name c \) -prune \) -o \( -type f -mtime -30 \( -name '*.txt' -o -name '*.err' \) -exec mv {} c/ \; \)

Note the sets of \( and \) grouping operators to alter the precedence the logical OR operators and the -prune primary to ignore all files under directories named b or c when selecting regular files with the extensions .txt and .err.

Last edited by Don Cragun; 12-04-2018 at 03:18 AM.. Reason: Add note explaining why nezabudka's suggestion won't work.
This User Gave Thanks to Don Cragun For This Post:
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Get the name of the file excluding the extension

How to get the name of the file by excluding the extention of file name? For example, my filename is 'test.txt'. I want to get only the name 'test' but not the extention .txt. (2 Replies)
Discussion started by: vinay123
2 Replies

2. UNIX for Advanced & Expert Users

find excluding a directory and a file

Hi I have some 5 folders and two files in the current directory. I want to delete all, expect one folder(files in the folder too should not be deleted) and a file in the current directory. Lets say the folder and file that should not be deleted as 'a'(folder name) and 'b'(file name). Can you... (1 Reply)
Discussion started by: ammu
1 Replies

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

4. Solaris

how to find out the file's name excluding string?

Hello, Under one directory, I can use below command to find out the file names with string "Export terminated successfully without warnings" grep -i -l "Export terminated successfully without warnings" *.* My question is : how I find out the file names without including string "Export... (5 Replies)
Discussion started by: GreatJerry
5 Replies

5. UNIX for Dummies Questions & Answers

Need help in excluding a particular directory using Find commad

Hi, I have a directory structure as below /home/gad/Merl/a/a1.txt /home/gad/Merl/b/a1.txt /home/gad/Merl/c/a1.txt How can I find the file a1.txt but not from directory 'a' and it(the filw) should loaded 6 days ago.. Can any one pls help,quick reply much appriciated.. Thanks. (1 Reply)
Discussion started by: jagadish_gaddam
1 Replies

6. Shell Programming and Scripting

Find all files for a user, excluding a directory

I have been searching, and cannot find an answer for this. I am trying to find all files for a user, lets call him (test001), and I want to exclude a specific directory. Here is the command I run, it finds all files: find / -user test001 I get this result: > find / -user test001 ... (4 Replies)
Discussion started by: steve2x4
4 Replies

7. UNIX for Dummies Questions & Answers

Finding new file, but excluding directory..

hi, I need to find files that have been created less than 3 days ago. However, I need to only search specific directories. I've searched about the net and found some useful commands such as : find . -type d -name 'dir_to_exclude' -prune -o -print -mtime -3 however I cannot get it... (2 Replies)
Discussion started by: horhif
2 Replies

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

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

10. Shell Programming and Scripting

Find/searching files in subdirectories excluding the fiels in Parent Directory

Hi All, requirement is to find and remove the files from sub directories but it should exclude the files from parent directory. At present i am using the below one but it finds and remove files from both parent and sub directories. find ${PATH} -type f \( -name securitas\* -o -name \*gz... (1 Reply)
Discussion started by: Naveenkk
1 Replies
All times are GMT -4. The time now is 09:38 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy