To delete files and directories in Bash, you can use the rm
command for files and the rmdir
command for directories.
Deleting a file:
rm <filename>
Replace <filename>
with the actual name of the file you want to delete. For example, to delete a file named "example.txt", you would use rm example.txt
.
Deleting an empty directory:
rm -r <directoryname>
Replace <directoryname>
with the actual name of the directory you want to delete. For example, to delete an empty directory named "directory", you would use rm -r directory
.
Deleting a directory and its contents:
rm -rf <directoryname>
Replace <directoryname>
with the actual name of the directory you want to delete. The -rf
option is used to forcefully delete the directory and its contents recursively. Use this command with caution as it can permanently remove important data without any prompt.
Before deleting files or directories, make sure to review your actions carefully as they cannot be undone.