Finding a File That Contains The Requested Text from Terminal Session - linux

I don't know if this is a duplicate questions or not, but I haven't been able to find it...
I'm an old-school UNIX/Linux/AIX programmer, so I'm used to the terminal command line, even on MacOS X.
I've been using the following command to locate the given text in all files under the current folder:
find . -type f 2>/dev/null -exec grep [text] {} \; -ls
where [text] is the text string that I'm searching for. I have two issues, one minor and one major:
Minor - this command displays the text before the path to the file that contains the text string
Major - this command is both CPU (minor) and memory (major) intensive, grabbing almost all available memory while it's running on folders containing large numbers of files.
What I would like to find is a solution that resolves both of these issues, but the resource issue is the more annoying one.
Thanks in advance for any help....
BTW, I checked How do I find all files containing specific text on Linux?, and it doesn't resolve the resource/time issue.

Related

How do I find missing files from a backup?

So I want to backup all my music to an external hard drive. This worked well for the most part using Grsync, but some didn't copy over because of encoding issues with the file name.
I would like to compare my two music directories (current and backup) to see what files were missed, so I can copy these over manually.
What is a good solution for this? Note there are many many files, so ideally I don't want a tool that wastes time comparing the file contents. I just need to know if a file is missing from the backup that is in the source.
Are there good command line or gui solutions that can do this in good time?
Go to the top level directory in each set.
find . -type f -print | sort > /tmp/listfile.txt
Set up a sorted list for each directory, and diff should help you spot the differences.

Determine what file has changed or been created

I'm able to connect our CentOS 6.7 server to an external LDAP successfully but the last step in the process requires something in the GUI:
System > Administration > Authentication, then checking "Authentication Method"
I'd love to either know the exact file that this change in the GUI modifies or creates, or learn a method that I can use to show me which files have been created or modified in the last five minutes, for example. Of course, I have no idea which directory or directories this file was created or modified in.
I'm primarily a Mac user so we have tools in OS X that can be used for such a purpose, but I'm hoping there's an equivalent method in CentOD/RHEL.
Thanks in advance,
Dan
This isn't the exact answer I was looking for but does solve my immediate problem. The following find command shows recently created files, sorted by most recent:
find /etc -type f -printf '%TY-%Tm-%Td %TT %p\n' | sort -r
Looks like the file changed by the GUI above is:
/etc/sysconfig/authconfig

How to identify line endings on a large number of files

Given a medium-size tree of files (a few hundred), is there some utility that can scan the whole tree (recursively) and display the name of each file and whether the file currently contains CRLF, LF, or mixed line terminators?
A GUI that can both display the current status and also selectively change specific files is preferred, but not essential.
Also prefer a solution for Windows, but I have access to both Bash for Windows and a Linux box that has access to the same file tree, so I can use something Linux-y if necessary.
Related Question: https://unix.stackexchange.com/questions/118959/how-to-find-files-that-contain-newline-in-filename
You can use linux' find to look recursivly for filenames containing newline characters:
find . -name $'*[\n\r]*'
From there you can proceed to do what you need to do.

vi text search with exclude (linux)

I have a huge log file (25.3 million lines) with errors and I won't to search it without holding down the up button. How can you search this with vi? I've seen similar at directory levels but not particular files. At the moment I've searched a date e.g. /Tue 15 Jan
and navigated down but I'm not sure when problems may have began (only when noticed) so I need a general search.
My general idea from within the file would be /ORA-/!ORA-00020
meaning that I want to find those strings containing "ORA-" but ignoring those that are "ORA-00020". Any idea how this can be done viewing a particular file?
Thanks for any info
You do
grep -v "ORA\-00020" error.log > error2.log
then you search error2.log
I don't know the exactly way on vi, but we have kind of ways to get the result:
we can use cat/grep commands and write the answers in another file (so we have much smaller file) and then you can search in it, if it will be ok.
you can use vim instead vi and use TagList Vim Plugin.
Additional info at:
http://www.thegeekstuff.com/2009/04/ctags-taglist-vi-vim-editor-as-sourece-code-browser/
http://vim-taglist.sourceforge.net/faq.html

How do you search for all the files that contain a particular string?

Let's say you're working on a big project with multiple files, directories, and subdirectories. In one of these directories/subdirectories/files, you've defined a method, but now you want to know exactly which files in your entire project have been calling your method. How do you do this?
You mentioned grep so I'll throw this solution out there. A more robust solution would be to implement a version control system as Fibbe suggested.
find . -exec grep 'method_name' {} \; -print 2> /dev/null
The idea is, for each file that is found in the current directory and sub-directories, a grep for 'method_name' is executed on that file. The 2> /dev/null is nice if you don't want to get warned about all of the directories and files you don't have access to.
The most common way to do this is by using your editor. For example emacs can do this if you create a tag index with etags.
Source: http://www.gnu.org/software/emacs/emacs-lisp-intro/html_node/etags.html
The you just types M-. and type the name of the function you want to visit and emacs will take you there.
I don't know what system or which editor you are using but most editors has a simular function.
If you don't use emacs an other good way to keep track of functions, and get a lots of other good features, is to use a versions control system. Like git, it provides really fast search.
If you don't use a version control system you may want to look at a program that is designed just for searching. Like OpenGrok.

Resources