Ana içeriğe geç
eLearner.app
Modül 2 · Ders 3 ders 3Kurstaki 5/11~8 min
Modül dersleri (3/3)

Kaynakların silinmesi (rm)

To delete files and directories in the terminal, use the command:

Bash
rm [path]

This command stands for Remove.

[!WARNING] Unlike files deleted via a graphical user interface (desktop), files deleted in the terminal with rm do not go to the trash bin. They are deleted instantly and permanently. Use it with extreme caution!


Deleting Files

To delete a single file in the current directory:

Bash
rm notes.txt

Deleting Directories Recursively with -r

If you try to delete a directory using just rm, the terminal will display an error stating that the target is a directory. To remove a directory and all files and subdirectories within it, you must specify the -r (recursive) option:

Bash
rm -r folder_to_delete

Forcing Removal with -f

Sometimes you may get confirmation prompts asking if you really want to delete write-protected files, or errors if a file does not exist. The -f (force) option forces deletion without asking for confirmation and ignores non-existent files:

Bash
rm -rf folder_to_delete

The combined -rf option is one of the most powerful and feared commands in the command line: it deletes everything instantly with no warnings.


Usage Examples and Common Errors

If you try to delete a directory without specifying the recursive -r option, the rm command will fail with an error:

Bash
rm backup
# Output:
# rm: cannot remove 'backup': Is a directory

To remove multiple files in a single command, list them one after another separated by spaces:

Bash
rm file1.txt file2.txt

Try it yourself

Exercise 1: Delete an obsolete file

Egzersiz#linux.m2.l3.e1
Denemeler: 0Yükleniyor…

Delete the file 'old_notes.txt' from the current folder.

Düzenleyici yükleniyor…
İpucu göster

Use the rm command followed by the exact filename.

3 denemeden sonra çözüm mevcut

Exercise 2: Remove a backup folder

Egzersiz#linux.m2.l3.e2
Denemeler: 0Yükleniyor…

Delete the 'backup' folder and all its contents recursively.

Düzenleyici yükleniyor…
İpucu göster

Use rm with the recursive -r flag and specify the folder name.

3 denemeden sonra çözüm mevcut

Exercise 3: Delete multiple files

Egzersiz#linux.m2.l3.e3
Denemeler: 0Yükleniyor…

Delete both the 'report.txt' and 'old_notes.txt' files at the same time by listing them both as arguments to the rm command.

Düzenleyici yükleniyor…
İpucu göster

Use the rm command followed by report.txt and old_notes.txt separated by a space.

3 denemeden sonra çözüm mevcut