<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>linux</title>
    <description>Linux notes</description>
    <link>https://dangduytung.github.io/linux/</link>
    <atom:link href="https://dangduytung.github.io/linux/feed.xml" rel="self" type="application/rss+xml" />
    <pubDate>Fri, 23 Jun 2023 02:39:21 +0000</pubDate>
    <lastBuildDate>Fri, 23 Jun 2023 02:39:21 +0000</lastBuildDate>
    <generator>Jekyll v3.9.3</generator>
    
      <item>
        <title>Ps</title>
        <description>&lt;p&gt;Lệnh &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ps&lt;/code&gt; liệt kê các tiến trình đang chạy&lt;/p&gt;

&lt;h4 id=&quot;hiển-thị-tất-cả-tiến-trình&quot;&gt;Hiển thị tất cả tiến trình&lt;/h4&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;ps -ef                                      # Lệnh tương tự ps aux 
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;lọc-theo-người-dùng&quot;&gt;Lọc theo người dùng&lt;/h4&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;ps -e -u userName
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;lọc-theo-tiến-trình&quot;&gt;Lọc theo tiến trình&lt;/h4&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;ps -C name 
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;lọc-theo-id-tiến-trình&quot;&gt;Lọc theo ID tiến trình&lt;/h4&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;ps -ef -p 1234,5678,9012
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;chuyển-kết-quả-sang-grep&quot;&gt;Chuyển kết quả sang grep&lt;/h4&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;ps -ef | grep worker
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;hiển-thị-các-cột-cụ-thể&quot;&gt;Hiển thị các cột cụ thể&lt;/h4&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;ps -e -o pid,uname,pcpu,pmem,comm           # https://linux.die.net/man/1/ps
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;sắp-xếp-các-tiến-trình-theo-cách-sử-dụng&quot;&gt;Sắp xếp các tiến trình theo cách sử dụng&lt;/h4&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;ps -e --sort=-pcpu -o pid,pcpu,comm
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;đổi-tên-tiêu-đề-cột&quot;&gt;Đổi tên tiêu đề cột&lt;/h4&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;ps -o pid=Process,ruser=RealUser,comm=Command
ps -e -o pid,pcpu=CPU -o pmem=RAM,comm
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;hiển-thị-kết-quả-theo-kiểu-cây-phân-cấp&quot;&gt;Hiển thị kết quả theo kiểu cây phân cấp&lt;/h4&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;ps -e --forest
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;hiển-thị-các-thread-bên-trong-tiến-trình&quot;&gt;Hiển thị các thread bên trong tiến trình&lt;/h4&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;ps -p 4041 -L
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;hiển-thị-tất-cả-các-tiến-trình-root&quot;&gt;Hiển thị tất cả các tiến trình root&lt;/h4&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;ps -f -U root -u root
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
</description>
        <pubDate>Tue, 01 Oct 2019 01:00:00 +0000</pubDate>
        <link>https://dangduytung.github.io/linux/command/ps</link>
        <guid isPermaLink="true">https://dangduytung.github.io/linux/command/ps</guid>
        
        <category>ps</category>
        
        
        <category>command</category>
        
      </item>
    
      <item>
        <title>Grep</title>
        <description>&lt;p&gt;Lệnh &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;grep&lt;/code&gt; tìm chuỗi trong file chỉ định&lt;/p&gt;

