remove files or directories
References
man rm
By default, it 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:
rm -- -foo
rm ./-foo
Note that if you use rm to remove a file, it might be possible to recover some of its contents, given sufficient expertise and/or time.
For greater assurance that the contents are truly unrecoverable, consider using shred
.
-r, -R, --recursive
Remove directories and their contents recursively-d, --dir
Remove empty directories
-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
- less intrusive than
--interactive[=WHEN]
Prompt according to WHEN: never, once (-I
), or always (-i
); without WHEN, prompt always
--preserve-root
Do not remove '/' (default)--no-preserve-root
Do not treat '/' specially--one-file-system
_When removing a hierarchy recursively, skip any directory that is on a file system different from that of the corresponding command line argument
rm <file>
# e.g.
rm -rf path/to/file
i for interactive
rm -i <file>
# e.g.
$ rm -i txt
rm: remove regular file ‘txt’? y
Forcedly & Recursively
- It can applied to directory.
rm -rf <file_or_dir>
# e.g.
rm -rf path/to/directory