|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
How to do ls -l on results of grep and find?
Hi, Am running the command below to search for files that contains a certain string. Code:
grep -il "shutdown" `find . -type f -mtime -1 -print` | grep "^./scripts/active" How do I get it to do a ls -l on the list of files? I tried doing Code:
ls -l `grep -il "shutdown" `find . -type f -mtime -1 -print` | grep "^./scripts/active"` and that does not work. The command just hangs there. I was hoping to use find -exec but I can't get it to do exec and grep at the same time. FYI, the grep "^./scripts/active" is 'coz that is the directory that am interested in. This is what I end up doing. Hoping someone can advise a one-liner Code:
for file in $(grep -il "shutdown" `find . -type f -mtime -1 -print` | grep "^./scripts/active") do ls -l $file done Any advise much appreciated. Thanks in advance. Last edited by Scrutinizer; 06-17-2012 at 02:51 AM.. Reason: Add what I did - mod: extra code tags |
| Sponsored Links | ||
|
|
#2
|
||||
|
||||
|
find
Hi, Try this one, Code:
find . -type f -mtime -1 -print -exec grep -il 'shutdown' {} \; | grep "^./scripts/active"Cheers, Ranga:-) |
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
Hi Ranga,
Thanks for your reply. Tried that and it didn't work. It seems to print all the files and not the ones that just contains the text that am looking for. Also, I've managed to find the files that am looking for using grep -il "shutdown" `find . -type f -mtime -1 -print` | grep "^./scripts/active", but I want to a ls -l of them so I can see the timestamp of the files. |
|
#4
|
||||
|
||||
|
Awk
Hi, Try this one, Code:
find . -type f -mtime -1 -print | grep "^./scripts/active" | xargs -I '{}' ls -l {}Cheers, Ranga:-) |
| Sponsored Links | |
|
|
#5
|
|||
|
|||
|
Quote:
Code:
ls -l $(grep -il "shutdown" `find . -type f -mtime -1 -print | grep "^./scripts/active"`) The option -print, instead of -print0, can easily lead to errors. You pipe the output to grep. What if you have a file with a space in its name, for example? Besides, I don't understand very well why you're using Code:
find . ... | grep "^./scripts/active" instead of: Code:
find ./scripts/active ... So, putting all toghether, I'd try: Code:
ls -l `find ./scripts/active -type f -mtime -1 -print0 | xargs -0 grep -il "shutdown"` or, which is the same: Code:
ls -l $(find ./scripts/active -type f -mtime -1 -print0 | xargs -0 grep -il "shutdown") Last edited by Lem; 06-18-2012 at 05:05 PM.. |
| Sponsored Links | |
|
|
#6
|
|||
|
|||
|
Code:
find ./scripts/active -type f -mtime -1 -exec grep -il 'shutdown' {} \; -ls | grep -v '^\.' |
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Grep no results | Benou | Shell Programming and Scripting | 3 | 10-17-2011 07:46 AM |
| My ps -ef|grep command results are chopped off | bsp18974 | UNIX for Dummies Questions & Answers | 1 | 08-14-2007 10:35 AM |
| List grep results | slire | UNIX for Dummies Questions & Answers | 14 | 10-31-2006 10:42 AM |
| How to refine results of grep -p | priceb | Shell Programming and Scripting | 2 | 06-28-2006 08:40 AM |
| Multiple Grep Results - Formatting | sysera | Shell Programming and Scripting | 7 | 03-25-2004 05:04 AM |
|
|