On this tutorial, we’ll present you methods to use the
rmdir instructions to take away recordsdata and directories in Linux.
How you can Take away Recordsdata
To take away (or delete) a file in Linux from the command line, use both the
rm (take away) or
unlink command permits you to take away solely a single file, whereas with
rm you’ll be able to take away a number of recordsdata without delay.
Be further cautious when eradicating recordsdata or directories, as a result of as soon as the file is deleted, it can’t be simply recovered.
$ unlink filename
$ rm filename
If the file is write-protected, you’ll be prompted for affirmation, as proven beneath. To take away the file sort
y and hit
Enter. In any other case, if the file just isn’t write-protected, will probably be deleted with out prompting.
Output: rm: take away write-protected common empty file 'filename'?
- To delete a number of recordsdata without delay, use the
rmcommand adopted by the file names separated by area.
$ rm filename1 filename2 filename3
You can too use a wildcard (
*) and common expansions to match a number of recordsdata. For instance, to take away all
$ rm *.pdf
When utilizing common expansions, first listing the recordsdata with the
ls command so as to see what recordsdata can be deleted earlier than operating the
-ichoice to substantiate every file earlier than deleting it:
$ rm -i filename(s)
- To take away recordsdata with out prompting even when the recordsdata are write-protected cross the
-f(drive) choice to the
$ rm -f filename(s)
- You can too mix
rmchoices. For instance, to take away all
.txtrecordsdata within the present listing with out a immediate in verbose mode, use the next command:
$ rm -fv *.txt
How you can Take away Directories (Folders)
In Linux, you’ll be able to take away/delete directories with the
rmdir is a command-line utility for deleting empty directories whereas with
rm you’ll be able to take away directories and their contents recursively.
To take away an empty listing, use both
rm -dadopted by the listing identify:
$ rm -d dirname
$ rmdir dirname
- To take away non-empty directories and all of the recordsdata inside them, use the
rmcommand with the
$ rm -r dirname
If a listing or a file throughout the listing is write-protected, you’ll be prompted to substantiate the deletion.
- To take away non-empty directories and all of the recordsdata with out being prompted, use
$ rm -rf dirname
- To take away a number of directories without delay, use the
rm -rcommand adopted by the listing names separated by area.
$ rm -r dirname1 dirname2 dirname3
Identical as with recordsdata you may as well use a wildcard (
*) and common expansions to match a number of directories.
By now it’s best to have a very good understanding of methods to use the Linux
unlink instructions and it’s best to be capable of safely take away recordsdata and directories from the command line.