Linux Inspirations

Menghapus file berdasarkan extension tertentu

Posted on: 22 Mei, 2008

To remove multiple files such as *.jpg or *.sh with one command find, use
find . -name “FILE-TO-FIND”-exec rm -rf {} \;

OR

find . -type f -name “FILE-TO-FIND” -exec rm -f {} \;


The only difference between above two syntax is that first command can remove directories as well where second command only removes files.

More Examples of find command

(a) Find all files having .bak (*.bak) extension in current directory and remove them:
$ find . -type f -name “*.bak” -exec rm -f {} \;

(b) Find all core files and remove them:
# find / -name core -exec rm -f {} \;

(c) Find all *.bak files in current directory and removes them with confirmation from user:
$ find . -type f -name “*.bak” -exec rm -i {} \;

Output:

rm: remove regular empty file `./data0002.bak’? y
rm: remove regular empty file `./d234234234fsdf.bak’? y
rm: remove regular empty file `./backup-20-10-2005.bak’? n

Caution: Before removing file makes sure, you have backup of all-important files. Do not use rm command as root user it can do critical damage to Linux/Unix system.

Source : http://www.cyberciti.biz/faq/linux-unix-how-to-find-and-remove-files/

Tinggalkan Balasan

Please log in using one of these methods to post your comment:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s

ABout Me!


WordPress ini sengaja saya buat untuk menulis apa yang telah saya lakukan agar saya selalu ingat, tulisan yang saya buat kebanyakan dalam bentuk tutorials configurasi linux dari hasil uji coba saya dan sebahagian di kutip dari beberapa website lain yang saya anggap perlu untuk saya tulis disini. Mudah-mudahan tutorial yang saya buat ini berguna buat pencinta linux yang lain. Salam Sejahtera.

Blog Stats

  • 120,467 hits

Linux Inspiration

%d blogger menyukai ini: