เกร็ดคำสั่ง find

(ศึกษาเพราะต้องการเอาไฟล์ในคลังของ apt-proxy เฉพาะไฟล์ใหม่ ๆ เลยต้องการลบไฟล์เก่า ๆ ทิ้ง เพื่อให้ขนาดคลังแพ็กเกจเล็กลง)

เริ่มเลยครับ

ต้องการค้นหาไฟล์ชื่อ *Doc*

$ find /PATH/TO/FILE -name '*Doc*'

ค้นหาและลบไฟล์

$ find /PATH/TO/FILE -name '*Doc*' -exec rm {} \;

ค้นหาไฟล์ที่เก่ากว่า 5 วันลงไป

$ find /PATH/TO/FILE -mtime +5

ค้นหาไฟล์เก่าตั้งแต่ 5 วันขึ้นมา

$ find /PATH/TO/FILE -mtime -5

ค้นหาไฟล์เก่ากว่า 1 ปีลงไป และลบไฟล์เหล่านั้นทิ้ง

$ find /PATH/TO/FILE -mtime +365 -exec rm {} \;

*** ใช้ด้วยความระมัดระวังนะครับ ***

วันนี้แค่นี้ก่อนครับ

อ้างอิง

Re: เกร็ดคำสั่ง find

อีกวิธีครับ

$ find /PATH/TO/FILE -name '*Doc*' | xargs rm -fv

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <pre> <blockquote> <img> <h3> <h4> <h5>
  • Lines and paragraphs break automatically.
  • E-Mail addresses are hidden with reCAPTCHA Mailhide.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.