Unix command deletes each directory, although not specified

I am very new to Unix. I executed the following command.

ls -l | xargs rm -rf bark.*
Team

and above deletes all directories in the folder.

Can someone explain to me why?

+5
source share
3 answers

The team ls -lprovided a list of all subdirectories in the current current working directory (PWD).

A command rmcan delete several files / directories if you transfer them as a list.

for example: rm test1.txt test2.txt myAppdelete all three files with names:

test1.txt
test2.txt
myApp

, rm, , .
rm -f - rm -r -

, , /home/user, :

 /home/user
|->dir1
|->dir2
`->file1.txt

ls -l , "dir1 dir2 file1.txt", ls -l | xargs rm -rf :
rm -rf dir1 dir2 file1.txt

, , , : rm -rf di1 dir2 file1.txt bark.*

, , bark.* ( , ).

, , (recurse), bark. , :
find -iname bark.* | xargs rm

" , UPPERCASE/lowercase/mIxEdCaSe, " bark. " ". , , , , , , .

, , , , .
find -iname bark.* | xargs echo

, , find -iname bark.* | xargs rm

, .

, "rm -rf" : https://github.com/MrMEEE/bumblebee-Old-and-abbandoned/commit/a047be85247755cdbe0acce6f1dafc8beb84f2ac

script - rm -rf /usr/local/........., - rm -rf /usr /local/......, " , usr local", , . .

, , : rm -rf "/usr/ local/...." , , - , / ( : rm, / SPACE ).

+5

-r " " (.. ). -f "force" ( , ). -rf " "

ls -l . xargs ls -l , xargs

, , :

rm -rf bark.* <output of ls -l>

bark.* . : rm -rf. ( rm -ri )

+10

rm(1) , .

, , :

cd /etc ;  ls -l | xargs echo

.

echo rm -rf . , rm -rf. , , rm -r, . rm -ir, . ( Linux 1994 , echo .)

, ls(1) : , ASCII NUL /, , , ls -l. , xargs(1), .

find(1) . bark.*, :

find . -type d -name 'bark.*' -print0 | xargs -0 rm -r

, echo rm -r - , rm -r.

+6

All Articles