Just lost every important files in my Trisquel Linux!!!! Very serious!

17 risposte [Ultimo contenuto]
Iscritto: 07/03/2016

I am still in chock! The last thing i know i was training with find command using xarg to remove files, like explaining in this page:
I was in using this command to erase some *.c files that i created in porpose and then I shut down my system. Later on when I started my machine my Document and Download folder were gone. Auto-completion and color ls were also not working, so I assume bashrc file was gone too wich I confirmed so far!
This is incredible I lost important files! This is serious! How this is possible only by training some find command. this is my last command from my history command before all broke down:
463 sudo find . -name "*.c" | xargs rm -rf
Why this happened? Is it possible to regain my losted files? This is a very serious thing if happens with somebody else!

p.s. I have backups from my files luckily it is not so bad! But still is a very serious issue if happens to somebody who don't make regularly backup files!

Iscritto: 12/31/2012

I tested your command with:

find -name "*.c" | less

... And got every good match, except ".bashrc".

You must have used:

find -name "*c"

... to result in such a mess.

Every time I work with the command line, I do multiple tests to make
sure things would work as expected, and since I'm slow, it takes some
hours to get things running the way I intend them to. Still, even after
testing, some times they work as intended, and other times I have to
test again.

Iscritto: 12/31/2012

Sorry, I know I'm dumb in most things (and slow also, :D), but I
wouldn't go that far as to call someone a dumb/donkey person. Besides,
my portrait is indeed not ideal, but it's the best I have for now. :)

So, regarding the incident: Perhaps I know what happened... Although I'm
not sure how your .bashrc got into the mess...

The issue is that, when xargs receives the path names, the spaces are,
by default, field separators. E.g.:

find -name "*copyright.markdown"

... would find the following paths, starting from my home directory:

./Público/Vídeos/Direito autoral e copyright.markdown
./Público/Documentos/Direito autoral e copyright.markdown

Since xargs understands spaces as field separators, and since find
doesn't put quotes every time it prints a path, then if we would pass it
to xargs, it would understand the following:

"./Público/Vídeos/Direito" "autoral" "e" "copyright.markdown"
"./Público/Documentos/Direito" "autoral" "e" "copyright.markdown"

What we could have done is:

while read -r each_path; do
rm -rf "$each_path"
done <

Iscritto: 09/05/2015

And that, folks, is how you respond extremely generously when someone comes asking for help and proceeds to treat you with offensive disrespect. Obrigado, compa. You're one of the people who consistently keeps this forum a pleasant and supportive environment for new-comers, old-timers, and even the ill-tempered. Um forte abraço !!

Iscritto: 12/31/2012
Iscritto: 12/31/2012

Readers must note: The message to which I'm replying to has more content
than what appears in the forums, see the same comment in the
trisquel-users mailing list for the complete message (with more command


I am a translator!

Iscritto: 10/31/2014

Actually his photo is very nice and he is a very nice dood. I cannot say the same of you. Spitting out nonsense shit on someone who tries to help you speaks loud of yourself, and you should maybe not write at all here, not until you learn some common decency anyway.

Magic Banana

I am a member!

Iscritto: 07/24/2010

The command you mention removes all .c files/directories in the working directory and below, unless you mistyped it like other members of this forum wrote. If you did not mistype the command, then you must have done something else that led to the involuntary remotion of many of your files.

Iscritto: 04/05/2012

If you create a directory and a file like this

mkdir 'x ./'
touch 'x ./ x.c'

and try the find command, you will have a match

x ./ x.c

Now if you pipe this into xargs rm you don't have just one path. You have three


The middle one is the current directory. So all will be gone.

You are right. The command is not safe.

But you should anyway understand a command before using it.

The sudo command seems pointless here. Giving recursive flag (-r) to rm doesn't make sense since you seem to have been only trying to delete files, not whole directories. In the example I gave having rm without the flag would only delete the .c file.

Hope you get your files back.

Iscritto: 12/10/2013

You probably have spaces in your filenames (perhaps your home directory). In this case, not using -rf would have mitigated the damage.
But, you shouldn't use xargs with find. Instead, use the -exec option like this:
$ find . -name '*.c' -exec rm {} \;
That way, you don't have to worry about spaces.

If you have a backup, just use that. Otherwise, try using photorec: http://www.cgsecurity.org/wiki/PhotoRec

Iscritto: 01/22/2011

By default xargs uses both spaces and newlines as item delimiters. The -d "\n" option tells xargs to use only newlines as delimiters, thus avoiding this problem in this context.
$ find ./ -name "*.c" | xargs -d "\n" rm

Iscritto: 12/16/2009

To add to what jbar suggests, it's even better to write:

find -name '*.c' -print0 | xargs -0 rm

Doing it this way should be even safer since names may have new lines in them (almost never in reality, but it's possible).

I would also suggest adding an echo before rm or any other command you run in this way, so you can see what's going to be done before doing it:

find -name '*.c' -print0 | xargs -0 echo rm
Iscritto: 12/16/2009

Or you could use:

find -name '*.c' -exec rm {} +

Which should be even better.

Iscritto: 07/03/2016

Thank you all for the replies, thank you very much!
But first of all I want to apologise to ADFENO. What I said it was not right, i Admit. Even if I was furious due to that event it was no way an excuse to talk to somebody like that. Sorry ADFENO and sorry to all the Forum.
Desculpa colega, voce tem ajudado sempre aqui no forum e eu fui ingrato e mal educado com voce. ao deveria nunca ter dito o que disse: Desculpa.

Iscritto: 12/31/2012

Don't worry mate, I accept your apologies.

I'm glad that you didn't insist on calling me like that again and again
(I know some people that are really difficult to deal with because of

We all know that humans experience pressure due to external factors, and
everyone reacts differently everytime.

Just remember to share your questions regarding free/libre software
movement or free/libre software in general, even if you might already
have an answer for them. :)

Iscritto: 07/03/2016

Thanks I will continue to make questions if there are any. Abracao

Iscritto: 01/22/2015

One thing you could do to prevent such accidental data loss
in the future is changing the default behaviour of the rm command for example with aliases.

This is what i have in my /etc/bash.bashrc to do this job:

alias rm='rm -div'
alias rrm='\rm -IRv'

alias mv='mv -iv'

alias cp='cp -iv'
alias cpr='cp -r'

I've never had any problems with these.
There is also to mention the package safe-rm in the repository, but i never tried it.
Take a look at the info or man pages of rm, mv and cp to see what exactly all these options do.