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

17 replies [Last post]
Offline
Joined: 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:
ekstuff.com/2013/12/xargs-examples/
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!

Offline
Joined: 12/31/2012

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.

Offline
Joined: 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.:

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

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:

What we could have done is:

rm -rf "$each_path" done < Offline Joined: 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 !! Offline Joined: 12/31/2012 Offline Joined: 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 options): I am a translator! Offline Joined: 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. I am a member! Offline Joined: 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. Offline Joined: 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 x ./ x.c 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. Offline Joined: 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

Offline
Joined: 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

Offline
Joined: 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

Offline
Joined: 12/16/2009

Or you could use:

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


Which should be even better.

Offline
Joined: 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.

Offline
Joined: 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
this).

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. :)

Offline
Joined: 07/03/2016

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

Offline
Joined: 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.