I am very new to the unix. I ran the following command.
ls -l | xargs rm -rf bark.*
and above command removed every directory in the folder.
Can any one explained me why ?
To remove a directory and all its contents, including any subdirectories and files, use the rm command with the recursive option, -r . Directories that are removed with the rmdir command cannot be recovered, nor can directories and their contents removed with the rm -r command.
To remove a directory that is not empty, use the rm command with the -r option for recursive deletion.
Syntax: rm command to remove a file-r : Remove the contents of directories recursively.
The -r
argument means "delete recursively" (ie descend into subdirectories). The -f
command means "force" (in other words, don't ask for confirmation). -rf
means "descend recursively into subdirectories without asking for confirmation"
ls -l
lists all files in the directory. xargs
takes the input from ls -l
and appends it to the command you pass to xargs
The final command that got executed looked like this:
rm -rf bark.* <output of ls -l>
This essentially removed bark.*
and all files in the current directory. Moral of the story: be very careful with rm -rf
. (You can use rm -ri
to ask before deleting files instead)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With