Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I have a folder which has a couple of txt files.Now what I want is I want to grep for a particlualr pattern in say the latest 4-5 files in the folder.It must list me those files and the occurrences of the line number in those files.How can I do this ?
No, it's almost never a good idea to parse ls for filenames, particularly when using a command substitution. Any name it hits that has whitespace in it will be unreadable.
Unfortunately, it's not particularly easy to safely grab "n" number of files, based on metadata like modification time, but bashFAQ 99 gives you some tips on how to do it. Doubtless google will give more.
(I'd help to work out a solution myself, but unfortunately I don't have much time now. I'll come back to it later when I have more time, and if the question is still active. )
Run from within the directory containing your files, this will look for all files created in the last week and then pass those file names to grep. The use of xargs avoids problem with filenames containing spaces.
Run from within the directory containing your files, this will look for all files created in the last week and then pass those file names to grep. The use of xargs avoids problem with filenames containing spaces.
That's not the last few files, that's all files from the last 6 days ...
I want to grep for a particular pattern in say the latest 4-5 files in the folder.It must list me those files and the occurrences of the line number in those files.
Depending on the frequency of new file creation then '-mmin' might be a better option than '-mtime'.
Sorry guys I am marking this thread as unsolved again.When I run the command given by Thinkster I am getting errors as below
find: 0652-017 -print0 is not a valid option.
xargs: The -0 flag is not valid.
Usage: xargs [-p][-t] [-e[EndOfFileString]] [-E EndOfFileString]
[-I ReplacementString] [-i[ReplacementString]] [-L Number]
[-l[Number]] [-n Number [-x]] [-s Size] [Command [Argument ...]]
The uname -a command on my server gives the follwoing output.Can you please tell what command should I run to find all the files that have the pattern "xyz" fast.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.