grep와find의 용법
45034 단어 grep
linux grep find
linux grep find , 。
grep
, -v , 。
, “UserService”, ”*.svn” , ?
grep -r "UserService" ./ | grep -v "svn"
, ”test、auto_load” , ? :
grep -r "UserService" ./ | grep -v "svn" | grep -v "test" | grep -v "auto_load"
, , ,grep , “ |” ?
grep -r "UserService" ./ | grep -v "svn|test|auto_load"
, , 。 , , ”|” 。 :
grep -r "UserService" ./ | grep -v "svn|prj|test|auto_load"
:
grep -i pattern files : 。 ,
grep -l pattern files : ,
grep -L pattern files : ,
grep -w pattern files : , ( ‘magic’, ‘magical’),
grep -C number pattern files : [number] ,
grep pattern1 | pattern2 files : pattern1 pattern2 ,
grep pattern1 files | grep pattern2 : pattern1 pattern2 。
:
< > 。
:
grep man * ‘Batman’、‘manic’、‘man’ ,
grep '<man' * ‘manic’ ‘man’, ‘Batman’,
grep '<man>' ‘man’, ‘Batman’ ‘manic’ 。
'^': ,
'$': ,
linux find
:
grep -i pattern files : 。 ,
grep -l pattern files : ,
grep -L pattern files : ,
grep -w pattern files : , ( ‘magic’, ‘magical’),
grep -C number pattern files : [number] ,
grep pattern1 | pattern2 files : pattern1 pattern2 ,
grep pattern1 files | grep pattern2 : pattern1 pattern2 。
:
< > 。
:
grep man * ‘Batman’、‘manic’、‘man’ ,
grep '<man' * ‘manic’ ‘man’, ‘Batman’,
grep '<man>' ‘man’, ‘Batman’ ‘manic’ 。
'^': ,
'$': ,
grep find
1.linux find win 。
find / , type size time , 。
2.linux grep win findstr 。 txt , 。
grep , , 。
grep
: 。
:grep [-abcEFGhHilLnqrsvVwxy][-A< >][-B< >][-C< >][-d< >][-e< >][-f< >][--help][ ][ ...]
:grep , , grep 。 , “-”, grep 。
:
-a --text 。
-A< > --after-context=< > , 。
-b --byte-offset , 。
-B< > --before-context=< > , 。
-c --count 。
-C< > --context=< > -< > , 。
-d< > --directories=< > , , grep 。
-e< > --regexp=< > 。
-E --extended-regexp 。
-f< > --file=< > , , grep , 。
-F --fixed-regexp 。
-G --basic-regexp 。
-h --no-filename , 。
-H --with-filename , 。
-i --ignore-case 。
-l --file-with-matches 。
-L --files-without-match 。
-n --line-number , 。
-q --quiet --silent 。
-r --recursive “-d recurse” 。
-s --no-messages 。
-v --revert-match 。
-V --version 。
-w --word-regexp 。
-x --line-regexp 。
-y “-i” 。
--help 。
linux grep
grep www.linuxso.com
, ‘grep’ 。‘grep’ 。
‘/usr/src/linux/Documentation’ ‘magic’ :
$ grep magic /usr/src/linux/Documentation/*
sysrq.txt:* How do I enable the magic SysRQ key?
sysrq.txt:* How do I use the magic SysRQ key?
‘sysrp.txt’ , SysRQ 。
,‘grep’ 。 ,‘grep’ :
grep: sound: Is a directory
‘grep’ 。 :
:grep -r
:grep -d skip
, , ‘less’
$ grep magic /usr/src/linux/Documentation/* | less
, 。
, ( *)。 ,‘grep’ , 。 , <CTRL c> , 。
:
grep -i pattern files : 。 ,
grep -l pattern files : ,
grep -L pattern files : ,
grep -w pattern files : , ( ‘magic’, ‘magical’),
grep -C number pattern files : [number] ,
grep pattern1 | pattern2 files : pattern1 pattern2 ,
grep pattern1 files | grep pattern2 : pattern1 pattern2 。
:
< > 。
:
grep man * ‘Batman’、‘manic’、‘man’ ,
grep \'<man\' * ‘manic’ ‘man’, ‘Batman’,
grep \'<man>\' ‘man’, ‘Batman’ ‘manic’ 。
\'^\': ,
\'$\': ,
, ‘grep’, reXgrep 。 AND、OR、NOT , :-) 。 , fungrep 。
.grep
:
grep string filename
, M . pattern
. □ , :
^M M ,^
M$ M ,$
^[0-9] ,[]
^[124ab] 1,2,4,a, b
^b.503
* 0 ( )
+ 1
.
<eg> cat passwd | grep ^b
cat passwd | grep ^s
cat passwd | grep \'^b.503\' ...
grep \'^.\' myfile.txt
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1. grep
grep (global search regular expression(RE) and print out the line, ) , , 。Unix grep grep、egrep fgrep。egrep fgrep grep 。egrep grep , re , fgrep fixed grep fast grep, , , , 。linux GNU grep。 , -G、-E、-F egrep fgrep 。
grep , 。 , , 。 , 。
grep shell , grep , , 0, , 1, , 2。 。
2. grep ( )
^
:\'^grep\' grep 。
$
:\'grep$\' grep 。
:\'gr.p\' gr , p。
*
:\'*grep\' grep 。 .* 。
[]
, \'[Gg]rep\' Grep grep。
[^]
, :\'[^A-FH-Z]rep\' A-R T-Z , rep 。
(..)
, \'(love)\',love 1。
<
, :\'
>
, \'grep>\' grep 。
x{m}
x,m , :\'0{5}\' 5 o 。
x{m,}
x, m , :\'o{5,}\' 5 o 。
x{m,n}
x, m , n , :\'o{5,10}\' 5--10 o 。
w
, [A-Za-z0-9], :\'Gw*p\' G , p。
W
w , , 。
b
, : \'bgrepb\' grep。
3. egrep grep -E
+
。 :\'[a-z]+able\', able , loveable,enable,disable 。
?
。 :\'gr?p\' gr , p 。
a|b|c
a b c。 :grep|sed grep sed
()
, :love(able|rs)ov+ loveable lovers, ov。
x{m},x{m,},x{m,n}
x{m},x{m,},x{m,n}
4. POSIX
,POSIX(The Portable Operating System Interface) , [:alnum:] A-Za-z0-9 。 [] , [A- Za-z0-9] [[:alnum:]]。 linux grep fgrep , POSIX 。
[:alnum:]
[:alpha:]
[:digit:]
[:graph:]
( 、 )
[:lower:]
[:cntrl:]
[:print:]
( )
[:punct:]
[:space:]
( , , )
[:upper:]
[:xdigit:]
(0-9,a-f,A-F)
5. Grep
-?
? , :grep -2 pattern filename 2 。
-b,--byte-offset
。
-c,--count
, 。
-f File,--file=File
。 0 , 。
-h,--no-filename
, 。
-i,--ignore-case
。
-q,--quiet
, 。0 。
-l,--files-with-matches
。
-L,--files-without-match
。
-n,--line-number
。
-s,--silent
。
-v,--revert-match
, 。
-w,--word-regexp
< > , 。
-V,--version
。
6.
grep , , grep , , 。
$ ls -l | grep \'^a\'
ls -l , a 。
$ grep \'test\' d*
d test 。
$ grep \'test\' aa bb cc
aa,bb,cc test 。
$ grep \'[a-z]{5}\' aa
5 。
$ grep \'w(es)t.*1\' aa
west , es , 1, (.*), es(1), 。 egrep grep -E, "" , \'w(es)t.*1\' 。
find
·find path -option [ -print ] [ -exec -ok command ] {} \;
find ;
pathname: find 。 . , / 。
-print: find 。
-exec: find shell 。 'command' { } \;, { } \; 。
-ok: -exec , shell , , , 。
#-print
#-exec command {} \; —– command ,{} \;
#-ok -exec ,
:find . -name .svn | xargs rm -rf
====================================================
-name filename # filename
-perm #
-user username #
-group groupname #
-mtime -n +n # ,-n n ,+n n
-atime -n +n # GIN: 0px">
-ctime -n +n # ,-n n ,+n n
-nogroup # , /etc/groups
-nouser # , /etc/passwd
-newer f1 !f2 ,-n n ,+n n
-ctime -n +n # ,-n n ,+n n
-nogroup # , /etc/groups
-nouser # , /etc/passwd
-newer f1 !f2 # f1 f2
-type b/d/c/p/l/f # 、 、 、 、 、
-size n[c] # n [ n ]
-depth #
-fstype # f1 f2
-type b/d/c/p/l/f # 、 、 、 、 、
-size n[c] # n [ n ]
-depth #
-fstype # , /etc/fstab
-mount # mount
-follow # ,
-cpio %; # , /etc/fstab
-mount # mount
-follow # ,
-cpio # cpio ,
-prune #
=====================================================
$find ~ -name "*.txt" -print # $HOME .txt
$find . -name "*.txt" -print
$find . -name "[A-Z]*" -print #
$find /etc -name "host*" -print # host
$find . -name "[a-z][a-z][0–9][0–9].txt" -print # txt
$find . -perm 755 -print
$find . -perm -007 -exec ls -l {} \; # -perm 777
$find . -type d -print
$find . ! -type d -print
$find . -type l -print
$find . -size +1000000c -print # 1Mb
$find . -size 100c -print # 100c
$find . -size +10 -print # 10 (1 =512 )
$cd /
$find etc home apps -depth -print | cpio -ivcdC65536 -o /dev/rmt0
$find /etc -name "passwd*" -exec grep "cnscn" {} \; # cnscn
$find . -name "yao*" | xargs file
$find . -name "yao*" | xargs echo "" > /tmp/core.log
$find . -name "yao*" | xargs chmod o-w
======================================================
find -name april* april
find -name april* fprint file april , file
find -name ap* -o -name may* ap may
find /mnt -name tom.txt -ftype vfat /mnt tom.txt vfat
find /mnt -name t.txt ! -ftype vfat /mnt tom.txt vfat
find /tmp -name wa* -type l /tmp wa
find /home -mtime -2 /home
find /home -atime -1 1
find /home -mmin +60 /home 60
find /home -amin +30 30
find /home -newer tmp.txt /home tmp.txt
find /home -anewer tmp.txt /home tmp.txt
find /home -used -2 , 2
find /home -user cnscn /home cnscn
find /home -uid +501 /home 501
find /home -group cnscn /home cnscn
find /home -gid 501 /home id 501
find /home -nouser /home
find /home -nogroup /home
find /home -name tmp.txt -maxdepth 4 /home tmp.txt 3
find /home -name tmp.txt -mindepth 3 2
find /home -empty 0
find /home -size +512k 512k
find /home -size -512k 512k
find /home -links +2 2
find /home -perm 0700 700
find /tmp -name tmp.txt -exec cat {} \;
find /tmp -name tmp.txt -ok rm {} \;
find / -amin -10 # 10
find / -atime -2 # 48
find / -empty #
find / -group cat # groupcat
find / -mmin -5 # 5
find / -mtime -1 # 24
find / -nouser #
find / -user fred # FRED
# find . -type f -exec ls -l {} \;
-rw-r–r– 1 root root 34928 2003-02-25 ./conf/httpd.conf
-rw-r–r– 1 root root 12959 2003-02-25 ./conf/magic
-rw-r–r– 1 root root 180 2003-02-25 ./conf.d/README
, - e x e c ls -l
=================================================
/ l o g s 5 :
$ find logs -type f -mtime +5 -exec -ok rm {} \;
=================================================
[root@book class]# find ./ -mtime -1 -type f -exec ls -l {} \;
=================================================
[root@book class]# find ./ -mtime -1 -type f -ok ls -l {} \;
< ls … ./classDB.inc.php > ? y
-rw-r–r– 1 cnscn cnscn 13709 1 12 12:22 ./classDB.inc.php
[root@book class]# find ./ -mtime -1 -type f -ok ls -l {} \;
< ls … ./classDB.inc.php > ? n
[root@book class]#
=================================================
awk
[root@book class]# who | awk ’{print $1"\t"$2}’
cnscn pts/0
=================================================
awk—grep—sed
[root@book class]# df -k | awk ‘{print $1}’ | grep -v ’none’ | sed s"/\/dev\///g"
sda2
sda1
[root@book class]# df -k | awk ‘{print $1}’ | grep -v ’none’
/dev/sda2
/dev/sda1
1) /tmp *.h, “SYSCALL_VECTOR", "SYSCALL_VECTOR"
A) find /tmp -name "*.h" | xargs -n50 grep SYSCALL_VECTOR
B) grep SYSCALL_VECTOR /tmp/*.h | cut -d’:' -f1| uniq > filename
C) find /tmp -name "*.h" -exec grep "SYSCALL_VECTOR" {} \; -print
2)find / -name filename -exec rm -rf {} \;
find / -name filename -ok rm -rf {} \;
3) 3M :
find . -size +3000k -exec ls -ld {} ;
4) find
find *.c -exec cp ‘{}’ /tmp ‘;’
, cpio, :
find dir -name filename -print | cpio -pdv newdir
6) 2004-11-30 16:36:37
# A=`find ./ -name "*php"` | ls -l –full-time $A 2>/dev/null | grep "2004-11-30 16:36:37"
Linux-all, Linux | No Comments »
find
18th, 2006
/usr/linux *.h, “SYSCALL_VECTOR", "SYSCALL_VECTOR" ,
find /usr/linux -name "*.h" | xargs -n50 grep SYSCALL_VECTOR
grep SYSCALL_VECTOR /usr/linux/*.h | cut -d’:’ -f1 | uniq > filename
find /usr/linux -name "*.h" -exec grep "SYSCALL_VECTOR" {} \; -print
find / -name filename| rm -rf, , ?
find / -name filename -exec rm -rf {} \;
find . -name filename |rm -rf {} 。
\; “ ”, , , -exec 。 man find 。
rm find , :
find / -name filename |xargs rm -rf
find . -name filename |rm -rf , rm
"the string you want find…" :
$find . -type f -exec grep “the string you want find…” {} ; -print
tmpfile,
find / -name "tmpfile" -exec rm {} \;
find perm
? -,
find -name ".*" -perm -007
find -name ".*" -perm 755
755
, , find pathname find ?
-ok -exec, {} \; ?
, , -ok -exec , , E
-007 、 、 , ~~~
?
find -name ".*" -perm -007 find -name ".*" -perm 777 ?
-007 ?
find . -perm -100 . , ?
explover 2002/10/01 06:15am :
-007 、 、 , ~~~
-007 ( , ) , , . ,- 007.
2002/10/01 10:16am :
OK ,
find . -perm -100 . , ?
. -100 .
unix , . .
find . -perm -001 -print .
, -100
, -010 owner ? 010 - ,- , 010 ?
find ?
find *.c -exec cp ‘{}’ /tmp ‘;’
, cpio, :
find dir -name filename -print | cpio -pdv newdir
3M :
find . -size +3000k -exec ls -ld {} ;
find ?
:
A=`find ~ -print` | ls -l –full-time $A 2>/dev/null | grep "Jun 27" | grep 1998
find shell 。 11 12 。thanks
judgetime, :
ls -l $*|awk ‘{split($8,hour,":");if((hour[1]>23 || hour[1] < 1)&&hour[1]<24)print}’
,
find ./ -name "*" -exec judgetime {} \;
24 。
thank you ,
touch -t 04241112 starttemp # 12
touch -t 04241220 endtemp # 12 20
find [dir] -newer starttemp -a ! -newer endtemp -exec ls -l {} \;
newer?
12:10 ?
, ?
11:00~12:00 , ?
, 。
!
!
, , !
。 。 2002, 12:00.
12:00 !
find ./ -name -exec rm -f {} \;
: 30 , :
find / -atime +30 -exec rm -f {} \;
SHELL, ll ,grep, rm , 。
FOR , rm 。 SHELL n , , !
, "find / -atime +30 -exec rm -f {} \;
" , , , -atime n n , , n 。
、 "ll |cut -f 1" , ll , cut -f , ll |cut -c 59- ,but it’s a pool idear ! awk , , ,TKS SO MUCH
、 I :
-rw-r—– 1 msahz01 users 2253 2002 2 2 poheader.i
-rw-rw-rw- 1 house users 2193 Apr 19 2001 hkdisp.p
?
awk
ll | awk ‘{print $9}’
find /yourpath -mtime +31 -exec rm {} \;
find /yourpath -mtime +366 -exec rm {} \;
find , -ctime, -mtime -atime
-ctime -mtime ?
ctime , ctime ?
-ctime -mtime ,-atime ?
-mtime -1 .
mv ( , ) ?
-newer 。
touch :
$ touch -t 08190800 test
$ ls -l test
-rw-r–r– 1 dba other 0 Aug 19 08:00 test
$ find . -newer test -print
.
./.sh_history
$ ls -l .sh_history
-rw——- 1 dba other 154 Aug 20 17:39 .sh_history
touch , -newer ,! -newer 。
1.ctime inode .mtime .
2 .
3. .
-ctime inode ( ).
inode ?
,-mtime , -ctime .
, -ctime .
i-node ?
vi /usr/include/sys/inode.h
, access /usr/include/sys/inode.h .
:
Directories contain directory entries. Each entry contains a file or subdirectory name and an index node reference number (i-node number). To increase speed and enhance use of disk space, the data in a file is stored at various locations in the computer’s memory. The i-node contains the addresses used to locate all the scattered blocks of data associated with a file. The i-node also records other information about the file including time of modification and access, access modes, number of links, file owner, and file type.
-atime , -ctime . why ?
( cat ASCII , -atime -1 -ctime -1 .)
inode , ctime ?
, ,atime,ctime,mtime , sco unix stat .(stat_32), .
sco inode :
typedef struct inode
{
struct inode *i_forw; /* inode hash chain */
struct inode *i_back; /* ‘’ */
struct inode *av_forw; /* freelist chain */
struct inode *av_back; /* ‘’ */
int *i_fsptr; /* "typeless" pointer to fs dependent */
ino32_t i_number; /* i number, 1-to-1 with dev address */
ushort i_ftype; /* file type = IFDIR, IFREG, etc. */
short i_fstyp; /* File system type */
off_t i_size; /* size of file */
ushort i_uid; /* owner */
ushort i_gid; /* group of owner */
ushort i_flag;
ushort i_want; /* i_flag extension to avoid MP races */
ushort i_count; /* reference count */
short i_nlink; /* directory entries */
dev_t i_rdev; /* Raw device number */
#define i_namtype i_rdev /* i_ftype==IFNAM subtype */
dev_t i_dev; /* device where inode resides */
struct mount *i_mton;/* ptr to mount table entry that */
/* this directory is mounted on */
struct region *i_rp; /* ptr to shared region if any */
struct stdata *i_sp; /* ptr to associated stream */
struct iisem *isem; /* ptr to XENIX semaphores */
struct iisd *isd; /* ptr to XENIX shared data */
} i_un;
#define i_mnton i_un.i_mton /* i_ftype==IFDIR IMOUNT */
#define i_rptr i_un.i_rp /* i_ftype==IFREG || i_ftype==IFBLK */
#define i_sptr i_un.i_sp /* i_ftype==IFCHR || i_ftype==IFIFO */
#define i_sem i_un.isem /* i_ftype==IFNAM && i_namtype==IFSEM */
#define i_sd i_un.isd /* i_ftype==IFNAM && i_namtype==IFSHD */
struct fstypsw *i_fstypp; /* ptr to file system switch FSPTR */
long *i_filocks; /* pointer to filock (structure) list */
unsigned long i_mappages; /* number of pages currently cached */
unsigned long i_vcode; /* read-ahead block save (NFS) */
short i_wcnt; /* write open count or ITEXT count */
struct lockb i_cilock; /* tas to synchronize i_flag changes */
ushort i_rdlocks; /* count of non-exclusive lockers */
} inode_t;
, inode .
chown, chgrp, chmod mtime ctime
chown , ctime , mtime .
.
! Solaris . -ctime .
:
,-mtime , -ctime .
,-atime , -ctime .
chown, chgrp, chmod,mv, -ctime , -atime -mtime.
touch -mtime and/or -atime, touch -a ,-ctime .
touch -m ,-ctime .
-ctime , .
-mtime,atime,ctime ?
-ctime transfer ?
!
,( )
st_mtime st_ctime, st_atime .
#include
int
main (int argc, char **argv)
{
struct stat buf;
char date[80];
char fname[80];
printf("Enter filename (with full path) to check mtime : ");
scanf("%s",fname);
stat(fname, &buf);
printf ("mtime (in sec) of %s = %ld
", fname, buf.st_mtime);
strcpy(date, ctime((time_t *)&(buf.st_mtime)));
printf ("mtime (in date) of %s = %s
", fname, date);
}
, ?
mtime ls -l
atime ls -lu
ctime ls -li , , \ , , ,
ls , ctime atime , mtime.
,ayhan . ayhan.
ahyan ! Solaris :
mtime ls -l
atime ls -lu
ctime ls -lc . (ls -li inode number)
:
-c Uses time of last modification of the i-node (file
created, mode changed, and so forth) for sorting (-t)
or printing (-l or -n).
-u Uses time of last access instead of last modification
for sorting (with the -t option) or printing (with the
-l option).
-i For each file, prints the i-node number in the first
column of the report.
grep 일반 명령
이 --include 옵션은 다음과 같이 사용할 수 있습니다.
grep -rn --include='*.c' --include='*.h' re .여러 번 지정할 수 있습니다. 만약에 정말 위의 경우라면grep-rn--include='*.[ch]' re .그러나 원본 파일에 C++ 원본 코드가 포함되어 있으면 위의 방법은 효과가 없습니다. 왜냐하면 [] 에는 한 문자만 넣을 수 있기 때문입니다.grep -rn --include='*.{cpp,h}'도 안 돼요.이때 인용부호를 넣지 않은 전개(bash에서grep를 실행하기 전에 이미 완성되어 set-x를 통해 관찰할 수 있음)grep-rn--include=*가 필요합니다.{cpp,h} re .bash에서 {A, B} 형식의 전개는 현재 디렉터리에 해당하는 파일이 있는지 무시합니다.이런 작법은 명령행에 손가락이 지치는 것을 피할 수 있다.
강조 표시
grep --color=auto 'pattern' 'text'
echo-e'\e[34mhaha\e[m'이렇게 하면 색이 있는 문자열-e가 출력되어 특수 처리를 나타냅니다\e 이\e는 반드시 [기호를 따라야 합니다
grep 상용
grep [-acinv]'검색 문자열'filename
매개변수 설명:
-a:binary 파일을text 파일로 데이터 찾기
-c: 검색 문자열 찾기 횟수 계산
-i: 대소문자가 다른 것은 무시하므로 대소문자는 동일하게 취급
-n: 줄 번호 출력하기
- v: '검색 문자열' 내용이 없는 줄을 반대로 선택하십시오!
1. 특정 문자 검색
grep'oo'pp.txt 다음은 ppp로만 pp.txt를 대표합니다
표시된 문자의 행 수 보기
grep -n 'oo' pp
oo가 아닌 문자 보기
grep -v 'oo' pp
대소문자 무시 문자 보기
grep -i 'oo' p
2. []를 이용하여 검색 결과 처리
tast와test의 문자열 보기
grep-n't[ae]st'pp 여기[ae]는 한 글자로 a나 e를 처리하면 위의 요구에 일치할 수 있다
t(x)st와 일치하기를 원한다면 이 x가 임의의 문자라면 다음과 같이 처리할 수 있습니다
grep 't[.]st' pp .기호는 임의의 문자를 대표한다
oo 문자가 포함된 정보 보기
grep -n 'oo' pp
만약 oo 이전에 g의 문자 정보가 없기를 원한다면
grep-n'[^g]oo'pp 여기 있는 ^는 거꾸로 하면 goo 문자가 아니라는 뜻이에요.
앞의 문자가 아닌 문자를 찾습니다
grep -n '[^a-zA-Z]oo' pp
숫자의 문자를 얻으면
grep-n'[0-9]'pp//사실 이것은 grep-n'[0-9[0-9]*'pp*와 같은 0개 또는 여러 개의 중복된 정보를 대표한다
3. 줄 시작과 줄 끝의 특수 처리 $^
첫 줄이 the로 시작하는 문자 줄을 원한다면
grep -n '^the' pp
영문으로 시작하는 문자를 원한다면
grep -n '^[a-zA-Z]' pp
영문자로 시작하지 않은 정보를 얻다
grep-n'^[^a-zA-Z]'pp//안에 있는^는 바깥쪽을 반으로 하는^는 위로 시작합니다
소수점 끝 행 가져오기
grep -n '\.$' pp//소수점은 특수 문자이므로\로 전의해야 합니다
윈도우즈에서 줄을 바꿀 때 ^M 기호를 주의하십시오
공행 방식을 얻다
grep - n'^$'pp 여기는 빈 줄입니다.
모든 문서에서 주석이 아닌 내용을 얻으려면 다음과 같습니다
grep-v'^$'pp|grep-v^# 첫 번째는 비어 있는 데이터를 찾습니다 첫 번째 파이프는 비어 있는 데이터를 찾습니다
저는 가끔 #로 시작하는 줄이 더 많아요.
grep -n '^#' pp
4. 모든 문자 및 반복 문자
.: 절대 임의의 문자
*: 0자 이상의 동일 문자
gf 중간에 두 문자의 데이터를 보려면
grep -n 'g..f' pp
적어도 하나는 o 문자열
grep-n'oo*'pp//왜냐하면 *는 0 개 또는 여러 개를 대표하기 때문이다
g로 시작하고 끝내고 중간에 최소한 o
grep -n 'goo*g'
gg 중간에 임의의 문자가 있는 문자열 찾기
grep - n'g.*g'pp 여기.모든 문자를 나타냅니다.
5.한정자{}
g와 p 사이에 두 개의 o가 연결된 문자열을 보기
grep -n 'go\{2,5\}p'
최소 두 개의 문자 창 찾기
grep -n 'go\{2,\}p' pp
두 개의 문자열만 찾기
grep -n 'go\{2\}p' pp
6. 중요한 특수 문자
^word 검색할 문자열(word)이 줄 맨 앞에 있습니다!
범례:grep-n'^#'pp 검색 줄의 첫 번째 줄은 #로 시작하는 줄입니다!
word$검색할 문자열(word)이 줄 끝에 있습니다!
예:grep-n'!$'pp는 줄 끝을!그 줄을 프린트해라!
. 문자를 나타냅니다.
예제grep - n'g.'pp는 g로 시작하는 두 문자를 출력합니다
\특수 문자 이스케이프
예: grep -n\'pp는 작은 따옴표가 있는 줄을 검색합니다.
*: 0자 이상 일치
grep-n'o*'pp는 0개 혹은 여러 개의 o를 가진 문자와 일치합니다
{n, m\}: 일치하는 개수
grep-n'o\{2\}'pp에서 두 개의oo 문자를 출력합니다
[] 단일 문자 일치
1.[list]: [abl]은 abl 중 어느 하나와 일치합니다
2.[^xx]: 그중의 문자를 반올림합니다. 여기는 그 문자만 반올림할 수 있습니다.
3.[char1-char2]: 특정 범위 내의 데이터와 일치합니다. 예를 들어 [a-z][A-Z][0-9]
7. 확장된grep--->egrep 이것은grep-E와 같다
grep -v '^$' pp | grep -v '^#'
egrep을 통해서 표현하자면...
egrep -v '^$|^'
8. 찾을 내용에 "또는"관계가 있습니다.
# 23 또는 24의 컨텐트를 찾고 컨텐트 및 행 번호를 표시합니다.
grep -E '23|24' * -n
9. 데이터를 찾습니다.txt 파일의 빈 행 수:
grep '^$' data.txt -c
10. 현재 디렉터리에 몇 개의 디렉터리가 있는지 조회하기:
ls -l | grep '^d'
11. 데이터를 찾습니다.txt 파일 문자열 끝부분이 a인 내용
grep 'a$' data.txt -i -n
$grep "sort it"* (# 또는 모든 파일에서 단어 "sort it"를 검색)
다음 예는 단일 파일에서 $grep-c "48"데이터와 일치하는 검색줄을 가리킨다.f$4 (#g r e p는 숫자 4를 반환하며, 문자열 "4 8"을 포함하는 4행을 의미합니다.)$grep "48"data.f(# 4-8 문자열이 포함된 4줄 텍스트 표시)
일치 모드에 맞는 모든 줄 수를 표시합니다: [root@mypc oid2000]# grep -n 1234 111.txt 1:12343:1234ab
6. 정확히 일치[root@mypc oid2000]# grep "1234\>"111.txt 1234
7. 빈 줄을 조회한다. 어떤 조건으로 시작하거나 끝나는 줄을 조회한다.^와 $를 결합하면 빈 줄을 조회할 수 있습니다.- n 매개변수를 사용하여 실제 행 수를 표시하십시오[root@mypc oid2000]# grep -n "^$"111.txt(반환 결과 2: # 두 번째 줄이 빈 줄이라는 뜻)[root@mypc oid2000]# grep -n "^abc"111.txt(# abc로 시작하는 줄 조회)[root@mypc oid2000]# grep -n "abc$"111.txt(# 질의 abc로 끝나는 행)
8. 특수 문자와 일치하며 $. 같은 특수 의미를 가진 문자를 조회합니다. '"* [] ^ |\+?, 특정 문자 앞에\를 입력해야 합니다.[root@mypc oid2000]# grep "\."111.txt(# 111.txt에'.'쿼리 포함의 모든 행)[root@mypc oid2000]# grep "my\.conf"111.txt(#파일 이름 my. c o n f가 있는 줄 조회)
9. 디렉터리 조회[root@mypcoid2000]#ls–l|grep"^d"(#디렉터리 목록에 있는 디렉터리를 조회하려면)[root@mypcoid2000]#ls–l|grep"^d[d]"(#한 디렉터리에 디렉터리가 포함되지 않은 모든 파일을 조회)[root@mypc] # ls – l | grep "^d.....x.x"(# 다른 사용자와 사용자 그룹 구성원에게 실행 가능한 권한이 있는 디렉터리 집합 조회)
10. 자신을 배제한다
ps-ef|grep telnet | grep-v grep (표시되는 프로세스에서 "telnet"프로세스를 추출하고 ps의grep 프로세스를 버려라)
egrep의 몇 개의 특수 문자
+: 최소한 하나 이상의 egrep - n'go+d'pp
?:0 개 혹은 하나의egrep - n'go?d' pp
|: 또는 같은 방법으로 egrep-n'go|good'pp 찾기 go 또는 good
(): 그룹의 데이터를 찾아내는 egrep - n'g (o|pp) d'pp god나 gppd 이것은 []와 유사하지만 []보다 강한 것은 여러 문자로 바꿀 수 있다
egrep -n 'd(r|o)e' pp ===== grep -n 'd[ro]e' pp
find grep
find
find . , Linux , , , , .
, . wish. root , :
grep
grep , , (General Regular Expression Parser). find , grep . , find grep -exec.
:
find :
grep:
Linux find grep
1.find:
: find
: /root/luojiahui index.htm
find /root/luojiahui index.htm
"c" ( -print )
find . -name "*.c"
find bootable kernel -name "*.c"
2.grep:
:grep
:grep success luojiahui.txt
luojiahui.txt success
grep -r " " *
grep -r dump_info /home/zhenwx/kernel
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
jquery가 사용되는 루트 디렉토리 이하, 모든 파일을 표시하는 명령운영중인 웹 사이트에서 JQuery 버전을 업데이트하기 위해 영향 범위를 확인하는 작업이 있으며 jQuery 코드가 작성된 파일을 모두 파악해야 했으므로 여기에 메모를 둡니다. jQuery의 코드는 $( 와 jQue...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.