Basic Linux Commands Part – 3

Basic Linux Commands

1]     grep  ( print lines matching a pattern) :-
grep command searches the given file for lines containing a match to the given strings or words. By default, grep prints the matching lines. Use grep to search for lines of text that match one or many regular expressions, and outputs only the matching lines.
grep’s basic syntax is
grep [options] PATTERN [FILE…]
Ex:
grep ‘word’ filename
grep ‘string1 string2’  filename
===========================================
2]  find  ( finding files ) :-
         find command is used to locate files on a Unix or Linux system.  find will search any set of directories you specify for files that match the supplied search criteria.  You can search for files by name, owner, group, type, permissions, date, and other criteria.  The search is recursive in that it will search all subdirectories too.
          find’s basic syntax is
find path expressions
Ex:
find / -name example
 ===========================================
3] diff  (Display the differences between two files) :-
       diff command compares two different files and reports the difference. The output is very cryptic and not straight forward to read.
diff’s basic syntax is
diff [options] file1 file2
Ex:
diff cookies.old cookies.new
===========================================
4] sort (Sorts the lines in a text file. )  :-
          sort command sorts a file according to fields–the individual pieces of data on each line. By default, sort assumes that the fields are just words separated by blanks, but you can specify an alternative field delimiter if you want (such as commas or colons). Output from sort is printed to the screen, unless you redirect it to a file.
sort’s basic syntax is
sort [options] [files]
Ex:
sort -k2 test.txt
sort -r file.txt
===========================================
5] tail (Delivers the last part of the file.)  :-
tail command displays the last few lines of a file. Like head, it can save you time, because it’s a lot quicker than calling up a file with a text editor and scrolling all the way down to the bottom. By default, tail will show the last ten lines of a file, but you can also tell it how many lines to display:
tail’s basic syntax is
tail [options]
Ex:
tail foo.txt
tail -n 5 flavours.txt
===========================================
Bookmark the permalink.

Comments are closed.