1

I want to remove all files and folders in folder /home/user I'm using command

rm -rf /home/user/*

without success, next I tried:

cd /home/user;rm -rf *

Which gives the following output

rm: cannot lstat `*': No such file or directory

How do I solve that? If I'm deleting file one by one, it works, but with "*" it does not.

2
  • Why isn't the first command working? What error are you getting? Apr 7, 2011 at 9:09
  • it does nothing, files still in place
    – user77473
    Apr 7, 2011 at 9:10

3 Answers 3

1

Does your user have read access to the files you want to remove? What are the filenames like? If they begin with a . they may not be picked up by the *.

To delete files starting with . in the current directory, you can use the old trick of find piped to xargs:

find . -name '.*' -maxdepth 1 -type f | xargs rm

Try first without the | xargs rm to see if the files returned by find match what you expect, then run it again with the pipe.

If you want to also look for files recursively, just take the -maxdepth 1 out of the command.

4
  • they are starting with ".". how delete files starting with "."?
    – user77473
    Apr 7, 2011 at 9:12
  • 3
    Advice: Do NOT try rm -rf .*. Depending on your config, this may match "..", ie upwards in the directory structure.
    – carlpett
    Apr 7, 2011 at 9:14
  • solution, i don`t know if is it kind of right, but it works:ls -a | xargs rm -rf
    – user77473
    Apr 7, 2011 at 9:26
  • 3
    For the same reason, if you use that solution, you might want to make that ls -A | xargs rm -rf (captial A is "all files, except '.' and '..').
    – carlpett
    Apr 7, 2011 at 9:53
0

What about:

find /home/user -delete

But be careful - read the man page for find first! Or train a bit in a particular directory.

0

I just use rm -rf /home/user.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .