linux command


Linux Command – rm ใช้ในการลบ file หรือ directory



ตัวอย่าง file และ directory

$ ls -ltr
total 8
-rw-r--r-- 1 root root 70 May 8 16:15 file2
drwxr-xr-x 2 root root 4096 May 9 16:59 filedir


1. ลบ file

rm <file>

$ rm file2


2. ลบ directory

rm -rf <directory>

$ rm -rf filedir



 rm [OPTION]... [FILE]...



เป็นคำสั่งที่ใช้ในการลบ file หรือ directory สามารถใช้สัญลักษณ์ widecard (*) ได้ ในการลบหลายๆ file



 -f, --force
 ignore nonexistent files and arguments, never prompt

 -i prompt before every removal

 -I prompt once before removing more than three files, or when removing recursively; less intrusive than -i, while still giving protection against most mistakes

 prompt according to WHEN: never, once (-I), or always (-i); without WHEN, prompt always

 when removing a hierarchy recursively, skip any directory that is on a file system different from that of the corresponding command line argument

 do not treat '/' specially

 do not remove '/' (default)

 -r, -R, --recursive
 remove directories and their contents recursively

 -d, --dir
 remove empty directories

 -v, --verbose
 explain what is being done

 --help display this help and exit

 output version information and exit

 By default, rm does not remove directories. Use the --recursive (-r or -R) option to remove each listed directory, too, along with all of its contents.

 To remove a file whose name starts with a '-', for example '-foo', use one of these commands:



unlink(1), unlink(2), chattr(1), shred(1)



คำสั่ง Unix – Linux Command

Linux, Unix


Author: Suphakit Annoppornchai


2 Thoughts to “rm – Linux Command คำสั่งลบ file หรือ directory”

  1. […] ใน path ที่ทำงานอยู่ ลงไปใน Shell Script ด้วย rm -rf * / […]

Leave a Reply