You need to use the rm command. It tries to remove the files specified on the command line. Use the rm command to delete files and directories on CentOS Linux. This page shows how to delete and remove files on CentOS Linux.
Command to delete and remove files on CentOS Linux
The syntax is as follows for the rm and unlink command to remove files on CentOS Linux:
- Open the terminal application (bash shell)
- Type any one of the following command to delete a file named nixcraft.txt in the current directory
- rm nixcraft.txt
OR
unlink nixcraft.txt
Let use see all rm command options to delete and remove files on CentOS Linux.
Delete multiple files
Type the following command to delete the file named foo.txt, bar.doc, and dance.jpg located in the current directory:
rm foo.txt bar.doc dance.jpg
You can specify path too. If a file named foo.txt located in /tmp/ directory, you can run:
rm /tmp/foo.txt
rm /tmp/foo.txt /home/vivek/dance.jpg /home/vivek/data/bar.doc
CentOS Linux delete a file and prompt before every removal
To get confirmation before attempting to remove each file pass the -i option to the rm command on CentOS Linux:
rm -i filename
rm -i foo.txt
Force rm command on CentOS Linux to explain what is being done with file
Pass the -v option as follows to get verbose output on CentOS Linux box:
rm -v filename
rm -v cake-day.jpg
Centos Linux delete all files in folder or directory
You need to pass the following options:
rm -rf dir1
rm -rf /path/to/dir/
rm -rf /home/vivek/oldschoolpics/
It will remove all files and subdirectories from a directory. So be careful. Always keep backups of all important data on CentOS Linux.
CentOS Linux delete file begins with a dash or hyphen
If the name of a file or directory or folder starts with a dash (- or hyphen --), use the following syntax:
rm -- -filename
rm -- --filename
rm -rf --dirname
rm ./-file
rm -rf ./--dirname
Do not run ‘rm -rf /‘ command as an administrator/root or normal CentOS Linux user
rm -rf (variously, rm -rf /, rm -rf *, and others) is frequently used in jokes and anecdotes about CentOS Linux disasters. The rm -rf / variant of the command, if run by an administrator, would cause the contents of every writable mounted filesystem on the computer to be deleted. Do not try these commands on CentOS Linux:
rm -rf /
rm -rf *
- How to delete and remove files on Fedora Linux
- How to delete and remove files on CentOS Linux
- How to delete and remove files on SUSE Enterprise Linux
- How to delete and remove files on Ubuntu Linux
- How to delete and remove files on RHEL (Red Hat) Linux
- How to delete and remove files on Arch Linux
- How to delete and remove files on Alpine Linux
- How to delete and remove files on Debian Linux
🐧 0 comments... add one ↓
Category | List of Unix and Linux commands |
---|---|
File Management | cat |
Firewall | Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04 |
Network Utilities | dig • host • ip • nmap |
OpenVPN | CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04 |
Package Manager | apk • apt |
Processes Management | bg • chroot • cron • disown • fg • jobs • killall • kill • pidof • pstree • pwdx • time |
Searching | grep • whereis • which |
User Information | groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w |
WireGuard VPN | Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04 |