&lt;h4 id=&quot;tìm-trong-file&quot;&gt;Tìm trong file&lt;/h4&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;grep &quot;search&quot; file                  # Chuỗi trong file
grep &quot;search&quot; file_*.log            # Chuỗi trong nhiều file
grep -i &quot;search&quot; file               # Chuỗi không phân biệt hoa thường
grep -w &quot;search&quot; file               # Tìm chính xác
grep -r &quot;search&quot; *                  # Tìm ở tất cả các file trong thư mục con
grep -v &quot;search&quot; file_*             # Tìm ngược (dòng không chứa chuỗi)
grep &quot;regex&quot; file                   # Tìm theo regex
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;tìm-trước-sau-xung-quanh-dòng-chứa-kết-quả&quot;&gt;Tìm trước, sau, xung quanh dòng chứa kết quả&lt;/h4&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;grep -&amp;lt;A, B hoặc C&amp;gt; &amp;lt;n&amp;gt; &quot;search&quot; file
-- A : là after
-- B : là before
-- C : là xung quanh
-- n : là số tự nhiên chỉ định xem hiển thị trước, sau hay xung quang bao nhiêu dòng
&amp;gt; grep -B 3 -iw &quot;search&quot; file       # Hiển thị trước kết qủa thêm nội dung của 3 dòng nữa. Không phân biệt hoa thường và tìm chính xác
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;đếm-kết-quả&quot;&gt;Đếm kết quả&lt;/h4&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;grep -c -w &quot;INSERT&quot; log_*           # Đếm kết quả search
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;chỉ-hiển-thị-tên-file&quot;&gt;Chỉ hiển thị tên file&lt;/h4&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;grep -l -r -w &quot;search&quot; *            # Từ khóa trong những file nào
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;kết-hợp-với-command-khác&quot;&gt;Kết hợp với command khác&lt;/h4&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;ps ux | grep tomcat                 # Tìm kiếm Pid
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
</description>
        <pubDate>Tue, 01 Oct 2019 01:00:00 +0000</pubDate>
        <link>https://dangduytung.github.io/linux/command/grep</link>
        <guid isPermaLink="true">https://dangduytung.github.io/linux/command/grep</guid>
        
        <category>grep</category>
        
        
        <category>command</category>
        
      </item>
    
      <item>
        <title>Find</title>
        <description>&lt;h4 id=&quot;1tìm-theo-tên&quot;&gt;1.Tìm theo tên&lt;/h4&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;find -name &quot;file_name&quot; (tên chính xác)
find -iname &quot;file_name&quot; (cả tên in hoa)
find -not -name &quot;file_name_to_avoid&quot;
find \! -name &quot;file_name_to_avoid&quot;
find -name test* (tên có chứa chuỗi)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;2tìm-theo-thể-loại&quot;&gt;2.Tìm theo thể loại&lt;br /&gt;&lt;/h4&gt;
&lt;p&gt;Sử dụng option &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-type&lt;/code&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;f: regular file&lt;/li&gt;
  &lt;li&gt;d: directory&lt;/li&gt;
  &lt;li&gt;l: symbolic link&lt;/li&gt;
  &lt;li&gt;c: character devices&lt;/li&gt;
  &lt;li&gt;b: block devices&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;find -type f -name “*.ovpn”
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;3tìm-theo-size&quot;&gt;3.Tìm theo size&lt;br /&gt;&lt;/h4&gt;
&lt;p&gt;Sử dụng option &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-size&lt;/code&gt; : c (bytes), k (kilobytes), M (megabytes), G (gigabytes), b (512-byte blocks)&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;find / -size 50c (file nặng 50 bytes)
find / -size -50c (file nhỏ hơn 50 bytes)
find / -size +1G (file nặng hơn 1G)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;4tìm-theo-time&quot;&gt;4.Tìm theo time&lt;/h4&gt;
&lt;p&gt;Linux lưu trữ 1 vài thông tin liên quan đến thời gian như: thời điểm truy cập, thời điểm chỉnh sửa, và thời điểm thay đổi file.&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Access Time (thời điểm truy cập): Lần cuối cùng file được đọc hoặc ghi vào.&lt;/li&gt;
  &lt;li&gt;Modification Time (thời điểm chỉnh sửa): Lần cuối nội dung file được chỉnh sửa.&lt;/li&gt;
  &lt;li&gt;Change Time (thời điểm thay đổi): Lần cuối mà inode meta-data của file bị sửa.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Tương đương với các thông tin trên, ta dùng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-atime&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-mtime&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-ctime&lt;/code&gt;, và cả “-“ và “+” để lọc ra những thời gian trước hay sau thời điểm đó.&lt;br /&gt;
Để tìm các file được chỉnh sửa trong vòng 1 ngày trước:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;find / -mtime 1
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Tìm các file được truy cập trong ngày hôm qua:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;find / -atime -1
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Các file mà meta-data bị chỉnh sửa lần cuối là 3 ngày trước và hơn:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;find / -ctime +3
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Hoặc tìm file được chỉnh sửa trong vòng 1 phút trước.&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;find / -mmin -1
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Lệnh find còn có thể so sánh với 1 file, và trả về những file mới hơn:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;find / -newer myfile
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;5tìm-theo-owner-và-permission&quot;&gt;5.Tìm theo Owner và Permission&lt;/h4&gt;

&lt;p&gt;Chúng ta có thể tìm theo user hay group owner bằng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-user&lt;/code&gt; và &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-group&lt;/code&gt;.&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;find / -user syslog
find / -group sudo
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Tìm những file có permission 644:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;find / -perm 644
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;ul&gt;
  &lt;li&gt;4 is read&lt;/li&gt;
  &lt;li&gt;5 is read/execute (execute is always needed for directories)&lt;/li&gt;
  &lt;li&gt;6 is read/write&lt;/li&gt;
  &lt;li&gt;7 is read, write, and execute&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;6-kết-hợp-find-với-command-khác&quot;&gt;6. Kết hợp find với command khác&lt;/h4&gt;

&lt;p&gt;Chúng ta còn có thể kết hợp find và các command khác để xử lý những file vừa tìm được với &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-exec&lt;/code&gt;&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;find find_parameters -exec command_and_params {} \;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Tìm các file có permission là 744 và chmod sang 755:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;find / -type f -perm 777 -print -exec chmod 755 {} \;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Tìm 1 file test.py và xóa nó:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;find . -type f -name &quot;test.py&quot; -exec rm -f {} \;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Xóa các file có đuôi .mp3 ở dir hiện tại:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;find . -type f -name &quot;*.mp3&quot; -exec rm -f {} \;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Tìm các file .mp3 ở thư mục gốc i, không tìm thư mục con của i và move sang thư mục Music&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;find /i -maxdepth 1 -name '*.mp3' -exec mv -t /i/Music/ {} +
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;7-option-khác&quot;&gt;7. Option khác&lt;/h4&gt;
&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-empty&lt;/code&gt; để tìm các file/dir rỗng&lt;/p&gt;
</description>
        <pubDate>Tue, 01 Oct 2019 01:00:00 +0000</pubDate>
        <link>https://dangduytung.github.io/linux/command/find</link>
        <guid isPermaLink="true">https://dangduytung.github.io/linux/command/find</guid>
        
        <category>find</category>
        
        
        <category>command</category>
        
      </item>
    
      <item>
        <title>Cat</title>
        <description>&lt;p&gt;Lệnh &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cat&lt;/code&gt; (concatenate) là một trong những tiện ích của hệ điều hành Linux được dùng để đọc và in tệp, dùng để xem nội dung tệp. Để xem tệp, chúng ta sử dụng:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;cat &amp;lt;thamso&amp;gt; &amp;lt;ten tep&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Tham số &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-n&lt;/code&gt; là hiển thị số dòng. &lt;br /&gt;
Tham số &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-T&lt;/code&gt; hiển thị khoảng trắng được sử dụng TAB. Lệnh cat sẽ chuyển đổi khoảng trắng tab thành ký tự ‘^I’.
Tham số &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-s&lt;/code&gt; loại bỏ dòng trống.&lt;/p&gt;

