Find the answer to your Linux question:
Results 1 to 10 of 10
Like Tree6Likes
  • 1 Post By Mudgen
  • 1 Post By Mudgen
  • 1 Post By Schmidt
  • 1 Post By svenw
  • 1 Post By Mudgen
  • 1 Post By alf55
i want something like: sudo rm -r < sudo find / -name rhythm* or i may do: sudo find / -name rhythm* > rhyth.txt rm -r < rhyth.txt i.e. i ...
  1. #1
    Just Joined!
    Join Date
    Jan 2011
    Location
    Ukraine, Donetsk
    Posts
    5

    linux rm find concatenate

    i want something like:


    sudo rm -r < sudo find / -name rhythm*


    or i may do:



    sudo find / -name rhythm* > rhyth.txt
    rm -r < rhyth.txt


    i.e. i want to find some files and delete them automatically.
    but i don't know syntax.
    how to do this?

  2. #2
    Linux Guru Irithori's Avatar
    Join Date
    May 2009
    Location
    Munich
    Posts
    2,096
    Code:
    find <PATH> -type f -name "rhythm"
    Two notes:
    1) You will need to replace <PATH>. It is not necessary to use / unless these rhyth files were scattered all over the filesystem.
    2) If the above command provides a list, that you can verify, then run it again and add a -delete
    You must always face the curtain with a bow.

  3. #3
    Just Joined!
    Join Date
    Jan 2011
    Location
    Ukraine, Donetsk
    Posts
    5
    thanks
    works fine but tooo slow :
    sudo find / -name rhythm* -delete,


    how to do this with rm?

    i.e. i want that rm reads list of files for deletion:
    rm -r < rhyth.2

  4. #4
    Linux Enthusiast Mudgen's Avatar
    Join Date
    Feb 2007
    Location
    Virginia
    Posts
    623
    Can be done in one line, but if I already have the list in a file I usually do something like

    Code:
    cat rhyth.2|while
    read file
    do
    rm -r $file
    done
    Make sure it's what you want to do first, there's no "unrm". Not easily, anyway.
    shbk likes this.

  5. #5
    Just Joined!
    Join Date
    May 2006
    Posts
    1
    I think what you are looking for is the backtick to immedeately concatenate:

    Code:
    sudo rm -r `find / -name rhythm*`

  6. #6
    Linux Enthusiast Mudgen's Avatar
    Join Date
    Feb 2007
    Location
    Virginia
    Posts
    623
    Quote Originally Posted by woutoo View Post
    I think what you are looking for is the backtick to immedeately concatenate:

    Code:
    sudo rm -r `find / -name rhythm*`
    Which will work fine as long as the backticked argument list doesn't get too long. Hence my tendency to use the for loop.
    shbk likes this.

  7. #7
    Linux Newbie
    Join Date
    Apr 2010
    Location
    Novosibirsk, Russia
    Posts
    136
    Why do not use pipes?...

    Code:
    find <find args> | rm <rm args>
    shbk likes this.

  8. #8
    Just Joined!
    Join Date
    Jun 2005
    Posts
    2
    Code:
    find . -type f -name rhythm\* -print0 | xargs -0 rm
    That will bypass any "max arguments list" encountered by the backtick method. It will alow allow xargs to work on files found in paths with spaces in them, e.g.

    /home/user/documents/old stuff/rhythmbox.txt
    shbk likes this.

  9. #9
    Linux Enthusiast Mudgen's Avatar
    Join Date
    Feb 2007
    Location
    Virginia
    Posts
    623
    ^Bingo. And if you have the list already in a file
    xargs -0 rm < file
    shbk likes this.

  10. #10
    Linux User
    Join Date
    Jan 2005
    Location
    Saint Paul, MN
    Posts
    262
    Quote Originally Posted by shbk View Post
    thanks
    works fine but tooo slow :
    sudo find / -name rhythm* -delete,


    how to do this with rm?

    i.e. i want that rm reads list of files for deletion:
    rm -r < rhyth.2
    To speed "find" up you need less files on your drive or narrow the search to a subtree.

    If you have the list of files to be deleted then you can do:
    Code:
     cat rhyth.2 | xargs rm
    shbk likes this.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...