From 58d08676a25be9a5aa742b10f3ea1a84eddbaf02 Mon Sep 17 00:00:00 2001 From: test2 Date: Thu, 24 Oct 2019 01:04:14 +0300 Subject: [PATCH] ls --- ls/ex-1_ls.adoc | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/ls/ex-1_ls.adoc b/ls/ex-1_ls.adoc index 1b2ad7c..3ad6121 100644 --- a/ls/ex-1_ls.adoc +++ b/ls/ex-1_ls.adoc @@ -176,6 +176,51 @@ ls -l example |/var| Storage for all variable files and temporary files created by users, such as log files, the mail queue, the print spooler area, space for temporary storage of files downloaded from the Internet, or to keep an image of a CD before burning it. |======================= +== Find and grep + +=== find + +The find tool, known from UNIX, is very powerful. This command not only allows you to search file names, it can also accept file size, date of last change and other file properties as criteria for a search. + +The most common use is for finding file names: + +NOTE: find -name + +This can be interpreted as "Look in all files and subdirectories contained in a given path, and print the names of the files containing the search string in their name" **(not in their content).** + +[source,bash] +---- + find /etc -name "*.conf" +---- + + +=== grep + +grep is used for filtering input lines and returning certain patterns to the output. + +NOTE: grep "string" path/to/file + +[source,bash] +---- + grep "root" /etc/passwd +---- + + +=== find and grep command together + +find . -name "*.conf" -exec grep -Hns "conf" {} \; + + +.Explanation +[source,bash] +---- +-H, --with-filename + Print the filename for each match + -n, --line-number + Prefix each line of output with the 1-based line number within its input file +-s, --no-messages + Suppress error messages about nonexistent or unreadable files. +---- == Find IP