&lt;h5 id=&quot;1nối-nhiều-tệp-để-hiển-thị-ra&quot;&gt;1.Nối nhiều tệp để hiển thị ra&lt;/h5&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;cat file1 file2
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h5 id=&quot;2kết-hợp-nhiều-tệp-cho-ra-file-mới&quot;&gt;2.Kết hợp nhiều tệp cho ra file mới&lt;/h5&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;cat file1 file2 &amp;gt; newfile
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h5 id=&quot;3nối-tệp-vào-tệp-hiện-có&quot;&gt;3.Nối tệp vào tệp hiện có&lt;/h5&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;cat file1 &amp;gt;&amp;gt; existingfile
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h5 id=&quot;4các-dòng-tiếp-theo-được-nhập-đi-vào-tệp-muốn-dừng-nhập-sử-dụng-ctrl--d&quot;&gt;4.Các dòng tiếp theo được nhập đi vào tệp, muốn dừng nhập sử dụng &lt;strong&gt;Ctrl + D&lt;/strong&gt;&lt;/h5&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;cat &amp;gt; file
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Lệnh này tương đương&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;touch file
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h5 id=&quot;5các-dòng-tiếp-theo-sẽ-được-thêm-tiếp-tục-vào-tệp-muốn-dừng-nhập-dùng-ctrl--d&quot;&gt;5.Các dòng tiếp theo sẽ được thêm tiếp tục vào tệp, muốn dừng nhập dùng &lt;strong&gt;Ctrl + D&lt;/strong&gt;&lt;/h5&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;cat &amp;gt;&amp;gt; file
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h5 id=&quot;6hiển-thị-nội-dung-với-lệnh-more-hoặc-less&quot;&gt;6.Hiển thị nội dung với lệnh &lt;em&gt;more&lt;/em&gt; hoặc &lt;em&gt;less&lt;/em&gt;&lt;/h5&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;cat file | more
cat file | less
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Lệnh &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;tac&lt;/code&gt; in các dòng của tệp theo thứ tự ngược lại. Mỗi dòng vẫn giữ nguyên, nhưng thứ tự các dòng được đảo ngược. Cú pháp của lệnh &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;tac&lt;/code&gt; hoàn toàn giống với lệnh &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cat&lt;/code&gt;.&lt;/p&gt;
</description>
        <pubDate>Tue, 01 Oct 2019 01:00:00 +0000</pubDate>
        <link>https://dangduytung.github.io/linux/command/cat</link>
        <guid isPermaLink="true">https://dangduytung.github.io/linux/command/cat</guid>
        
        <category>cat</category>
        
        
        <category>command</category>
        
      </item>
    
      <item>
        <title>Vi</title>
        <description>&lt;p&gt;Có rất nhiều trình soạn thảo trong  Linux nhưng trình soạn thảo vi là trình soạn thảo được nhiều người dùng Linux sử dụng nhất vì là nó chiếm ít tài nguyên mặc khác nó được thiết lập như một trình soạn thảo mặc định trên các bản destroy của Unix.&lt;/p&gt;

&lt;p&gt;Bộ soạn thảo vi chạy ở hai chế độ khác nhau:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Chế độ dòng lệnh command mode, những gì được gõ vào sẽ được hiểu như là lệnh của vi. Vi có rất nhiều lệnh như: tìm kiếm, thay thế, xóa, lưu tâp tin…&lt;/li&gt;
  &lt;li&gt;Chế độ nhập văn bản insert mode, những gì được gõ vào được hiểu là nội dung của tập tin đang soạn thảo.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Khi bắt đầu sử dụng lệnh vi, vi mặc định ở command mode. Ấn phím lệnh i, a, o hoặc Insert  từ chế độ command mode để chuyển sang insert mode.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;i&lt;/code&gt; để thêm ký tự trước con trỏ,&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;a&lt;/code&gt; để thêm ký tự sau con trỏ,&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;o&lt;/code&gt; để chèn thêm dòng mới sau con trỏ.&lt;/li&gt;
  &lt;li&gt;Ấn &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Esc&lt;/code&gt; để chuyển đổi qua lại từ command mode với insert mode.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Một số lệnh với &lt;strong&gt;vi&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;:set nu&lt;/code&gt; hiện thị số dòng&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;:set nonu&lt;/code&gt; bỏ hiện thị số dòng&lt;/li&gt;
  &lt;li&gt;Sử dụng phím mũi tên hoặc các phím h,l,j,k để dịch trái, phải. lên, xuống&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;:1&lt;/code&gt; để nhảy đến dòng đầu tiên của file&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;:n&lt;/code&gt; nhảy đến dòng n&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$&lt;/code&gt; nhảy xuống cuối dòng&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;:$&lt;/code&gt; nhảy đến dòng cuối của file.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;0&lt;/code&gt; nhảy về đầu dòng&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;:0&lt;/code&gt; nhảy về dòng đầu tiên của file.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dd&lt;/code&gt; xóa một dòng hiện tại&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ndd&lt;/code&gt; xóa n dòng&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/&lt;/code&gt; hay &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;?&lt;/code&gt; để tìm kiếm&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;:w!&lt;/code&gt; lưu tập tin&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;:x!&lt;/code&gt; lưu tập tin và thoát&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;:wq&lt;/code&gt; ZZ lưu tập tin và thoát&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;:q!&lt;/code&gt; không lưu và thoát&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;img src=&quot;/linux/images/posts/command/huong-dan-su-dung-vi-trong-linux.png&quot; alt=&quot;Screenshot&quot; /&gt;&lt;/p&gt;
