You can find files created after a specific date/time. Ie: Age of file since either creation or modification.
You can find files over a specific size. Looking for files that has filled a partition or blew out a user quota all of a sudden? This would be a perfect example of using the find.
You can find directories.(use this alot in the freebsd ports collection when I can't remember where the port is at).
You demonstrated executing specific commands with the find once a file has been found. combining the time with lookup (modification date) and the execution of other commands(rm), you can keep your /tmp files cleaned up.
Like I said, find is one of my favorite commands.
Dan
Discussion on:
View:
Show:
Being a bit new to this I probably doing something wrong, this is also on Solaris rather than Linux, but I assume it should be similar.
I was trying to use find and grep the other day to look for a word in all files within a directory and sub directories. But had trouble getting it to work.
Command was grep -li management `find . -type f` > /tmp/latfile.lst
Result is ksh: /bin/grep: arg list too long
Any help would be appreciated, thanks.
I was trying to use find and grep the other day to look for a word in all files within a directory and sub directories. But had trouble getting it to work.
Command was grep -li management `find . -type f` > /tmp/latfile.lst
Result is ksh: /bin/grep: arg list too long
Any help would be appreciated, thanks.
find . -exec grep "www.athabasca" '{}' \; -print
This is an example from here:
http://www.athabascau.ca/html/depts/compserv/webunit/HOWTO/find.htm
In your case, I would try something like:
find . -type f -exec grep "management" '{}' \;
This should search all files in current directory, grep those files for the word management and print them.
Dan
This is an example from here:
http://www.athabascau.ca/html/depts/compserv/webunit/HOWTO/find.htm
In your case, I would try something like:
find . -type f -exec grep "management" '{}' \;
This should search all files in current directory, grep those files for the word management and print them.
Dan
Thanks Dan for taking the time to reply, that worked fine.
I didn't however explain very well what I was looking for.
Rather than returning the actual text with the word searched for, how would I just get the file name that contains the search criteria?
I thought the -name switch with find would give me the answer, but again I am struggling to get the syntax right.
I didn't however explain very well what I was looking for.
Rather than returning the actual text with the word searched for, how would I just get the file name that contains the search criteria?
I thought the -name switch with find would give me the answer, but again I am struggling to get the syntax right.
find . -type f -exec grep -Hc "idiot" '{}' \; | grep -v ":0"
This was performed in a high level script directory where I developed a firewall script called idiotblocker. This is what it listed off.
./CVS/Repository:1
./CVS/Entries:2
./ChangeLog:5
./README:14
./check.txt:3
./idiotblocker.sh:34
./ManualUpdate.sh:5
./FTP-idiotblocker.pl:6
./FTP-idiotblocker.pl-bk20061030:2
./BruteForceCheck.sh:5
./PerlVersion/idiotblocker.pl:8
./PerlVersion/idiotconfig.pl:1
./PerlVersion/test.pl:2
./PerlVersion/idiotblocker_20070822Works.pl:8
./PerlVersion/idiotblockerbkup.pl:4
./ExternalBlacklist.sh:2
./idiotblocker_non.sh:34
What your seeing is the path with a number on the end showing the number of times the verb appears in the file.
What is occurring is.
1). Find is actually listing off all files, but it is showing a numeric at the end showing the number of occurrences of the text specified in the find grep option. Lots of 0 counts appeared.
2). This output is then directed to another grep which via the -v option prints every line from the previous command that does not have
Will this work?
Dan
This was performed in a high level script directory where I developed a firewall script called idiotblocker. This is what it listed off.
./CVS/Repository:1
./CVS/Entries:2
./ChangeLog:5
./README:14
./check.txt:3
./idiotblocker.sh:34
./ManualUpdate.sh:5
./FTP-idiotblocker.pl:6
./FTP-idiotblocker.pl-bk20061030:2
./BruteForceCheck.sh:5
./PerlVersion/idiotblocker.pl:8
./PerlVersion/idiotconfig.pl:1
./PerlVersion/test.pl:2
./PerlVersion/idiotblocker_20070822Works.pl:8
./PerlVersion/idiotblockerbkup.pl:4
./ExternalBlacklist.sh:2
./idiotblocker_non.sh:34
What your seeing is the path with a number on the end showing the number of times the verb appears in the file.
What is occurring is.
1). Find is actually listing off all files, but it is showing a numeric at the end showing the number of occurrences of the text specified in the find grep option. Lots of 0 counts appeared.
2). This output is then directed to another grep which via the -v option prints every line from the previous command that does not have
Will this work?
Dan
Now my brain is spinning! The -H option is not valid on this OS. It will list the count fine.
I will have a bit of a play with it over the next day or so. Thanks again for your help.
I will have a bit of a play with it over the next day or so. Thanks again for your help.
Sorry, missed that when I was doing the man last night on the grep.
It's cleaner then what I got too.
Dan
It's cleaner then what I got too.
Dan
I use the find command a LOT! The temptation of new Linux users is to use Search via a GUI file manager, which I've found to be painfully slow compared to the find command.
A few tips to add here:
1) Always surround the search text between single quotes (NOT double quotes!).
2) An often overlooked option is -ls as the last option, instead of -print (the default).
Finding files without knowing where they're located is many times useless, so use -ls to see the complete path, the permissions and more. The -ls option gives a long listing; the same as you'd see with the ls -l command.
A few tips to add here:
1) Always surround the search text between single quotes (NOT double quotes!).
2) An often overlooked option is -ls as the last option, instead of -print (the default).
Finding files without knowing where they're located is many times useless, so use -ls to see the complete path, the permissions and more. The -ls option gives a long listing; the same as you'd see with the ls -l command.
I recently found good examples of unix find commands , easy to use and explained with clear example. something I have been looking for unix find in last few days. Some of example of find command is bit old but they are still effective.
- Keyboard Shortcuts:
- Prev
- Next
- Toggle

































