2

UPDATE

Status of the process for the command rm -rf ~/.local/share/Trash/files/ has been set to Very High. Command was initiated at 0745 today and is still running. CPU Time is current 53 seconds at 0955, memory is constant at 52.0 miB. Status goes between Running and Uninteruptible


I opened up nano yesterday to just look at a file and noticed that inside of my home directory I have a very large amount of files in there that can be deleted. They are there because awhile back I accidentally turned my home directory into a git repo. I undid this, but I want to clean up the mess that I could only see when viewing the folder when searching for a file using nano.

I have this same problem in my trash bin where I have so many files in it from bad git repos that I cannot just click on the trash bin and click empty bin all 8 gigs plus the swap get used up and nothing gets deleted.

How can I delete files from the terminal where the files meet a certain pattern? I have tried the following command:

rm -rf ~/.local/share/Trash/Files/*

rm -rf ~/.local/share/Trash/info/*

and I eventually some time later get a message that there are just to many files and it does not delete.

I would like to say delete all files that start or end with some pattern like .quo or whatever they might be. To sum it up:

How do I list all the files so that I can at least start finding some begining or ending patterns to identify those for deletion How do I use that pattern to delete them?

2
  • 1
    Use the find command: find /path/to/directory/ -name *pattern*. If that lists the right files, delete them with find /path/to/directory/ -name *pattern* -exec rm {} \;. The exec option exectutes the rm command, where {} is substituted by the filename. The \; bit signifies the end of the rm command.
    – Jos
    May 1, 2014 at 12:48
  • Thank you I will try this tonight when I get home and let you know what happens May 1, 2014 at 12:56

1 Answer 1

3

The error you are getting is because you have too many files which means that * in your rm command is expanded to a list that is longer than the limit (ARG_MAX). So, to get around this you have various options:

  1. Give rm only some of the files:

    rm -rf ~/.local/share/Trash/Files/*.quo
    
  2. Delete the directory containing the files, this avoids listing the files altogether:

    rm -rf ~/.local/share/Trash/Files/
    
  3. Use find:

    find ~/.local/share/Trash/Files/ -delete
    

    or, for non-GNU find:

    find ~/.local/share/Trash/Files/ -exec rm {} +
    
  4. Use a shell loop

    for file in  ~/.local/share/Trash/Files/*; do rm "$file"; done
    
5
  • as of right now it has been running for 20 minutes, I went to the path ~/.local/share/Trash and did rm -rm files will update later May 2, 2014 at 1:43
  • the following command rm -rf ~/.local/share/Trash/files/ has been running for two hours now, when I go to process properties it says the CPU use is 0% and CPU time is 48 seconds, resident memory remains constant at 52.5 mb, status switches between Uninterubtible and running May 2, 2014 at 13:46
  • @MCP_infiltrator that's fine. There's no reason for that command to use significant CPU or memory and if you are deleting several gigabytes of files it can take ages. You can also try running rm -rfv ~/.local/share/Trash/Files/ which will list the files being deleted (the -v means "verbose"). That way, you can be sure it's doing something.
    – terdon
    May 2, 2014 at 14:34
  • Thank you, did not know that. I'm going to stop the current process and use that one instead and report back May 2, 2014 at 14:40
  • no need, it just finished, thank you for your help i really appreciate it. May 2, 2014 at 14:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.