![]() Real-life useful examples of the grep commands in Linux I am going to share with you how to use grep command in Linux with examples. But my secret weapon to find my way through so many code lines is the grep tool. ![]() It is not always easy to be immediately effective when you dig for the first time into a codebase containing several thousand of lines. To list *.html files not containing tables (option -L) : grep -L " the number of occurencesand ignoring case sensitivity : grep -ci "" *.html … With the row numbers and ignoring case sensitivity : grep -ni " To search for tables (HTML tags ) in *.html files : grep " find directory criteria -exec command ' 18.16 Mb The grep command and its options grep command syntax grep -option(s) expression file(s)ĭisplay lines that do not match the expressionĬounts the number of lines matching the expressionĭisplay the row matching the expression and its row number![]() When the option -exec is used, it is then possible to execute a command on the files found by theįind command. The option -exec is available in the find command and this option is exclusive of the option -print. The option -print is used to display the results to the standard output. \( -name a.out -o -name "*.c" \) -print > /dev/null find and the option exec The errors can be saved in a regular file if needed.Įxemple : find. To avoid this, redirect error messages to /dev/null. size +2G -print Redirecting error messagesĭue to access rights in some directories, the find command may produce a large number of error In practice, the unit ( k | M | G) is specified to avoid computing the multiples of 512 bytes. To identify *.html files whose size is greater than 50K (i.e. daystart -mtime -2 -name "*.html" Searching by size Specify daystart to use the real number of days without considering the current time. The option -mtime -2 means -48h, the option -ctime +30 means +30 × 24h : by default find uses the current date and the current time. To find *.json files created more than 30 days ago in the directory $LOG : find $LOG -ctime +30 -name "*.json" | sort. To find *.js or *.css files modified less than 2 days ago : find. images/google-analytics-optimisation-mesure-audience-02.jpgīy default, results are not sorted, that’s why in the above example sort is applied on the output of the find command. images/google-analytics-optimisation-mesure-audience-01.jpg images/conception-html-equations-math-mathjax-asciimath-01.jpg ![]() gif extensionīut not containing the keyword gimp in the name : find. To find in the current directory all files with the. c extension in the directory /usr : find /usr -name *.c -print /usr/share/bison/yacc.c The find command is recursive, directories and subdirectories are scanned by this command. Without at least this option,Įven if the search is successful, find displays nothing to the standard output. ![]() The find command is used at least with the option -print. \( critere1 -o critere2 \) : logical OR.\( criteria1 criteria2 \) or \( criteria1 -a criteria2 \) : logical AND.Search criteria can be combined using logical operators : ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |