Skip to main content

Posts

Linux find file names with given string

  I'd like to find all files in the current directory and subdirectories whose name contains the string "ram". Solutions: 1.  find . -type f -name "*ram*" The find command will take long time because it scans real files in file system. The quickest way is using locate command, which will give result immediately: 2. locate "ram" If the command is not found, you need to install mlocate package and run updatedb command first to prepare the search database for the first time. How to install locate command on Amazon Linux? $ sudo yum install mlocate $ sudo updatedb $ sudo updatedb $ locate "ram" /home/work/ram.txt /usr/share/mime/application/vnd.google-earth.kml+xml.xml /usr/share/mime/application/vnd.google-earth.kmz.xml /usr/share/mime/text/x-google-video-pointer.xml 3. find . -type f -exec grep -H 'text-to-find-here' {} \; Usage : find . -type f -exec grep -H 'ram' {} \; 4.grep -rnw '/path/to/somewhere/...

Find Command that returns line number of the string

I have a bunch of files organized into directories..All these are text files (c/c++). I am trying to understand this code and i need to look at the declarations of many variables..How can i use find command to get the exact location( File Name with line number(s) ) using Find command in ubuntu linux?? Or is there any graphical tool for doing the same? Answer: You can do this with grep.   grep -n 'search-term' *.c   will give you the filename and line number where the term appears. This will fail if there are sub directories     You can use grep -nr 'search-term' *.c -H, --with-filename     

Files creation

In LINUX files can be created by using any of the three methods given below:        1.  Cat command (cat - CONCATENATION)        2. Touch command        3. Vi editor 1. cat command: cat stands for CONCATENATE. This is the basic command when we start learning LINUX/UNIX, as the name suggest it is used to create new file, concatenate files and display the content of the files on the standard output.     Different examples of cat command which will be useful for the beginners. 1. Creating new file 2. View the contents of the file 3. View the contents of  multiple files 4. Display the output of a file using page wise 5. cat command without filename arguments 6. Display the content of a file with line numbers 7. Copy the contents of a one file to another file 8. Appending the contents of one file to another file 9. Redirecting the output of multiple files into a single fi...