Find the answer to your Linux question:
Results 1 to 5 of 5
I need to delete a number of files that are some levels down within a higher-level directory. All the files have the same name. (ex.-- I have a directory named ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jan 2005
    Posts
    1

    Need to delete a bunch of files


    I need to delete a number of files that are some levels down within a higher-level directory. All the files have the same name. (ex.-- I have a directory named /abc, and it contains directories /bcd, /cde, /def, /efg, and so on. each of these contains other files and directories. I need to delete a file named xyz.123 that is somewhere within each of these directories).

    Is there a recursive "rm" - type command I can use to do this, or is it faster to do a find, using a GUI such as KDE, and then delete the files from the find dialog?

    Thanks for the help,

    Bob

  2. #2
    Just Joined!
    Join Date
    Jan 2005
    Posts
    2
    something to the effect of:

    find . -name 'xyz.123' -exec rm "{}" \;

  3. #3
    Just Joined!
    Join Date
    Dec 2004
    Location
    Worcester EN UK
    Posts
    31

    Try whereis

    Try typing

    Code:
    # whereis xyz.123
    and see what comes up. If it doesn't work, try to get hold of the package, or 'locate'. There is a recursive rm command, but you need to know exactly which directory to delete, for example you have a directory called bar in one called foo. You want to delete bar (which contains files to delete too), so you would type:

    Code:
    # cd foo
    # rm -r bar
    To find out about a command, type man command, such as man rm. If you despair, there's no shame in using X for it; it makes it easier, after all.

    I assume you're using Debian, it's the best after all, (and why would you be in the Debian forum if you weren't?), so to get locate, type

    Code:
    $ su -
    # apt-get install findutils
    # updatedb
    # exit
    $
    You should need the original discs, or it'll use the internet, but either way works.

  4. #4
    Linux Guru lakerdonald's Avatar
    Join Date
    Jun 2004
    Location
    St. Petersburg, FL
    Posts
    5,035
    Though rm is aliased to rm -i for root on most distros, so unless you want to get prompted, then:
    Code:
    rm -rf foo

  5. #5
    Just Joined!
    Join Date
    Dec 2004
    Location
    Worcester EN UK
    Posts
    31

    rm -f isn't clever unless POSITIVE

    Well, naturally, but it's always best to stay interactive unless you're totally confident with your typing abilities, or plain arrogant (like me).

Posting Permissions

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