</description>
        <pubDate>Tue, 01 Oct 2019 00:00:00 +0000</pubDate>
        <link>https://dangduytung.github.io/linux/command/vi</link>
        <guid isPermaLink="true">https://dangduytung.github.io/linux/command/vi</guid>
        
        <category>vi</category>
        
        
        <category>command</category>
        
      </item>
    
      <item>
        <title>Redimensionar partições LVM</title>
        <description>&lt;p&gt;Em um post passado, mostrando como fazer a &lt;a href=&quot;/linuxblog/archlinux-lvm-luks/&quot;&gt;instalação do Arch Linux [0]&lt;/a&gt;, utilizei do LVM para gerenciar os discos. Lá falei um pouco mais da teoria por trás dele e tal. Aqui vou me ater mesmo a repassar o passo a passo utilizado para isso.&lt;/p&gt;

&lt;p&gt;Uma questão a ser dita é que o LVM nos dá a possibilidade de poder redimensionar nossas partições sem desligar o sistema. Acontece que a depender de sua aplicação, mesmo que não dê um shutdown no sistema, as consequências podem ser as mesmas. Explico: para aumentar o tamanho da partição é moleza, dá para fazer sem mais nem menos. Agora para diminuir o volume de uma partição tem de desmontá-la e tudo mais. E isso para alguns pode ser um grande problema.&lt;/p&gt;

&lt;p&gt;Mas enfim, vamos lá…&lt;/p&gt;

&lt;h2 id=&quot;reduzir-o-tamanho&quot;&gt;Reduzir o tamanho&lt;/h2&gt;

&lt;p&gt;Digamos que uma partição sua está sendo menos utilizada que outra e que você quer tirar um pouco de espaço dessa determinada partição e colocar na outra. Pois bem, não esqueça de adaptar os endereços aqui para seu cenário, uma breve explicação:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/particao&lt;/code&gt;: endereço no qual a partição que você está usando está montada&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;VolumeGroup&lt;/code&gt;: acredito que o nome já é autoexplicativo&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;LogicalVolume01&lt;/code&gt; e &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;LogicalVolume02&lt;/code&gt;: os nomes também já se explicam, mas a numeração se refere a que o 01 é o volume lógico que irá diminuir de tamanho, enquanto o 02 o que irá aumentar&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;XXG&lt;/code&gt;: nova quantidade de gigas da partição que teve espaço diminuído&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Primeiro, desmonte a partição:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;# umount /particao
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Então, repare o sistema de arquivos:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;# fsck -f /dev/VolumeGroup/LogicalVolume01
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Agora de fato redimensione:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;# resize2fs /dev/VolumeGroup/LogicalVolume01 XXG
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;E então, reduza o tamanho do volume lógico para seu novo espaço:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;# lvreduce -L XXG /dev/VolumeGroup/LogicalVolume01
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Agora monte sua partição numa boa:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;# mount /particao
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;aumentar-tamanho&quot;&gt;Aumentar tamanho&lt;/h2&gt;

&lt;p&gt;Depois que passei por alguns apertos passei a deixar alguns gigas “sobrando” quando ia pensar no esquemas de partições, justamente por essa facilidade da adição em relação à redução. Pois bem, tendo em vista que já se tem o espaço sobrando, como o procedimento acima mostra como fazer, basta seguir:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;# lvextend -L +10G /dev/mapper/main-root
# resize2fs /dev/mapper/main-root
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;E pronto. Agora cheque o tamanho dos discos com &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;df -h&lt;/code&gt; e seja feliz! :)&lt;/p&gt;

