To delete a file in Linux, you can use the rm
command followed by the name of the file you want to delete. For example:
rm file_to_delete
This will delete the file called file_to_delete
if it exists in the current working directory.
To delete a file in a different directory, you can specify the path to the file. For example:
rm /path/to/file_to_delete
You can also delete multiple files at once by specifying multiple filenames separated by spaces. For example:
rm file1 file2 file3
To delete all files in the current directory with a certain extension, you can use the *
wildcard. For example:
rm *.txt
This will delete all files with the .txt
extension in the current directory.
You can use the -f
option to force the deletion of the file, even if it is not writable or if you do not have permission to delete it. For example:
rm -f file_to_delete
Be careful with the rm
command, as it cannot be undone.
For more information, you can consult the rm
man page by running man rm
on the command line.