Command : ค้นหาไฟล์และลบออก


ในการหาไฟล์บน linux นั้นส่วนมากผมจะชอบใช้คำสั่ง find ในการค้นหา คราวนี้ผมมีความคิดว่าสมมติผมต้องการลบไฟล์ขยะหรือไฟล์สำรองที่ถูกสร้างมาจาก gedite เช่น name.sh~ , index.php~ ซึ่งไฟล์พวกนี้มันอยู่เต็มเครื่องผมไปหมดหลังจากที่ใช้ gedite ในการแก้ไข

จะให้มานั่งลบทีละไฟล์ก็ใช่เรื่องเลยต้องใช้คำสั่ง command line พระเอกของเราช่วยซะหน่อย

Linux or UNIX - Find and remove file syntax

find . -iname "FILE-TO-FIND" -exec rm -rf {} \;
เช่น
sudo find / -iname "*~" -exec rm -rf {} \;
อันนี้ก็จะหาจาก root directory และหาไฟล์ทั้งหมดที่มีชื่อลงท้ายด้วย ~ จากนั้นก็นำไปรันคำสั่ง rm -rf ต่อเพื่อทำการลบ

ที่มา : http://www.cyberciti.biz/faq/linux-unix-how-to-find-and-remove-files/


Comments

Post new comment

The content of this field is kept private and will not be shown publicly. If you have a Gravatar account, used to display your avatar.
  • HTML tags will be transformed to conform to HTML standards.

More information about formatting options

CAPTCHA
คำถามนี้ทดสอบว่าคุณมีความรู้ทางคณิตศาสตร์ ไม่ได้โง่!!!
2 + 3 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.