Find the answer to your Linux question:
Results 1 to 7 of 7
Hello all, I am very new to Linux. Here is my scenario There is a directory in linux with alot of sub-directories I want to run a command or script ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Sep 2011
    Posts
    7

    command or script to trim a directory


    Hello all,

    I am very new to Linux. Here is my scenario

    There is a directory in linux with alot of sub-directories

    I want to run a command or script that will delete *.cif files. and Thumbnail_images sub-directory from my directory.


    what is the best way.

  2. #2
    Just Joined!
    Join Date
    Sep 2008
    Location
    Earth
    Posts
    51
    Test this, but should work. Other ways to do this, but this was first that came to mind.
    find $DIRNAME/* -name '*.cif' | xargs rm -f

  3. #3
    Just Joined!
    Join Date
    Sep 2011
    Posts
    7
    will this get rid of "Thumbnail Images" sub- directory itself also because that is what i want.

    In the parent directory BIO delete whatever ends with *.cif and the "Thumbnail Images" directory..

  4. $spacer_open
    $spacer_close
  5. #4
    Just Joined!
    Join Date
    Sep 2008
    Location
    Earth
    Posts
    51
    paste the directory structure, and you wanna keep and what you wanna get rid of. As its pasted it will only rm a file with .cif in its name

  6. #5
    Just Joined!
    Join Date
    Sep 2011
    Posts
    7

    directroy structure

    Quote Originally Posted by Pimpntel View Post
    paste the directory structure, and you wanna keep and what you wanna get rid of. As its pasted it will only rm a file with .cif in its name

    X:\0381\130207_SN381

    under the 130207_SN381 folder there are multiple folders

    X:\0381\130207_SN381\Config
    X:\0381\130207_SN381\Data
    X:\0381\130207_SN381\Logs
    X:\0381\130207_SN381\Recipe
    X:\0381\130207_SN381\Thumbnail_Images

    So, I want all the .cif files deleted from all these folders. Also, i want the whole Thumbnail_images folder deleted with a script.

    appreciate your help.

  7. #6
    Just Joined!
    Join Date
    Sep 2011
    Posts
    7
    the previous admin ran the below command

    find $1 -regextype posix-egrep -regex ".*(\.cif|\.cnf|\.tif|_int.*|_nse.*|Temp.*)" -exec rm -v {} +

    i think this command get rids of all these file extensions but not the "Thumbnail_Images" folder. Does this make sense i am still trying to learn what this script does.

    thanks.

  8. #7
    Linux Enthusiast meton_magis's Avatar
    Join Date
    Oct 2006
    Location
    arizona
    Posts
    699
    Quote Originally Posted by am09 View Post
    X:\0381\130207_SN381

    under the 130207_SN381 folder there are multiple folders

    X:\0381\130207_SN381\Config
    X:\0381\130207_SN381\Data
    X:\0381\130207_SN381\Logs
    X:\0381\130207_SN381\Recipe
    X:\0381\130207_SN381\Thumbnail_Images

    So, I want all the .cif files deleted from all these folders. Also, i want the whole Thumbnail_images folder deleted with a script.

    appreciate your help.
    Code:
    find /path/to/top/directory -type f -name "*.cif" -delete
    find /path/to/top/directory -type d -name "Thumbnail_Images" -delete
    That should take care of you. It will search for all files (type f) under /path/to/top/directory and delete the ones that end in .cif
    Then the second will search for all directories named "Thumbnail_Images" and delete them. I don't know for certain if it works on directories with files in them, so you'll have to test it.
    New to the internet, technical forums, or the hacker / open source community??
    Read this to learn good posting habits http://www.catb.org/~esr/faqs/smart-questions.html

    RHCE for RHEL version 5
    RHCT for RHEL version 4

Posting Permissions

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