&lt;p&gt;Até!&lt;/p&gt;

&lt;h2 id=&quot;links&quot;&gt;Links&lt;/h2&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;[0]: https://dangduytung.github.io/linuxblog/archlinux-lvm-luks/
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

</description>
        <pubDate>Tue, 11 Apr 2017 03:00:00 +0000</pubDate>
        <link>https://dangduytung.github.io/linux/blog/redimensionar-particoes-lvm</link>
        <guid isPermaLink="true">https://dangduytung.github.io/linux/blog/redimensionar-particoes-lvm</guid>
        
        <category>linux</category>
        
        <category>lvm</category>
        
        
        <category>blog</category>
        
      </item>
    
      <item>
        <title>Arch Linux + Tmux = CLI++</title>
        <description>&lt;p&gt;&lt;img src=&quot;/linuximages/posts/2017/01.png&quot; alt=&quot;Screenshot&quot; /&gt;&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Caso queira ver o print maior, &lt;a href=&quot;/linuximages/posts/2017/01.png&quot;&gt;clica aqui [0]&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Primeiro post do blog em 2017, logo no primeiro dia do ano, será que isso quer dizer alguma coisa? haha&lt;/p&gt;

&lt;p&gt;Enfim, temos aqui um screenshot, algo que já queria postar há um tempo, mas enfim, está aqui agora. Nele tem aberto o filme “Lights Out” no Mplayer (\o/) e por trás o Tmux, com ZSH.&lt;/p&gt;

&lt;p&gt;O Tmux é quase o padrão. No arquivo de configuração tem apenas o seguinte:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;bind c new-window -c '#{pane_current_path}'
bind '&quot;' split-window -c '#{pane_current_path}'
bind % split-window -h -c '#{pane_current_path}'
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Contribuição do &lt;a href=&quot;https://github.com/marinofull&quot;&gt;Marino&lt;/a&gt;, que serve para quando abrirmos um novo painel no Tmux, ele persistir o diretório do painel atual.&lt;/p&gt;

&lt;p&gt;Já no ZSH eu utilizo o &lt;a href=&quot;http://ohmyz.sh/&quot;&gt;Oh-My-ZSH [1]&lt;/a&gt; com um tema bem simples que montei:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;setopt promptsubst
PROMPT=$'%B${(r:$COLUMNS::¨:)}$(git_prompt_info)%{$fg[white]%}&amp;gt;&amp;gt; %b%{$reset_color%}'
RPROMPT='%B%*%b'

ZSH_THEME_GIT_PROMPT_PREFIX=&quot;%{$fg[white]%}&quot;
ZSH_THEME_GIT_PROMPT_SUFFIX=&quot;%{$reset_color%} &quot;
ZSH_THEME_GIT_PROMPT_DIRTY=&quot;%{$fg[red]%} *%{$reset_color%}&quot;
ZSH_THEME_GIT_PROMPT_CLEAN=&quot;&quot;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;E lá ao fundo o wallpaper de gatênho! Aqui o link para ele: &lt;a href=&quot;/linuximages/posts/2017/02.jpg&quot;&gt;Gatênho [2]&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Bom, tomara que começar o ano postando algo assim faça vir mais posts e coisas boas por aqui. Até a próxima, pessoal! o/&lt;/p&gt;

&lt;h2 id=&quot;links&quot;&gt;Links&lt;/h2&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;[0]: https://dangduytung.github.io/linuximages/posts/2017/01.png
[1]: http://ohmyz.sh/
[2]: https://dangduytung.github.io/linuximages/posts/2017/02.jpg
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

</description>
        <pubDate>Sun, 01 Jan 2017 12:00:00 +0000</pubDate>
        <link>https://dangduytung.github.io/linux/blog/arch-linux-tmux</link>
        <guid isPermaLink="true">https://dangduytung.github.io/linux/blog/arch-linux-tmux</guid>
        
        <category>archlinux</category>
        
        <category>linux</category>
        
        <category>screenshot</category>
        
        <category>tmux</category>
        
        
        <category>blog</category>
        
      </item>
    
  </channel>
</rss>
