{"id":79,"date":"2025-06-24T08:35:47","date_gmt":"2025-06-24T00:35:47","guid":{"rendered":"http:\/\/1.14.207.80\/?p=79"},"modified":"2025-06-24T08:46:41","modified_gmt":"2025-06-24T00:46:41","slug":"linux%e5%9f%ba%e7%a1%80%ef%bc%88%e6%96%87%e4%bb%b6%e7%ae%a1%e7%90%86%e3%80%81io%e9%87%8d%e5%ae%9a%e5%90%91%ef%bc%89","status":"publish","type":"post","link":"https:\/\/www.zhangjianjia.xyz\/index.php\/2025\/06\/24\/linux%e5%9f%ba%e7%a1%80%ef%bc%88%e6%96%87%e4%bb%b6%e7%ae%a1%e7%90%86%e3%80%81io%e9%87%8d%e5%ae%9a%e5%90%91%ef%bc%89\/","title":{"rendered":"Linux\u57fa\u7840\uff08\u6587\u4ef6\u7ba1\u7406\u3001IO\u91cd\u5b9a\u5411\uff09"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code><\/code><\/pre>\n\n\n\n<div class=\"wp-block-jetpack-markdown\"><h3>\u6587\u4ef6\u7ba1\u7406\u4e0eIO\u91cd\u5b9a\u5411\u7cbe\u8981\u6307\u5357<\/h3>\n<h4><strong>\u4e00\u3001\u6587\u4ef6\u7cfb\u7edf\u6838\u5fc3\u7ed3\u6784<\/strong><\/h4>\n<ol>\n<li>\n<p><strong>\u76ee\u5f55\u6811\u7279\u6027<\/strong><\/p>\n<ul>\n<li>\u5355\u6839\u5012\u7f6e\u6811\u7ed3\u6784\uff0c\u6839\u76ee\u5f55 <code>\/<\/code><\/li>\n<li>\u6587\u4ef6\u540d\u79f0<strong>\u5927\u5c0f\u5199\u654f\u611f<\/strong>\uff08Mail \u2260 mail\uff09<\/li>\n<li>\u9690\u85cf\u6587\u4ef6\u4ee5 <code>.<\/code> \u5f00\u5934\uff08\u5982 <code>.bashrc<\/code>\uff09<\/li>\n<li>\u8def\u5f84\u5206\u9694\u7b26\uff1a<code>\/<\/code><\/li>\n<li>\u6700\u5927\u6587\u4ef6\u540d\u957f\u5ea6\uff1a255\u5b57\u8282<\/li>\n<li>\u6700\u5927\u8def\u5f84\u957f\u5ea6\uff1a4095\u5b57\u8282<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u6587\u4ef6\u7c7b\u578b\u6807\u8bc6<\/strong><\/p>\n<table>\n<thead>\n<tr>\n<th><strong>\u7b26\u53f7<\/strong><\/th>\n<th><strong>\u7c7b\u578b<\/strong><\/th>\n<th><strong>\u793a\u4f8b<\/strong><\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><code>-<\/code><\/td>\n<td>\u666e\u901a\u6587\u4ef6<\/td>\n<td><code>file.txt<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>d<\/code><\/td>\n<td>\u76ee\u5f55<\/td>\n<td><code>\/home\/user<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>l<\/code><\/td>\n<td>\u7b26\u53f7\u94fe\u63a5<\/td>\n<td><code>\/bin\/sh \u2192 dash<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>b<\/code><\/td>\n<td>\u5757\u8bbe\u5907<\/td>\n<td><code>\/dev\/sda<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>c<\/code><\/td>\n<td>\u5b57\u7b26\u8bbe\u5907<\/td>\n<td><code>\/dev\/tty<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>p<\/code><\/td>\n<td>\u7ba1\u9053\u6587\u4ef6<\/td>\n<td><code>named_pipe<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>s<\/code><\/td>\n<td>\u5957\u63a5\u5b57\u6587\u4ef6<\/td>\n<td><code>\/run\/docker.sock<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/li>\n<li>\n<p><strong>\u76ee\u5f55\u989c\u8272\u7ea6\u5b9a<\/strong><\/p>\n<ul>\n<li>\u84dd\u8272\uff1a\u76ee\u5f55<\/li>\n<li>\u7eff\u8272\uff1a\u53ef\u6267\u884c\u6587\u4ef6<\/li>\n<li>\u7ea2\u8272\uff1a\u538b\u7f29\u6587\u4ef6<\/li>\n<li>\u6d45\u84dd\uff1a\u94fe\u63a5\u6587\u4ef6<\/li>\n<li>\u7070\u8272\uff1a\u5176\u4ed6\u6587\u4ef6<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<hr>\n<h4><strong>\u4e8c\u3001\u76ee\u5f55\u4e0e\u6587\u4ef6\u64cd\u4f5c<\/strong><\/h4>\n<ol>\n<li>\n<p><strong>\u76ee\u5f55\u7ba1\u7406<\/strong><\/p>\n<pre><code class=\"language-bash\">mkdir \/data\/project           # \u521b\u5efa\u76ee\u5f55\nmkdir -p \/data\/project\/{src,log} # \u9012\u5f52\u521b\u5efa\ntree -L 2 \/data               # \u67e5\u770b\u76ee\u5f55\u7ed3\u6784\uff082\u7ea7\u6df1\u5ea6\uff09\nbasename \/path\/to\/file.txt    # \u8f93\u51fa file.txt\ndirname \/path\/to\/file.txt     # \u8f93\u51fa \/path\/to\n<\/code><\/pre>\n<\/li>\n<li>\n<p><strong>\u5b89\u5168\u5220\u9664\u5b9e\u8df5<\/strong><\/p>\n<table>\n<thead>\n<tr>\n<th><strong>\u573a\u666f<\/strong><\/th>\n<th><strong>\u5b89\u5168\u64cd\u4f5c<\/strong><\/th>\n<th><strong>\u5371\u9669\u64cd\u4f5c<\/strong><\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>\u5220\u9664\u6587\u4ef6<\/td>\n<td><code>rm -f old.log<\/code><\/td>\n<td><code>rm -rf \/data\/*<\/code><\/td>\n<\/tr>\n<tr>\n<td>\u751f\u4ea7\u73af\u5883\u5220\u9664<\/td>\n<td><code>mv bigfile \/tmp\/trash\/<\/code><\/td>\n<td><code>rm -rf \/*<\/code><\/td>\n<\/tr>\n<tr>\n<td>\u6e05\u7a7a\u6b63\u5728\u4f7f\u7528\u7684\u6587\u4ef6<\/td>\n<td><code>cat \/dev\/null &gt; running.log<\/code><\/td>\n<td>\u76f4\u63a5\u5220\u9664\u5bfc\u81f4\u7a7a\u95f4\u4e0d\u91ca\u653e<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/li>\n<li>\n<p><strong>\u6587\u4ef6\u5360\u7528\u95ee\u9898\u89e3\u51b3<\/strong><\/p>\n<pre><code class=\"language-bash\">lsof | grep deleted         # \u67e5\u627e\u88ab\u5220\u9664\u4f46\u672a\u91ca\u653e\u7684\u6587\u4ef6\nps aux | grep 1234          # \u67e5\u770b\u5360\u7528\u8fdb\u7a0b(1234\u4e3aPID)\nkill -9 1234                # \u7ec8\u6b62\u8fdb\u7a0b\ndf -h                       # \u9a8c\u8bc1\u7a7a\u95f4\u91ca\u653e\n<\/code><\/pre>\n<\/li>\n<\/ol>\n<hr>\n<h4><strong>\u4e09\u3001\u6587\u4ef6\u5143\u6570\u636e\u4e0e\u65f6\u95f4\u6233<\/strong><\/h4>\n<ol>\n<li>\n<p><strong>\u65f6\u95f4\u7c7b\u578b\u5bf9\u6bd4<\/strong><\/p>\n<table>\n<thead>\n<tr>\n<th><strong>\u7c7b\u578b<\/strong><\/th>\n<th><strong>\u67e5\u770b\u547d\u4ee4<\/strong><\/th>\n<th><strong>\u89e6\u53d1\u6761\u4ef6<\/strong><\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><code>atime<\/code><\/td>\n<td><code>ls -lu<\/code> \/ <code>stat<\/code><\/td>\n<td>\u6587\u4ef6\u88ab\u8bfb\u53d6<\/td>\n<\/tr>\n<tr>\n<td><code>mtime<\/code><\/td>\n<td><code>ls -l<\/code> (\u9ed8\u8ba4) \/ <code>stat<\/code><\/td>\n<td>\u6587\u4ef6\u5185\u5bb9\u4fee\u6539<\/td>\n<\/tr>\n<tr>\n<td><code>ctime<\/code><\/td>\n<td><code>ls -lc<\/code> \/ <code>stat<\/code><\/td>\n<td>\u5143\u6570\u636e\u53d8\u66f4(\u6743\u9650\/\u6240\u6709\u8005\u7b49)<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/li>\n<li>\n<p><strong>\u5143\u6570\u636e\u64cd\u4f5c<\/strong><\/p>\n<pre><code class=\"language-bash\">stat file.txt            # \u67e5\u770b\u8be6\u7ec6\u5143\u6570\u636e\nfile unknown.bin         # \u68c0\u6d4b\u6587\u4ef6\u7c7b\u578b\ntouch file.txt           # \u66f4\u65b0\u6240\u6709\u65f6\u95f4\u6233\n<\/code><\/pre>\n<\/li>\n<\/ol>\n<hr>\n<h4><strong>\u56db\u3001\u901a\u914d\u7b26\u4e0e\u6a21\u5f0f\u5339\u914d<\/strong><\/h4>\n<table>\n<thead>\n<tr>\n<th><strong>\u901a\u914d\u7b26<\/strong><\/th>\n<th><strong>\u529f\u80fd<\/strong><\/th>\n<th><strong>\u793a\u4f8b<\/strong><\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><code>*<\/code><\/td>\n<td>\u5339\u914d\u4efb\u610f\u5b57\u7b26<\/td>\n<td><code>rm *.log<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>?<\/code><\/td>\n<td>\u5339\u914d\u5355\u4e2a\u5b57\u7b26<\/td>\n<td><code>ls file?.txt<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>[abc]<\/code><\/td>\n<td>\u5339\u914d\u6307\u5b9a\u5b57\u7b26<\/td>\n<td><code>cp [abc]*.conf \/backup<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>{a,b}<\/code><\/td>\n<td>\u6269\u5c55\u6a21\u5f0f<\/td>\n<td><code>mkdir \/dir{1,2,3}<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>[^a-z]<\/code><\/td>\n<td>\u6392\u9664\u5b57\u7b26\u8303\u56f4<\/td>\n<td><code>ls !(*.bak)<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<pre><code class=\"language-bash\"># \u5907\u4efd\u975e\u9690\u85cf\u6587\u4ef6\ncp -a !(.*) \/backup\/  \n<\/code><\/pre>\n<hr>\n<h4><strong>\u4e94\u3001Inode \u6df1\u5ea6\u89e3\u6790<\/strong><\/h4>\n<ol>\n<li>\n<p><strong>Inode \u7ed3\u6784<\/strong><\/p>\n<pre><code class=\"language-mermaid\">graph LR\nA[\u6587\u4ef6\u540d] --&gt; B[Inode \u8868]\nB --&gt; C[\u5143\u6570\u636e]\nC --&gt; D[\u6743\u9650\/\u5927\u5c0f\/\u65f6\u95f4]\nC --&gt; E[\u6570\u636e\u5757\u6307\u9488]\n<\/code><\/pre>\n<\/li>\n<li>\n<p><strong>\u5173\u952e\u547d\u4ee4<\/strong><\/p>\n<pre><code class=\"language-bash\">ls -i file.txt        # \u67e5\u770binode\u53f7\ndf -i                 # \u67e5\u770b\u5206\u533ainode\u603b\u6570\ndf -h                 # \u67e5\u770b\u78c1\u76d8\u7a7a\u95f4\u4f7f\u7528\n<\/code><\/pre>\n<\/li>\n<li>\n<p><strong>\u7a7a\u95f4\u672a\u91ca\u653e\u89e3\u51b3\u65b9\u6848<\/strong><\/p>\n<pre><code class=\"language-bash\">lsof +L1              # \u67e5\u627e\u5df2\u5220\u9664\u4f46\u88ab\u5360\u7528\u7684\u6587\u4ef6\n&gt; \/var\/log\/app.log    # \u6e05\u7a7a\u6587\u4ef6\u91ca\u653e\u7a7a\u95f4\nsystemctl restart service # \u91cd\u542f\u5360\u7528\u8fdb\u7a0b\n<\/code><\/pre>\n<\/li>\n<\/ol>\n<hr>\n<h4><strong>\u516d\u3001IO\u91cd\u5b9a\u5411\u9ad8\u7ea7\u6280\u5de7<\/strong><\/h4>\n<ol>\n<li>\n<p><strong>\u6807\u51c6\u6d41\u63cf\u8ff0\u7b26<\/strong><\/p>\n<table>\n<thead>\n<tr>\n<th><strong>FD<\/strong><\/th>\n<th><strong>\u540d\u79f0<\/strong><\/th>\n<th><strong>\u9ed8\u8ba4\u8bbe\u5907<\/strong><\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>0<\/td>\n<td>stdin<\/td>\n<td>\u952e\u76d8<\/td>\n<\/tr>\n<tr>\n<td>1<\/td>\n<td>stdout<\/td>\n<td>\u5c4f\u5e55<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>stderr<\/td>\n<td>\u5c4f\u5e55<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/li>\n<li>\n<p><strong>\u91cd\u5b9a\u5411\u64cd\u4f5c\u7b26<\/strong><\/p>\n<pre><code class=\"language-bash\">cmd &gt; file         # \u6807\u51c6\u8f93\u51fa\u8986\u76d6\u91cd\u5b9a\u5411\ncmd &gt;&gt; file        # \u6807\u51c6\u8f93\u51fa\u8ffd\u52a0\u91cd\u5b9a\u5411\ncmd 2&gt; error.log   # \u6807\u51c6\u9519\u8bef\u91cd\u5b9a\u5411\ncmd &amp;&gt; all.log     # \u6df7\u5408\u8f93\u51fa\u91cd\u5b9a\u5411\ncmd 2&gt;&amp;1 | tee output.log # \u540c\u65f6\u8f93\u51fa\u5230\u5c4f\u5e55\u548c\u6587\u4ef6\n<\/code><\/pre>\n<\/li>\n<li>\n<p><strong>\u9ad8\u7ea7\u7528\u6cd5<\/strong><\/p>\n<pre><code class=\"language-bash\"># \u591a\u884c\u8f93\u5165\u91cd\u5b9a\u5411\ncat &lt;&lt;EOF &gt; config\nline1\nline2\nEOF\n\n# Here String\ntr 'a-z' 'A-Z' &lt;&lt;&lt; &quot;hello&quot;\n\n# \u8fdb\u7a0b\u66ff\u6362\ndiff &lt;(ls dir1) &lt;(ls dir2)\n<\/code><\/pre>\n<\/li>\n<\/ol>\n<hr>\n<h4><strong>\u4e03\u3001\u6587\u672c\u5904\u7406\u547d\u4ee4<\/strong><\/h4>\n<ol>\n<li>\n<p><strong><code>tr<\/code> \u5b57\u7b26\u8f6c\u6362<\/strong><\/p>\n<pre><code class=\"language-bash\">echo &quot;123456&quot; | tr '123' 'ABC'     # ABC456\necho &quot;Hello123&quot; | tr -d '0-9'      # Hello\necho &quot;aaabbbccc&quot; | tr -s 'ab'      # abccc\n<\/code><\/pre>\n<\/li>\n<li>\n<p><strong><code>tee<\/code> \u53cc\u8def\u8f93\u51fa<\/strong><\/p>\n<pre><code class=\"language-bash\"># \u8986\u76d6\u5199\u5165\necho &quot;New Data&quot; | tee output.log\n\n# \u8ffd\u52a0\u5199\u5165\ndmesg | tee -a system.log\n\n# \u5ffd\u7565\u4e2d\u65ad\u4fe1\u53f7\nimportant_process | tee -i logfile\n<\/code><\/pre>\n<\/li>\n<\/ol>\n<\/div>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[3],"tags":[],"class_list":["post-79","post","type-post","status-publish","format-standard","hentry","category-linux"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.zhangjianjia.xyz\/index.php\/wp-json\/wp\/v2\/posts\/79","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.zhangjianjia.xyz\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.zhangjianjia.xyz\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.zhangjianjia.xyz\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.zhangjianjia.xyz\/index.php\/wp-json\/wp\/v2\/comments?post=79"}],"version-history":[{"count":2,"href":"https:\/\/www.zhangjianjia.xyz\/index.php\/wp-json\/wp\/v2\/posts\/79\/revisions"}],"predecessor-version":[{"id":82,"href":"https:\/\/www.zhangjianjia.xyz\/index.php\/wp-json\/wp\/v2\/posts\/79\/revisions\/82"}],"wp:attachment":[{"href":"https:\/\/www.zhangjianjia.xyz\/index.php\/wp-json\/wp\/v2\/media?parent=79"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zhangjianjia.xyz\/index.php\/wp-json\/wp\/v2\/categories?post=79"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhangjianjia.xyz\/index.php\/wp-json\/wp\/v2\/tags?post=79"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}