Search code examples
linuxubuntuswitch-statementrm

Linux how to use rm and exclude switch


I was wondering how we can use linux rm command with --exclude switch?

For example like grep has exclude function when searching over the files.


Solution

  • Here is one specific

    rm `find . -name "safe_room*" ! -name "safe_rooms.php"`
    

    I used it mainly for git

    git rm `find . -name "safe_room*" ! -name "safe_rooms.php"`
    

    Explanation:

    rm - linux command for delete

    `` - the signs used within mysql. on keyboard CTRL + 7

    find . -name "safe_room*" - find everything with safe_room*

    ! - NOT logical operator

    -name "safe_rooms.php" - exclude everything except safe_rooms.php

    Hope this will help :)