<!DOCTYPE html>
    <html lang="vi" xmlns="http://www.w3.org/1999/xhtml" prefix="og: http://ogp.me/ns#">
    <head>
<title>Hướng dẫn sử dụng lệnh find trong Linux</title>
<meta name="description" content="Hướng dẫn sử dụng lệnh find trong Linux - Savefile - Tin Tức -...">
<meta name="author" content=".: Nguoicodonvn2008.info - Cõi lòng người cô đơn :.">
<meta name="copyright" content=".: Nguoicodonvn2008.info - Cõi lòng người cô đơn :. [admin@nguoicodonvn2008.info]">
<meta name="robots" content="index, archive, follow, noodp">
<meta name="googlebot" content="index,archive,follow,noodp">
<meta name="msnbot" content="all,index,follow">
<meta name="generator" content="NukeViet v4.5">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta property="og:title" content="Hướng dẫn sử dụng lệnh find trong Linux">
<meta property="og:type" content="website">
<meta property="og:description" content="Savefile - Tin Tức - https&#x3A;&#x002F;&#x002F;www.nguoicodonvn2008.info&#x002F;vi&#x002F;news&#x002F;savefile&#x002F;kien-thuc-may-tinh&#x002F;huong-dan-su-dung-lenh-find-trong-linux-3252.html">
<meta property="og:site_name" content=".&#x3A; Nguoicodonvn2008.info - Cõi lòng người cô đơn &#x3A;.">
<meta property="og:url" content="https://www.nguoicodonvn2008.info/vi/news/savefile/kien-thuc-may-tinh/huong-dan-su-dung-lenh-find-trong-linux-3252.html">
<link rel="shortcut icon" href="https://nguoicodonvn2008.info/favicon.ico">
<link rel="canonical" href="https://www.nguoicodonvn2008.info/vi/news/savefile/kien-thuc-may-tinh/huong-dan-su-dung-lenh-find-trong-linux-3252.html">
<link rel="alternate" href="https://nguoicodonvn2008.info/vi/news/rss/" title="Tin Tức" type="application/rss+xml">
<link rel="alternate" href="https://nguoicodonvn2008.info/vi/news/rss/karaoke-dual/" title="Tin Tức - Karaoke Dual" type="application/rss+xml">
<link rel="alternate" href="https://nguoicodonvn2008.info/vi/news/rss/nhac-tre/" title="Tin Tức - Nhạc trẻ" type="application/rss+xml">
<link rel="alternate" href="https://nguoicodonvn2008.info/vi/news/rss/tru-tinh/" title="Tin Tức - Trữ tình" type="application/rss+xml">
<link rel="alternate" href="https://nguoicodonvn2008.info/vi/news/rss/nuoc-ngoai/" title="Tin Tức - Nước ngoài" type="application/rss+xml">
<link rel="alternate" href="https://nguoicodonvn2008.info/vi/news/rss/remix/" title="Tin Tức - Remix" type="application/rss+xml">
<link rel="alternate" href="https://nguoicodonvn2008.info/vi/news/rss/tam-su-tinh-yeu/" title="Tin Tức - Tâm sự tình yêu" type="application/rss+xml">
<link rel="alternate" href="https://nguoicodonvn2008.info/vi/news/rss/tho-suu-tam/" title="Tin Tức - Thơ sưu tầm" type="application/rss+xml">
<link rel="alternate" href="https://nguoicodonvn2008.info/vi/news/rss/cuoc-song/" title="Tin Tức - Cuộc sống" type="application/rss+xml">
<link rel="alternate" href="https://nguoicodonvn2008.info/vi/news/rss/phan-mem/" title="Tin Tức - Phần mềm" type="application/rss+xml">
<link rel="alternate" href="https://nguoicodonvn2008.info/vi/news/rss/kien-thuc-may-tinh/" title="Tin Tức - Kiến thức máy tính" type="application/rss+xml">
<link rel="alternate" href="https://nguoicodonvn2008.info/vi/news/rss/hoc-tap/" title="Tin Tức - Học tập" type="application/rss+xml">
<link rel="alternate" href="https://nguoicodonvn2008.info/vi/news/rss/tai-lieu/" title="Tin Tức - Tài liệu" type="application/rss+xml">
<link rel="alternate" href="https://nguoicodonvn2008.info/vi/news/rss/de-thi/" title="Tin Tức - Đề thi" type="application/rss+xml">
<link rel="preload" as="style" href="https://nguoicodonvn2008.info/assets/css/font-awesome.min.css" type="text/css">
<link rel="preload" as="style" href="https://nguoicodonvn2008.info/themes/default/css/bootstrap.non-responsive.css" type="text/css">
<link rel="preload" as="style" href="https://nguoicodonvn2008.info/themes/default/css/style.css" type="text/css">
<link rel="preload" as="style" href="https://nguoicodonvn2008.info/themes/default/css/style.non-responsive.css" type="text/css">
<link rel="preload" as="style" href="https://nguoicodonvn2008.info/themes/default/css/news.css" type="text/css">
<link rel="preload" as="style" href="https://nguoicodonvn2008.info/themes/default/css/custom.css" type="text/css">
<link rel="preload" as="script" href="https://nguoicodonvn2008.info/assets/js/jquery/jquery.min.js" type="text/javascript">
<link rel="preload" as="script" href="https://nguoicodonvn2008.info/assets/js/language/vi.js" type="text/javascript">
<link rel="preload" as="script" href="https://nguoicodonvn2008.info/assets/js/DOMPurify/purify3.js" type="text/javascript">
<link rel="preload" as="script" href="https://nguoicodonvn2008.info/assets/js/global.js" type="text/javascript">
<link rel="preload" as="script" href="https://nguoicodonvn2008.info/assets/js/site.js" type="text/javascript">
<link rel="preload" as="script" href="https://nguoicodonvn2008.info/themes/default/js/news.js" type="text/javascript">
<link rel="preload" as="script" href="https://nguoicodonvn2008.info/themes/default/js/main.js" type="text/javascript">
<link rel="preload" as="script" href="https://nguoicodonvn2008.info/themes/default/js/custom.js" type="text/javascript">
<link rel="preload" as="script" href="https://nguoicodonvn2008.info/themes/default/js/bootstrap.min.js" type="text/javascript">
<link rel="stylesheet" href="https://nguoicodonvn2008.info/assets/css/font-awesome.min.css">
<link rel="stylesheet" href="https://nguoicodonvn2008.info/themes/default/css/bootstrap.non-responsive.css">
<link rel="stylesheet" href="https://nguoicodonvn2008.info/themes/default/css/style.css">
<link rel="stylesheet" href="https://nguoicodonvn2008.info/themes/default/css/style.non-responsive.css">
<link rel="StyleSheet" href="https://nguoicodonvn2008.info/themes/default/css/news.css">
<link rel="stylesheet" href="https://nguoicodonvn2008.info/themes/default/css/custom.css">
<style type="text/css">
	body{background: #fff;}
</style>
    </head>
    <body>
<div id="print">
	<div id="hd_print">
		<h2 class="pull-left">.&#x3A; Nguoicodonvn2008.info - Cõi lòng người cô đơn &#x3A;.</h2>
		<p class="pull-right"><a title=".&#x3A; Nguoicodonvn2008.info - Cõi lòng người cô đơn &#x3A;." href="https://nguoicodonvn2008.info/">https://nguoicodonvn2008.info</a></p>
	</div>
	<div class="clear"></div>
	<hr />
	<div id="content">
		<h1>Hướng dẫn sử dụng lệnh find trong Linux</h1>
		<ul class="list-inline">
			<li>Thứ ba - 15/12/2020 23:58</li>
			<li class="hidden-print txtrequired"><em class="fa fa-print">&nbsp;</em><a title="In ra" href="javascript:;" onclick="window.print()">In ra</a></li>
			<li class="hidden-print txtrequired"><em class="fa fa-power-off">&nbsp;</em><a title="Đóng cửa sổ này" href="javascript:;" onclick="window.close()">Đóng cửa sổ này</a></li>
		</ul>
		<div class="clear"></div>
		<div id="hometext">
		</div>
				<div class="imghome">
			<img alt="Hướng dẫn sử dụng lệnh find trong Linux" src="https://st.quantrimang.com/photos/image/2020/12/15/lenh-find-trong-linux-1.jpg" width="460" class="img-thumbnail" />
		</div>
		<div class="clear"></div>
		<div id="bodytext" class="clearfix">
			<p style="text-align: justify;">Lệnh find là một trong những lệnh quan trọng và tiện dụng nhất trên hệ thống&nbsp;Linux. Như tên gọi của nó cho thấy, lệnh có thể tìm các file trên PC Linux dựa trên khá nhiều điều kiện và biến số bạn đặt. Bạn có thể tìm file theo quyền, người dùng, nhóm, loại file, ngày tháng, dung lượng và các tiêu chí có thể có khác bằng cách sử dụng lệnh find.</p>

<p style="text-align: justify;">Lệnh find có sẵn trên hầu hết các bản phân phối Linux theo mặc định, vì vậy bạn không cần phải cài đặt gói cho nó.</p>

<div style="text-align: justify;">&nbsp;</div>

<p style="text-align: justify;">Trong hướng dẫn này,&nbsp;<strong>Quantrimang</strong>&nbsp;sẽ chỉ cho bạn cách tìm file trên Linux bằng cách sử dụng các kết hợp phổ biến khác nhau của những biểu thức tìm kiếm trong dòng lệnh.</p>

<h2 style="text-align: justify;">Tìm file theo tên trong thư mục hiện tại</h2>

<p style="text-align: justify;">Cách rõ ràng nhất để tìm kiếm file là theo tên. Để tìm một file theo tên trong thư mục hiện tại, hãy chạy:</p>

<pre id="pre0">
<code>find . -name photo.png</code></pre>

<figure>
<div style="text-align: justify;"><img alt="Tìm file theo tên trong thư mục hiện tại" data-i="0" data-src="https://st.quantrimang.com/photos/image/2020/12/15/lenh-find-trong-linux-1.jpg" data-was-processed="true" height="65" src="https://st.quantrimang.com/photos/image/2020/12/15/lenh-find-trong-linux-1.jpg" width="650" /></div>

<figcaption>
<div style="text-align: justify;">Tìm file theo tên trong thư mục hiện tại</div>
</figcaption>
</figure>

<p style="text-align: justify;">Nếu bạn muốn tìm một file theo tên có cả chữ hoa và chữ nhỏ, hãy chạy:</p>

<pre id="pre1">
<code>find . -iname photo.png</code></pre>

<figure>
<div style="text-align: justify;"><img alt="Tìm file theo tên có cả chữ hoa và chữ nhỏ" data-i="1" data-src="https://st.quantrimang.com/photos/image/2020/12/15/lenh-find-trong-linux-2.jpg" data-was-processed="true" height="65" src="https://st.quantrimang.com/photos/image/2020/12/15/lenh-find-trong-linux-2.jpg" width="650" /></div>

<figcaption>
<div style="text-align: justify;">Tìm file theo tên có cả chữ hoa và chữ nhỏ</div>
</figcaption>
</figure>

<p style="text-align: justify;">Nếu bạn muốn tìm một file trong thư mục root, hãy đặt tiền tố&nbsp;<strong>sudo</strong>&nbsp;trước tìm kiếm của bạn. Điều này sẽ cung cấp cho bạn tất cả các quyền cần thiết để làm như vậy và cũng có biểu tượng&nbsp;<strong>“/”</strong>&nbsp;cho phép Linux tìm kiếm trong&nbsp;<a href="https://quantrimang.com/thu-muc-root-la-gi-166229" title="Thư mục root là gì?">thư mục root</a>. Cuối cùng, biểu thức&nbsp;<strong>-print</strong>&nbsp;hiển thị các thư mục trong kết quả tìm kiếm. Nếu đang tìm kiếm Gzip, bạn phải nhập:</p>

<pre id="pre2">
<code>sudo find / -name gzip -print</code></pre>

<figure>
<div style="text-align: justify;"><img alt="Tìm một file trong thư mục root" data-i="2" data-src="https://st.quantrimang.com/photos/image/2020/12/15/lenh-find-trong-linux-3.jpg" data-was-processed="true" height="105" src="https://st.quantrimang.com/photos/image/2020/12/15/lenh-find-trong-linux-3.jpg" width="650" /></div>

<figcaption>
<div style="text-align: justify;">Tìm một file trong thư mục root</div>
</figcaption>
</figure>

<h2 style="text-align: justify;">Tìm file trong thư mục cụ thể</h2>

<p style="text-align: justify;">Nếu bạn muốn tìm các file trong một thư mục cụ thể như&nbsp;<strong>“/home”</strong>, hãy chạy:</p>

<pre id="pre3">
<code>find /home -name filename.txt</code></pre>

<p style="text-align: justify;">Nếu bạn muốn tìm các file có phần mở rộng&nbsp;<strong>“.txt”</strong>&nbsp;trong thư mục&nbsp;<strong>“/home”</strong>, hãy chạy:</p>

<pre id="pre4">
<code>find /home -name *.txt</code></pre>

<p style="text-align: justify;">Để tìm các file có tên là&nbsp;<strong>“test.txt”</strong>&nbsp;trong nhiều thư mục như&nbsp;<strong>“/home”</strong>&nbsp;và&nbsp;<strong>“/opt”</strong>, hãy chạy:</p>

<pre id="pre5">
<code>find /home /opt -name test.txt</code></pre>

<p style="text-align: justify;">Để tìm các file ẩn trong thư mục&nbsp;<strong>“/home”</strong>, hãy chạy:</p>

<pre id="pre6">
<code>find /home -name &quot;.*&quot;</code></pre>

<p style="text-align: justify;">Để tìm một file duy nhất có tên&nbsp;<strong>“test.txt”</strong>&nbsp;và xóa nó, hãy chạy:</p>

<pre id="pre7">
<code>find /home -type f -name test.txt -exec rm -f {}</code></pre>

<p style="text-align: justify;">Để tìm tất cả các file trống trong thư mục&nbsp;<strong>“/opt”</strong>, hãy chạy:</p>

<pre id="pre8">
<code>find /opt -type f -empty</code></pre>

<div style="text-align: justify;">&nbsp;</div>

<h2 style="text-align: justify;">Tìm thư mục bằng tên</h2>

<p style="text-align: justify;">Nếu bạn muốn tìm tất cả các thư mục có tên là&nbsp;<strong>“testdir”</strong>&nbsp;trong thư mục&nbsp;<strong>“/home”</strong>, hãy chạy:</p>

<pre id="pre9">
<code>find /home -type d -name testdir</code></pre>

<p style="text-align: justify;">Để lưu trữ tất cả các thư mục trống trong&nbsp;<strong>“/home”</strong>, hãy chạy:</p>

<pre id="pre10">
<code>find /home -type d -empty</code></pre>

<h2 style="text-align: justify;">Tìm file với một số quyền nhất định</h2>

<p style="text-align: justify;">Lệnh find có thể được sử dụng để tìm các file có quyền cụ thể bằng cách sử dụng tùy chọn&nbsp;<strong>perm.</strong></p>

<p style="text-align: justify;">Để tìm tất cả các file có quyền là&nbsp;<strong>“777”</strong>&nbsp;trong thư mục&nbsp;<strong>“/home”</strong>, hãy chạy:</p>

<pre id="pre11">
<code>find /home -type f -perm 0777 -print</code></pre>

<p style="text-align: justify;">Để tìm tất cả các file không có quyền&nbsp;<strong>&quot;777&quot;</strong>, hãy chạy:</p>

<pre id="pre12">
<code>find . -type f ! -perm 777</code></pre>

<p style="text-align: justify;">Để tìm tất cả các file chỉ đọc, hãy chạy:</p>

<pre id="pre13">
<code>find /home -perm /u=r</code></pre>

<p style="text-align: justify;">Để tìm tất cả các file thực thi, hãy chạy:</p>

<pre id="pre14">
<code>find /home -perm /a=x</code></pre>

<p style="text-align: justify;">Để tìm tất cả các tập hợp file&nbsp;Sticky Bit&nbsp;có quyền là&nbsp;<strong>“553”</strong>, hãy chạy:</p>

<pre id="pre15">
<code>find /home -perm 1553</code></pre>

<p style="text-align: justify;">Để tìm tất cả các tập hợp file SUID, hãy chạy:</p>

<pre id="pre16">
<code>find /home -perm /u=s</code></pre>

<p style="text-align: justify;">Để tìm tất cả các file có quyền là&nbsp;<strong>“777”</strong>&nbsp;và thay đổi quyền của chúng thành&nbsp;<strong>“700”</strong>, hãy chạy:</p>

<pre id="pre17">
<code>find /home -type f -perm 0777 -print -exec chmod 700 {} ;</code></pre>

<h2 style="text-align: justify;">Tìm file và thư mục dựa trên ngày và giờ</h2>

<p style="text-align: justify;">Để tìm tất cả các file trong&nbsp;<strong>“/opt”</strong>&nbsp;đã được sửa đổi 20 ngày trước đó, hãy chạy:</p>

<pre id="pre18">
<code>find /opt -mtime 20</code></pre>

<p style="text-align: justify;">Để tìm tất cả các file trong&nbsp;<strong>“/opt”</strong>&nbsp;được truy cập 20 ngày trước đó, hãy chạy:</p>

<pre id="pre19">
<code>find /opt -atime 20</code></pre>

<p style="text-align: justify;">Để tìm tất cả các file trong&nbsp;<strong>“/opt”</strong>&nbsp;được sửa đổi trong khoảng 30 đến 50 ngày, hãy chạy:</p>

<pre id="pre20">
<code>find /opt -mtime +30 -mtime -50</code></pre>

<p style="text-align: justify;">Để tìm tất cả các file trong&nbsp;<strong>“/opt”</strong>&nbsp;được thay đổi trong hai giờ qua, hãy chạy:</p>

<pre id="pre21">
<code>find /opt -cmin -120</code></pre>

<h2 style="text-align: justify;">Tìm file và thư mục dựa trên dung lượng</h2>

<p style="text-align: justify;">Để tìm tất cả các file 10MB trong thư mục&nbsp;<strong>“/home”</strong>, hãy chạy:</p>

<pre id="pre22">
<code>find /home -size 10M</code></pre>

<p style="text-align: justify;">Để tìm tất cả các file trong thư mục&nbsp;<strong>“/home”</strong>&nbsp;lớn hơn 10MB và nhỏ hơn 50MB, hãy chạy:</p>

<pre id="pre23">
<code>find /home -size +10M -size -50M</code></pre>

<p style="text-align: justify;">Để tìm tất cả các file&nbsp;<strong>“.mp4”</strong>&nbsp;trong thư mục&nbsp;<strong>“/home”</strong>&nbsp;có dung lượng hơn 10MB và xóa chúng bằng một lệnh duy nhất, hãy chạy:</p>

<pre id="pre24">
<code>find /home -type f -name *.mp4 -size +10M -exec rm {} ;</code></pre>
		</div>
				<div id="author">
						<p>
				<strong>Nguồn tin:</strong>
				Quantrimang.com
			</p>
		</div>
	</div>
	<div id="footer" class="clearfix">
		<div id="url">
			<strong>URL của bản tin này: </strong><a href="https://www.nguoicodonvn2008.info/vi/news/savefile/kien-thuc-may-tinh/huong-dan-su-dung-lenh-find-trong-linux-3252.html" title="Hướng dẫn sử dụng lệnh find trong Linux">https://www.nguoicodonvn2008.info/vi/news/savefile/kien-thuc-may-tinh/huong-dan-su-dung-lenh-find-trong-linux-3252.html</a>

		</div>
		<div class="clear"></div>
		<div class="copyright">
			&copy; .&#x3A; Nguoicodonvn2008.info - Cõi lòng người cô đơn &#x3A;.
		</div>
		<div id="contact">
			<a href="mailto:admin@nguoicodonvn2008.info">admin@nguoicodonvn2008.info</a>
		</div>
	</div>
</div>
        <div id="timeoutsess" class="chromeframe">
            Bạn đã không sử dụng Site, <a onclick="timeoutsesscancel();" href="https://nguoicodonvn2008.info/#">Bấm vào đây để duy trì trạng thái đăng nhập</a>. Thời gian chờ: <span id="secField"> 60 </span> giây
        </div>
        <div id="openidResult" class="nv-alert" style="display:none"></div>
        <div id="openidBt" data-result="" data-redirect=""></div>
		</script>
		<div class="car-top">
  <span><img src="https://nguoicodonvn2008.info/themes/default/images/car.png" alt=""></span>
</div>
<div id="run_cronjobs" style="visibility:hidden;display:none;"><img alt="cron" src="/index.php?second=cronjobs&amp;p=n0d9B83e" width="1" height="1" /></div>
<script src="https://nguoicodonvn2008.info/assets/js/jquery/jquery.min.js"></script>
<script>var nv_base_siteurl="/",nv_lang_data="vi",nv_lang_interface="vi",nv_name_variable="nv",nv_fc_variable="op",nv_lang_variable="language",nv_module_name="news",nv_func_name="savefile",nv_is_user=0, nv_my_ofs=-4,nv_my_abbr="EDT",nv_cookie_prefix="nv4c_e856T",nv_check_pass_mstime=1738000,nv_area_admin=0,nv_safemode=0,theme_responsive=0,nv_recaptcha_ver=2,nv_recaptcha_sitekey="",nv_recaptcha_type="image",XSSsanitize=1;</script>
<script src="https://nguoicodonvn2008.info/assets/js/language/vi.js"></script>
<script src="https://nguoicodonvn2008.info/assets/js/DOMPurify/purify3.js"></script>
<script src="https://nguoicodonvn2008.info/assets/js/global.js"></script>
<script src="https://nguoicodonvn2008.info/assets/js/site.js"></script>
<script src="https://nguoicodonvn2008.info/themes/default/js/news.js"></script>
<script src="https://nguoicodonvn2008.info/themes/default/js/main.js"></script>
<script src="https://nguoicodonvn2008.info/themes/default/js/custom.js"></script>
<script type="application/ld+json">
        {
            "@context": "https://schema.org",
            "@type": "Organization",
            "url": "https://nguoicodonvn2008.info",
            "logo": "https://nguoicodonvn2008.info/uploads/angel.gif"
        }
        </script>
<script src="https://nguoicodonvn2008.info/themes/default/js/bootstrap.min.js"></script>
<script type="text/javascript">
var $scrolltop = $('.car-top');
$scrolltop.on('click', function () {
    $('html,body').animate({
        scrollTop: 0
    }, 800);
    $(this).addClass("car-run");
    setTimeout(function(){ $scrolltop.removeClass('car-run');}, 1000);
    return false;
});
$(window).on('scroll', function ()
{ 
    if($(window).scrollTop() >= 200)
    {
        $scrolltop.addClass("show");
        $scrolltop.addClass("car-down");
    }
    else
    {
       $scrolltop.removeClass("show");
       setTimeout(function(){ $scrolltop.removeClass('car-down');}, 300);
    }
});
</script>
</body>
</html>