나스나 서버에서 파일 관리를 할 때 자주 사용하는 명령어가 find이다. 기억하려고 해도 자꾸 잊어버리는 탓에 기록용으로 남겨두고자 한다.
1. 이름으로 찾기(-name)
이름으로 찾기는 폴더인지 파일인지 구별하지 않는다. 따라서 정확한 서칭이 필요하다면 이름으로만 찾으면 안 된다.
찾고자 하는 파일 이름을 gumu.jpg 라고 할 때 현재 디렉토리에서 찾을 때
find . -name gumu.jpg
찾고자 하는 파일 이름을 gumu.jpg 라고 할 때 /volume1 디렉토리에서 찾을 때
find /volume1 -name gumu.jpg
대소문자 구분 없이 gumu.jpg를 현재 디렉토리에서 찾을 때
find . -iname gumu.jpg
2. 파일 찾기(-type f)
찾고자 하는 파일 이름을 gumu.zip 라고 하고 현재 디렉토리에서 찾을 때
파일의 타입인 f를 명시해준다.
find . -type f -name gumu.zip
현재 디렉토리 내 모든 .zip파일 찾기
find . -type f -name "*.zip"
현재 디렉토리 내 모든 .zip파일 또는 .pdf파일을 한꺼번에 찾기
(OR을 의미하는 -o 를 붙여준다)
find . -type f \( -name "*.zip" -o -name "*.pdf" \)
3. 폴더 찾기(-type d)
여기서는 디렉토리보다는 폴더라고 하는 것이 윈도우 사용자에게 익숙할 것 같아서 폴더 찾기라고 명명한다.
현재 디렉토리 내 모든 폴더 찾기
find . -type d #주의! 이 명령어는 현재 폴더도 포함한다.
#결과는 아래와 같이 나온다.
.
./01test
./02test
./03test
현재 폴더를 제외하고 디렉토리 내 모든 폴더 찾기
find . ! -path . -type d
#결과는 아래와 같이 나온다.
./01test
./02test
./03test
현재 디렉토리 상에서 탐색 단계별로 폴더 찾기
예를 들어, /volume1/Test/Practice라는 폴더 구조로 되어 있고 현재 디렉토리는 /volume1 일 때 Test폴더 안에 있는 폴더만 찾고 싶다면 최소 2단계는 내려가고 더 이상의 탐색을 하면 안 된다.
최소한의 depth설정을 -mindepth
최대한의 depth설정을 -maxdepth로 설정해준다.
파일 찾기에서도 응용이 가능하다.
find . -mindepth 2 -maxdepth 2 -type d
#이렇게 되면 Test내 폴더만 탐색하고 Test내 폴더 안에 있는 폴더는 탐색하지 않는다.
gumu라는 폴더 찾기
find . -type d -name "gumu"
4. find의 응용(-exec)
find 명령어를 사용하여 나오는 결과값은 {}로 다양하게 활용 가능하다. -exec 뒤에는 우리가 평소에 쓰던 쉘 스크립트를 넣을 수 있다. 예를 들어서 특정 폴더 안에 있는 모든 폴더를 삭제하고 싶다면 아래와 같은 스크립트를 사용하면 된다.
find . -mindepth 2 -type d -exec rm -r {} \;
-exec 뒤에 디렉토리 삭제를 위한 rm -r 을 넣었고 그 뒤에 {}를 넣어주면 find명령어로 찾은 결과값이 rm -r 뒤에 순차적으로 들어가게 된다. 반드시 명령어 끝에는 (공백)\;를 넣어주어야 한다.
만일 특정 경로에 있는 폴더들을 압축하고 싶다면 아래와 같은 스크립트를 사용하자.
find . -mindepth 2 -type d -exec zip -r {}.zip {} \;
52개의 댓글
hot shot bald cop · 2022-04-09 2:16 오전
I was just telling my friend about that.
hotshot bald cop · 2022-04-12 7:12 오전
I didn’t know that.
hotshot bald cop · 2022-04-12 7:24 오전
Wonderful views on that!
hotshot bald cop · 2022-05-07 10:10 오후
I was just telling my friend about that.
💟 Kathy just viewed your profile! More info: https://letsg0dancing.page.link/go?hs=db632b911b422851cb5db208115a1f70& 💟 · 2022-08-08 1:37 오후
1vd585
😍 Lori sent you a private message! View Message: https://letsg0dancing.page.link/go?hs=db632b911b422851cb5db208115a1f70& 😍 · 2022-08-25 11:39 오후
9y5t2m
graliontorile · 2022-11-22 1:25 오전
I am not really good with English but I line up this real leisurely to interpret.
Davidamire · 2023-01-22 5:10 오후
https://drugsoverthecounter.shop/# over the counter nausea medicine for pregnancy
WillieKef · 2023-02-08 10:04 오전
Get warning information here. Get here.
cost cheap nexium without insurance
Everything information about medication. Best and news about drug.
esurance quotes · 2023-02-09 11:26 오전
You are my aspiration, I have few blogs and very sporadically run out from to post .
JamesBot · 2023-02-10 7:56 오후
Drug information. Top 100 Searched Drugs. https://avodart.science/# can i get cheap avodart without a prescription
Get warning information here. Get information now.
DonaldJep · 2023-02-10 9:39 오후
Read here. Drugs information sheet. how can i get generic avodart without a prescription
Commonly Used Drugs Charts. Everything about medicine.
Jamesricle · 2023-02-11 6:21 오전
Get warning information here. Get here. https://avodart.science/# can i get generic avodart
All trends of medicament. п»їMedicament prescribing information.
กานต์กนิษฐ์ · 2023-02-15 7:11 오후
I’m commenting to let you understand what a beneficial encounter our daughter experienced browsing the blog. She came to understand lots of pieces, which included how it is like to have a great coaching character to get most people effortlessly fully grasp chosen tortuous things. You actually exceeded her desires. Thanks for offering the invaluable, dependable, revealing as well as unique guidance on your topic to Mary.
EfrenBeils · 2023-02-16 11:46 오후
Generic Name. Some trends of drugs.
https://edonlinefast.com best ed pill
Read information now. Medscape Drugs & Diseases.
MortonBiali · 2023-02-17 5:30 오전
drug information and news for professionals and consumers. safe and effective drugs are available.
treatment of ed
Drug information. earch our drug database.
RobertGed · 2023-02-17 7:51 오전
What side effects can this medication cause? safe and effective drugs are available.
https://edonlinefast.com ed meds online
п»їMedicament prescribing information. Generic Name.
Philipgrali · 2023-02-18 3:06 오전
Read now. Drug information.
ed pills
Learn about the side effects, dosages, and interactions. Medicament prescribing information.
RobertGed · 2023-02-20 12:08 오후
Some are medicines that help people when doctors prescribe. Get here.
canadianpharmacy com
What side effects can this medication cause? Long-Term Effects.
VictorCit · 2023-02-21 12:00 오전
Top 100 Searched Drugs. Commonly Used Drugs Charts.
https://canadianfast.online/# prescription drugs online without
Commonly Used Drugs Charts. Read here.
Edgardix · 2023-02-21 2:10 오후
Learn about the side effects, dosages, and interactions. Actual trends of drug.
https://canadianfast.online/# how can i order prescription drugs without a doctor
Drugs information sheet. All trends of medicament.
MichaelRot · 2023-02-21 11:41 오후
Read information now. Learn about the side effects, dosages, and interactions.
https://canadianfast.online/# pet meds without vet prescription canada
Prescription Drug Information, Interactions & Side. Drugs information sheet.
Desentupimento de Coletora · 2023-02-24 6:31 오후
Very instructive and excellent complex body part of articles, now that’s user pleasant (:.
passeio porto seguro praia do espelho · 2023-02-25 4:11 오전
Some really interesting info , well written and generally user pleasant.
tendaggi · 2023-02-26 10:48 오후
Some really nice and useful information on this site, besides I think the design has got good features.
tende a vetro · 2023-02-26 11:45 오후
I like this site so much, saved to bookmarks.
tendaggi · 2023-02-27 1:02 오전
so much good information on here, : D.
tende a vetro · 2023-02-27 5:09 오전
I’ve been absent for some time, but now I remember why I used to love this blog. Thank you, I will try and check back more often. How frequently you update your site?
tende a vetro · 2023-02-27 6:29 오전
Very interesting information!Perfect just what I was looking for! “The most wasted day of all is that on which we have not laughed.” by Sbastien-Roch Nicolas de Chamfort.
moonriver token · 2023-03-02 4:33 오후
I have not checked in here for some time because I thought it was getting boring, but the last several posts are good quality so I guess I will add you back to my everyday bloglist. You deserve it my friend 🙂
hire a hacker dark web · 2023-03-05 12:32 오전
Hello. impressive job. I did not expect this. This is a splendid story. Thanks!
plazo para impugnar acta comunidad de propietarios · 2023-03-07 6:04 오후
so much wonderful info on here, : D.
iguala juridica precio · 2023-03-07 6:48 오후
You actually make it seem really easy along with your presentation but I in finding this topic to be really one thing that I believe I’d never understand. It kind of feels too complex and extremely extensive for me. I am having a look forward to your next submit, I’ll attempt to get the dangle of it!
Disolución de proindiviso · 2023-03-07 9:44 오후
Very interesting information!Perfect just what I was looking for!
swimming pool companies near me · 2023-03-08 4:26 오후
I like this site very much, Its a rattling nice place to read and receive information.
https://ssupportsdrivers.com/brother-mfc-l2720dw-driver/ · 2023-03-09 6:41 오전
You are a very smart person!
atm tratamento · 2023-03-09 1:17 오후
You are my aspiration, I have few blogs and infrequently run out from to post .
taxi Nice airport transfers · 2023-03-09 9:03 오후
Regards for this post, I am a big big fan of this site would like to go on updated.
slot maxwin hari ini · 2023-03-10 4:34 오전
I respect your piece of work, regards for all the great content.
situs gacor hari ini · 2023-03-10 3:15 오후
It’s exhausting to search out educated folks on this matter, however you sound like you already know what you’re speaking about! Thanks
Shorts Infanto Juvenil Feminino · 2023-03-13 1:22 오전
Well I sincerely liked reading it. This post offered by you is very helpful for proper planning.
Sox 4 Horses Bed Sores · 2023-03-14 7:36 오후
Way cool, some valid points! I appreciate you making this article available, the rest of the site is also high quality. Have a fun.
Déménagement France suisse · 2023-03-16 4:39 오전
Hello. remarkable job. I did not imagine this. This is a splendid story. Thanks!
Podiatry Clinic Solihull · 2023-03-18 4:38 오후
It’s hard to find knowledgeable people on this topic, but you sound like you know what you’re talking about! Thanks
AI · 2023-03-19 2:10 오전
I’ve been absent for some time, but now I remember why I used to love this blog. Thank you, I?¦ll try and check back more frequently. How frequently you update your website?
เซรั่มลดริ้วรอย · 2023-03-19 1:45 오후
Excellent read, I just passed this onto a friend who was doing a little research on that. And he actually bought me lunch because I found it for him smile So let me rephrase that: Thank you for lunch!
vender ouro · 2023-03-22 2:11 오후
This really answered my problem, thank you!
隆亨娛樂城 · 2023-03-23 3:23 오후
I am always invstigating online for ideas that can aid me. Thank you!
นักสืบเอกชน · 2023-03-24 10:23 오전
But wanna input on few general things, The website layout is perfect, the written content is rattling wonderful. “The sun sets without thy assistance.” by The Talmud.
libid gel · 2023-03-24 10:11 오후
Way cool, some valid points! I appreciate you making this article available, the rest of the site is also high quality. Have a fun.
Blog Militer · 2023-03-25 9:02 오전
Excellent read, I just passed this onto a friend who was doing a little research on that. And he actually bought me lunch as I found it for him smile So let me rephrase that: Thank you for lunch!
Internado Espana · 2023-03-26 2:55 오전
Real informative and great body structure of articles, now that’s user friendly (:.