urgent: problem with find command


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users urgent: problem with find command
# 1  
Old 06-03-2006
urgent: problem with find command

find / * -print > /var/tmp/updatedfilelist.txt 2>&1


i need to run the above file in cron. problem is, this process takes a long long long time to finish up. and even worse, it fills up the directory the output file is located in.

i dont want the /var directory to ge filled up because of this prcess. so i was thinking about running the program for about 10 minutes then killing it off. after examining the file earlier, i noticed it is the bogus files on the system that makes it take so long. so i concluded thee files that the find command is able to find within the first 10 minutes should be good enough.

will the below command work to kill off that process in 10 minutes?

#!/bin/sh
find / * -print > /var/tmp/updatedfilelist.txt 2>&1
sleep 600
for process in `ps -ef | grep find | awk '{print $2}'`
do
kill -9 $process
done


i'm asking because i'm not sure if the script will wait till the find command is done before initiating the sleep command. because if it has to wait for the find command to finish then this script might as well be useless

Last edited by Terrible; 06-03-2006 at 08:32 AM..
Terrible
# 2  
Old 06-03-2006
why not just limit the number of files you find, instead of time?
Code:
# limit total number
find / * -print | head -10000 > /var/tmp/updatedfilelist.txt 2>&1
# exclude system files
find / * -print ! -group bin ! -group sys ! -group root > /var/tmp/updatedfilelist.txt 2>&1
#exclude files older than a month
find / * -print -mtime -30 > /var/tmp/updatedfilelist.txt 2>&1

What are you trying to acheive by listing every file on the system?
# 3  
Old 06-03-2006
find / *
is silly. "find /" is already going to try for every file. The * is replaced by the shell with a list of files in the current directory. After find finishes with every file due to the /, it will move on to the list of files generated by * and search those too.
# 4  
Old 06-03-2006
Quote:
Originally Posted by Perderabo
find / *
is silly. "find /" is already going to try for every file. The * is replaced by the shell with a list of files in the current directory. After find finishes with every file due to the /, it will move on to the list of files generated by * and search those too.

so you're saying the * is not needed?
Terrible
# 5  
Old 06-03-2006
If you're looking specifically for files, add the "-type f" expression which will exclude links, directories, pipes, etc... The "-xdev" expression will prevent the find from tracing through NFS mounts but would require a separate find for each file system, such as /, /usr, /var, etc...

As asked earlier, what exactly are you trying to achieve?
# 6  
Old 06-03-2006
Quote:
Originally Posted by Terrible
so you're saying the * is not needed?
I was trying to make a stronger statement. The presence of the * is harmful.
# 7  
Old 06-04-2006
i was just trying to list all the files on the system and send em to a file. this makes it easier on both the user and system to, at a later date, search for the location of a file from the file that contains the list of all the files on the system. instead of having to use the find command and possibly risking render the system powerless by mistakenly typing the wrong command.
Terrible
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX and Linux Applications

problem with find command

Hi All, I want to search only files more than 60 min in particular directory but not in sub directories. with this command i am getting even sub directires also.Please and let me know how to get the files. $i=`find /home/n1013141/vijay -type f -mmin -60`; print $i; ... (6 Replies)
Discussion started by: bhas1285
6 Replies

2. Shell Programming and Scripting

Problem with Find command urgent help!!

hi I used find command to find some file names as per input from user. I used it for current directory. It was working fine. Now I tried with giving some other directory path. Its giving issues. Here what I tried. Script will take input from user say 1_abc.txt, find the file and print list. if... (1 Reply)
Discussion started by: sukhdip
1 Replies

3. Shell Programming and Scripting

URGENT HELP: problem with mv command

I was trying to move a file to a particular directory. In a hurry i forgot to give the dest directory, as below mv prod.log The file disappeared. :confused: Any idea where it might have moved??? And I have tried moving files based on date from one directory to another as below.... (1 Reply)
Discussion started by: siteregsam
1 Replies

4. Shell Programming and Scripting

problem in find command

I am facing problem in find command. I want to read all file names of a directory and write those names in a text file. My script is find /home/Pratik/src -type f -exec basename {} \; >> names.txt The script is working fine and writing all the file names but problem is file names are not... (5 Replies)
Discussion started by: pratikjain998
5 Replies

5. UNIX for Dummies Questions & Answers

Problem with Find command

Hi, I have a script below,which reads dates from No_weekandMonthend_dates.txt performs the copy operation. for i in `cat /tmp/No_weekandMonthend_dates.txt` do cd $Gerenimopath/ZH_LP find . -type f -name "$i_*.txt" -exec cp {} /home/gaddamja/TempLocal \; cd... (2 Replies)
Discussion started by: jagadish_gaddam
2 Replies

6. UNIX for Dummies Questions & Answers

very urgent..need of a script which finds a file without the use of find command..hlp

im a beginner in shell scripting and i need a script which will find a file in a given path without the use of find or grep command.......i need some kind of code.....plzzz plzzzz help me......ive tried n searched every where but i couldn't find the solution for my particular problem..... (4 Replies)
Discussion started by: mishi
4 Replies

7. UNIX for Dummies Questions & Answers

problem with output of find command being input to basename command...

Hi, I am triying to make sure that there exists only one file with the pattern abc* in path /path/. This directory is having many huge files. If there is only one file then I have to take its complete name only to use furter in my script. I am planning to do like this: if ; then... (2 Replies)
Discussion started by: new_learner
2 Replies

8. Shell Programming and Scripting

Find command problem

Hi All, I am using following find command to delete the records older than 7 days but getting missing conjuction error.Kindly suggest: The command is: find <complete_dir_path> \(! -name usr -prune \) -type f -name "*.txt" -mtime +6 -print | xargs rm (11 Replies)
Discussion started by: visingha
11 Replies

9. Shell Programming and Scripting

Problem with Tail command --urgent pls

eg: If I execute an example tail statement to put rows from one file to another, it truncates some of the data. /carrier>wc -l IntIndA.txt 1918 IntIndA.txt /carrier>tail -1918 IntIndA.txt > test /carrier>wc -l test 132 test The tail command should copy 1918 rows to test file instead of... (4 Replies)
Discussion started by: subbukns
4 Replies

10. UNIX for Dummies Questions & Answers

find command - Urgent Plz.

Hi, In my current directory, i have the following files: x1.dat x2.dat.gz x3.dat I want to use the find command and display only files which has *.dat and NOT *.gz extension files. Please help me out. Thanks, Kris Kart. (2 Replies)
Discussion started by: Kris_Kart_101
2 Replies
Login or Register to Ask a Question