how to differentiate a file from a folder in a FIND?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers how to differentiate a file from a folder in a FIND?
# 1  
Old 06-06-2006
how to differentiate a file from a folder in a FIND?

I have to read a complete folder and if it is a file older that 7 days I have to copy it elsewhere and if it is a folder nothing to make.

The way I do it:
for I in `find /home/. -name "*" -mtime +7`
do
cp -Rf $I /home/elsewhere/.
done

Am I okay with the way I want to do it?

Help please?!?!

Denys
# 2  
Old 06-06-2006
Denys,

You can simplify this in a couple of ways.

1) Use the type switch for 'find' command - to limit your results to files - not dirs or anything else
-type f

2) Use an exec at the end of find to automatically cp for you without the 'for' loop

3) Remove the -name "*" , which is redundant - it is adding a filter with no limitations.


Try this as a solution:

find /home/. -mtime +7 -type f -exec cp -Rf {} /home/elsewhere/ \;
# 3  
Old 06-06-2006
Quote:
Originally Posted by steweston
Denys,

You can simplify this in a couple of ways.

1) Use the type switch for 'find' command - to limit your results to files - not dirs or anything else
-type f

2) Use an exec at the end of find to automatically cp for you without the 'for' loop

3) Remove the -name "*" , which is redundant - it is adding a filter with no limitations.


Try this as a solution:

find /home/. -mtime +7 -type f -exec cp -Rf {} /home/elsewhere/ \;

Thanks. I tried that but I still have a problem. When I do the find command as you told me I have this error:
find: 0652-018 An expression term lacks a required parameter.

What can I do wrong?
# 4  
Old 06-06-2006
Try stripping off the -exec part of the statement to see what the output is before we manipulate it.
execute
find /home -mtime +7 -type f
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Don't have tree, need advise to differentiate dir from file from this alternative that uses find

Hi, I don't have tree on the Solaris server and our SA don't want to install it. I found this example from One Line Linux Command to Print Out Directory Tree Listing | systemBash that more or less does what I am mainly looking for. Example run is as below: $: find ./ | sed -e... (2 Replies)
Discussion started by: newbie_01
2 Replies

2. Shell Programming and Scripting

Find common lines with one file and with all of the files in another folder

Hi! I would like to comm -12 with one file and with all of the files in another folder that has a 100 files or more (that file is not in that folder) to find common text lines. I would like to have each case that they have common lines to be written to a different output file and the names of the... (6 Replies)
Discussion started by: Eve
6 Replies

3. UNIX for Beginners Questions & Answers

UNIX utility to find difference in folder, file and contents of file against a base version

Hi, I am trying to find out whether there are any Unix utilities that compares folders, files and contents within the file and provides a comprehensive report. The comparison can be against base version of a folder and file with content. Can you please let me know of such a utility? Thanks,... (6 Replies)
Discussion started by: Sripathi_ks
6 Replies

4. Shell Programming and Scripting

how to differentiate file and directory name using ls command

how to differentiate file and directory name using ls command. l (3 Replies)
Discussion started by: jhon123
3 Replies

5. Shell Programming and Scripting

Find folder within folder, then find other folder in same dir

Hi all I'm new to your forum but not new to shells. I'm having a little trouble though as it's been quite some time since I scripted. Here's what I'm trying to do: I'm trying to search a directory named '/var/root/Applications' for another directory 'fooBar'. The "Applications" directory... (9 Replies)
Discussion started by: DC Slick
9 Replies

6. Shell Programming and Scripting

Find all text files in folder and then copy to a new folder

Hi all, *I use Uwin and Cygwin emulator. I´m trying to search for all text files in the current folder (C/Files) and its sub folders using find -depth -name "*.txt" The above command worked for me, but now I would like to copy all found text files to a new folder (C/Files/Text) with ... (4 Replies)
Discussion started by: cgkmal
4 Replies

7. UNIX for Dummies Questions & Answers

Disk Usage in GB and Unix command to find the biggest file/folder

Hi All, Please help me out 1) Command to find the disk usage in GB. I know that du -k will give in kilobites. 2) How to find the Biggest file/folder in a given set of files/folders. Thanks in advance Regards, Manas (8 Replies)
Discussion started by: manas6
8 Replies

8. UNIX for Dummies Questions & Answers

differentiate between a file and a device

sorry probably a beginner question but i was just wondering how unix does this as device are treated as files? (6 Replies)
Discussion started by: keith_hampson
6 Replies

9. UNIX for Dummies Questions & Answers

Find a file in a folder-please help

HI , I have a very small requirement here. I need to find a file say which ends with .gz in a folder. If i found this file then i need to echo" file found" and do a word count of the file and if not i need to echo file not found and exit from the loop. i have written this script but i am only... (7 Replies)
Discussion started by: bsandeep_80
7 Replies

10. Shell Programming and Scripting

Script to find a file in the other folder

Hi, I have two folders in two different directories.Both the folders contain set of text files. The name of the files are same in both the folders. I need to write a script to compare all the files in both the folders having same name. I am new to unix. Can you help me out in giving a script to... (4 Replies)
Discussion started by: ragavhere
4 Replies
Login or Register to Ask a Question