remove the content in directory and subdirectory hierarichally with out distroy the directory structure

Posted by user3713876 on Stack Overflow See other posts from Stack Overflow or by user3713876
Published on 2014-06-12T03:01:05Z Indexed on 2014/06/12 3:25 UTC
Read the original article Hit count: 90

Filed under:
|

In shell script,

I want to clear only text files and log files in the following structure with out removing the directory as well as subdirectories

|
|------bar/
    |
    |---file1.txt
    |---file2.txt
    |
    |---subdir1/
    |   |---file1.log
    |   |---file2.log
    |
    |---subdir2/
        |---image1.log
        |---image2.log

I am using rm -rf /bar/* so I am getting the result as follows.

|------bar/

but I want the output like following

|
|------bar/
    |
    |
    |
    |
    |---subdir1/
    |   
    |   
    |
    |---subdir2/

I want to remove only text files or log files or csv with out removing the directory and the subdirectories

© Stack Overflow or respective owner

Related posts about linux

Related posts about shell