
{"id":251,"date":"2025-11-27T10:08:58","date_gmt":"2025-11-27T03:08:58","guid":{"rendered":"https:\/\/uynghi.com\/?p=251"},"modified":"2025-11-27T10:11:21","modified_gmt":"2025-11-27T03:11:21","slug":"lenh-find-tim-kiem-trong-linux","status":"publish","type":"post","link":"https:\/\/uynghi.com\/lenh-find-tim-kiem-trong-linux\/","title":{"rendered":"L\u1ec7nh Find (t\u00ecm ki\u1ebfm) trong Linux"},"content":{"rendered":"\n<p>L\u1ec7nh\u00a0<code>find<\/code>\u00a0trong Linux l\u00e0 m\u1ed9t ti\u1ec7n \u00edch m\u1ea1nh m\u1ebd d\u00f9ng \u0111\u1ec3 t\u00ecm ki\u1ebfm t\u1ec7p tin ho\u1eb7c th\u01b0 m\u1ee5c d\u1ef1a tr\u00ean nhi\u1ec1u ti\u00eau ch\u00ed kh\u00e1c nhau nh\u01b0\u00a0<strong>t\u00ean, lo\u1ea1i, k\u00edch th\u01b0\u1edbc, ng\u00e0y th\u00e1ng v\u00e0 quy\u1ec1n<\/strong>. N\u00f3 th\u1ef1c hi\u1ec7n t\u00ecm ki\u1ebfm theo th\u1eddi gian th\u1ef1c, b\u1eaft \u0111\u1ea7u t\u1eeb m\u1ed9t th\u01b0 m\u1ee5c \u0111\u01b0\u1ee3c ch\u1ec9 \u0111\u1ecbnh.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">C\u00fa ph\u00e1p c\u01a1 b\u1ea3n<\/h2>\n\n\n\n<p>C\u00fa ph\u00e1p chung l\u00e0&nbsp;<code>find [th\u01b0 m\u1ee5c b\u1eaft \u0111\u1ea7u] [t\u00f9y ch\u1ecdn] [bi\u1ec3u th\u1ee9c]<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">C\u00e1c th\u01b0 m\u1ee5c b\u1eaft \u0111\u1ea7u ph\u1ed5 bi\u1ebfn bao g\u1ed3m:<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>~<\/code>\u00a0(d\u1ea5u ng\u00e3): T\u00ecm ki\u1ebfm t\u1eeb th\u01b0 m\u1ee5c ch\u00ednh c\u1ee7a b\u1ea1n (home directory).<\/li>\n\n\n\n<li><code>.<\/code>\u00a0(d\u1ea5u ch\u1ea5m): T\u00ecm ki\u1ebfm t\u1eeb th\u01b0 m\u1ee5c hi\u1ec7n t\u1ea1i.<\/li>\n\n\n\n<li><code>\/<\/code>\u00a0(d\u1ea5u g\u1ea1ch ch\u00e9o): T\u00ecm ki\u1ebfm to\u00e0n b\u1ed9 h\u1ec7 th\u1ed1ng, b\u1eaft \u0111\u1ea7u t\u1eeb th\u01b0 m\u1ee5c g\u1ed1c.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">V\u00ed d\u1ee5 v\u1ec1 c\u00e1c l\u1ec7nh&nbsp;<code>find<\/code>&nbsp;ph\u1ed5 bi\u1ebfn<\/h2>\n\n\n\n<p>D\u01b0\u1edbi \u0111\u00e2y l\u00e0 m\u1ed9t s\u1ed1 c\u00e1ch s\u1eed d\u1ee5ng&nbsp;<code>find<\/code>&nbsp;ph\u1ed5 bi\u1ebfn nh\u1ea5t:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><th>M\u00f4 t\u1ea3<\/th><th>L\u1ec7nh<\/th><th>Gi\u1ea3i th\u00edch<\/th><\/tr><tr><td><strong>T\u00ecm t\u1ec7p theo t\u00ean<\/strong><\/td><td><code>find \/home\/user -name filename.txt<\/code><\/td><td>T\u00ecm ki\u1ebfm t\u1ec7p c\u00f3 t\u00ean&nbsp;<code>filename.txt<\/code>&nbsp;trong th\u01b0 m\u1ee5c&nbsp;<code>\/home\/user<\/code>.<\/td><\/tr><tr><td><strong>T\u00ecm kh\u00f4ng ph\u00e2n bi\u1ec7t ch\u1eef hoa\/th\u01b0\u1eddng<\/strong><\/td><td><code>find . -iname filename.txt<\/code><\/td><td>T\u00ecm ki\u1ebfm t\u1ec7p trong th\u01b0 m\u1ee5c hi\u1ec7n t\u1ea1i (<code>.<\/code>) kh\u1edbp v\u1edbi&nbsp;<code>filename.txt<\/code>, b\u1ecf qua ph\u00e2n bi\u1ec7t ch\u1eef hoa\/th\u01b0\u1eddng (v\u00ed d\u1ee5: t\u00ecm th\u1ea5y&nbsp;<code>Filename.txt<\/code>,&nbsp;<code>FILENAME.TXT<\/code>, v.v.).<\/td><\/tr><tr><td><strong>T\u00ecm t\u1ec7p theo ph\u1ea7n m\u1edf r\u1ed9ng<\/strong><\/td><td><code>find \/path\/to\/dir -name \"*.log\"<\/code><\/td><td>S\u1eed d\u1ee5ng k\u00fd t\u1ef1 \u0111\u1ea1i di\u1ec7n (<code>*<\/code>) \u0111\u1ec3 t\u00ecm t\u1ea5t c\u1ea3 c\u00e1c t\u1ec7p c\u00f3 ph\u1ea7n m\u1edf r\u1ed9ng l\u00e0&nbsp;<code>.log<\/code>&nbsp;trong th\u01b0 m\u1ee5c \u0111\u00e3 ch\u1ec9 \u0111\u1ecbnh.<\/td><\/tr><tr><td><strong>Ch\u1ec9 t\u00ecm th\u01b0 m\u1ee5c<\/strong><\/td><td><code>find . -type d -name \"project*\"<\/code><\/td><td>T\u00ecm ki\u1ebfm c\u00e1c m\u1ee5c c\u00f3 lo\u1ea1i&nbsp;<code>d<\/code>&nbsp;(th\u01b0 m\u1ee5c) b\u1eaft \u0111\u1ea7u b\u1eb1ng &#8220;project&#8221; trong th\u01b0 m\u1ee5c hi\u1ec7n t\u1ea1i.<\/td><\/tr><tr><td><strong>Ch\u1ec9 t\u00ecm t\u1ec7p<\/strong><\/td><td><code>find . -type f -name \"*.jpg\"<\/code><\/td><td>T\u00ecm ki\u1ebfm c\u00e1c m\u1ee5c c\u00f3 lo\u1ea1i&nbsp;<code>f<\/code>&nbsp;(t\u1ec7p) c\u00f3 ph\u1ea7n m\u1edf r\u1ed9ng l\u00e0&nbsp;<code>.jpg<\/code>&nbsp;trong th\u01b0 m\u1ee5c hi\u1ec7n t\u1ea1i.<\/td><\/tr><tr><td><strong>T\u00ecm theo k\u00edch th\u01b0\u1edbc<\/strong><\/td><td><code>find . -size +10M<\/code><\/td><td>T\u00ecm c\u00e1c t\u1ec7p l\u1edbn h\u01a1n 10 Megabyte trong th\u01b0 m\u1ee5c hi\u1ec7n t\u1ea1i. (S\u1eed d\u1ee5ng&nbsp;<code>c<\/code>&nbsp;cho byte,&nbsp;<code>k<\/code>&nbsp;cho kilobyte,&nbsp;<code>M<\/code>&nbsp;cho megabyte,&nbsp;<code>G<\/code>&nbsp;cho gigabyte).<\/td><\/tr><tr><td><strong>T\u00ecm theo th\u1eddi gian s\u1eeda \u0111\u1ed5i<\/strong><\/td><td><code>find . -mtime -7<\/code><\/td><td>T\u00ecm c\u00e1c t\u1ec7p \u0111\u00e3 \u0111\u01b0\u1ee3c s\u1eeda \u0111\u1ed5i trong v\u00f2ng 7 ng\u00e0y qua. (S\u1eed d\u1ee5ng&nbsp;<code>+<\/code>&nbsp;cho c\u00e1c t\u1ec7p \u0111\u00e3 s\u1eeda \u0111\u1ed5i c\u00e1ch \u0111\u00e2y h\u01a1n 7 ng\u00e0y).<\/td><\/tr><tr><td><strong>T\u00ecm theo quy\u1ec1n<\/strong><\/td><td><code>find . -perm 644<\/code><\/td><td>T\u00ecm ch\u00ednh x\u00e1c c\u00e1c t\u1ec7p c\u00f3 quy\u1ec1n&nbsp;<code>644<\/code>&nbsp;trong th\u01b0 m\u1ee5c hi\u1ec7n t\u1ea1i.<\/td><\/tr><tr><td><strong>T\u00ecm t\u1ec7p\/th\u01b0 m\u1ee5c r\u1ed7ng<\/strong><\/td><td><code>find . -empty<\/code><\/td><td>Li\u1ec7t k\u00ea t\u1ea5t c\u1ea3 c\u00e1c t\u1ec7p v\u00e0 th\u01b0 m\u1ee5c r\u1ed7ng trong th\u01b0 m\u1ee5c hi\u1ec7n t\u1ea1i.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">K\u1ebft h\u1ee3p&nbsp;<code>find<\/code>&nbsp;v\u1edbi c\u00e1c l\u1ec7nh kh\u00e1c<\/h2>\n\n\n\n<p>L\u1ec7nh&nbsp;<code>find<\/code>&nbsp;th\u01b0\u1eddng \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng v\u1edbi t\u00f9y ch\u1ecdn&nbsp;<code>-exec<\/code>&nbsp;\u0111\u1ec3 th\u1ef1c hi\u1ec7n m\u1ed9t h\u00e0nh \u0111\u1ed9ng tr\u00ean c\u00e1c t\u1ec7p m\u00e0 n\u00f3 t\u00ecm th\u1ea5y.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>T\u00ecm v\u00e0 x\u00f3a t\u1ec7p:<\/strong><br><code>find . -name \"*.temp\" -type f -delete<\/code>\u00a0ho\u1eb7c\u00a0<code>find . -name \"*.temp\" -type f -exec rm {} \\\\;<\/code><\/li>\n\n\n\n<li><strong>T\u00ecm t\u1ec7p ch\u1ee9a v\u0103n b\u1ea3n c\u1ee5 th\u1ec3:<\/strong><br><code>find . -type f -exec grep -l \"search pattern\" {} \\\\;<\/code><br>L\u1ec7nh n\u00e0y t\u00ecm c\u00e1c t\u1ec7p (<code>-type f<\/code>) trong th\u01b0 m\u1ee5c hi\u1ec7n t\u1ea1i v\u00e0 ch\u1ea1y\u00a0<code>grep<\/code>\u00a0\u0111\u1ec3 t\u00ecm &#8220;search pattern&#8221; (m\u1eabu t\u00ecm ki\u1ebfm) b\u00ean trong ch\u00fang, ch\u1ec9 in ra t\u00ean t\u1ec7p (<code>-l<\/code>).<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>L\u1ec7nh\u00a0find\u00a0trong Linux l\u00e0 m\u1ed9t ti\u1ec7n \u00edch m\u1ea1nh m\u1ebd d\u00f9ng \u0111\u1ec3 t\u00ecm ki\u1ebfm t\u1ec7p tin ho\u1eb7c th\u01b0 m\u1ee5c d\u1ef1a tr\u00ean nhi\u1ec1u [&hellip;]<\/p>\n","protected":false},"author":13,"featured_media":257,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-251","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-huong-dan"],"views":265,"_links":{"self":[{"href":"https:\/\/uynghi.com\/rest-api\/wp\/v2\/posts\/251","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/uynghi.com\/rest-api\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/uynghi.com\/rest-api\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/uynghi.com\/rest-api\/wp\/v2\/users\/13"}],"replies":[{"embeddable":true,"href":"https:\/\/uynghi.com\/rest-api\/wp\/v2\/comments?post=251"}],"version-history":[{"count":5,"href":"https:\/\/uynghi.com\/rest-api\/wp\/v2\/posts\/251\/revisions"}],"predecessor-version":[{"id":256,"href":"https:\/\/uynghi.com\/rest-api\/wp\/v2\/posts\/251\/revisions\/256"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/uynghi.com\/rest-api\/wp\/v2\/media\/257"}],"wp:attachment":[{"href":"https:\/\/uynghi.com\/rest-api\/wp\/v2\/media?parent=251"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/uynghi.com\/rest-api\/wp\/v2\/categories?post=251"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/uynghi.com\/rest-api\/wp\/v2\/tags?post=251"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}