- Comparison between DOS and Linux/UNIX:
Link: How to create Markdown Table
DOS | Linux/UNIX |
---|---|
cd | cd |
attrib | chmod |
comp | diff |
copy | cp |
del | rm |
rd | rmdir |
dir | ls |
set | printenv |
find | grep |
help | man |
md | mkdir |
move | mv |
ren (rename) | mv |
date, time | date |
chkdsk | df |
type | cat |
type <filename> | more | more |
sort | sort |
- Example:
dir | sort /R
- Some
grep
examples integrated withfind
andglobstar: **
:
-
NOTE:
glob
~*
: was called asGLOB
expression.- If Bash version is 4 or higher, can make use of Bash’s
globstar
(**
) to match files recursively.
-
exp1: Using
grep
with --include=Glob, search for the pattern only with the.log/.md
extension recursively in thetest/
folder:
grep -R --include=*.log 'Exception' test/
grep -R --include=*.{log,md} 'Exception' test/
- exp2: With
globstar
expression, the-R
recursive option is now totally useless:
grep 'Exception' test/**/*.log
grep 'Exception' test/**/*.{log,md}
- exp3: Only using
find
command with the example filename pattern "app_20200301.log":
find test/ -type f -a -regextype 'egrep' -regex '.*_[0-9]{8}.*'
- exp4: Combining the
find
withgrep
in one command with the-exec
action:
find test/ -type f -a -regextype 'egrep' -regex '.*_[0-9]{8}.*' -exec grep -H "Exception" '{}' \;
-
NOTE (exp4):
- The command requires the ending
\;
. This is because it indicates the termination of the grep command. - The
-exec
action will be executed on each file the find command has found.
- The command requires the ending
-
exp5: Using
xargs
to combinefind
andgrep
:
find test/ -type f -a -regextype 'egrep' -regex '.*_[0-9]{8}.*' | xargs grep "Exception"
-
NOTE (exp5):
xargs
will build matched files into bundles and run them through the command as few times as possible.