0

This question already has an answer here:

Under /var/log/hive we have a lot of log files

we want to remove all files exclude the following that should be not removed

hivemetastore.log
hiveserver2-report.json.tmp
hivemetastore-report.json.tmp

marked as duplicate by jimmij, roaima, Kusalananda linux Aug 7 '18 at 9:18

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 2
  • 1
    we have couple files to exclude , this post talk about one file to exclude – yael Aug 7 '18 at 8:33
  • this is not duplicate as I mentioned the post talk about one file for exclude and I need couple file to exclude – yael Aug 7 '18 at 8:45
1

As stated in the question 153862 mentioned by Kamaraj, use find. Just use multiple entries of ! -name:

$ ls
hivemetastore.log  hivemetastore-report.json.tmp  hiveserver2-report.json.tmp  1  2  3  4
$ find . ! -name 'hivemetastore.log' ! -name 'hivemetastore-report.json.tmp' ! -name 'hiveserver2-report.json.tmp' -type f -exec rm -f {} +
$ ls
hivemetastore.log  hivemetastore-report.json.tmp  hiveserver2-report.json.tmp
0

Going off of @Kamaraj's comment - you can use find to look for multiple files using the -o switch, and then negate it and use -exec to rm the rest.

List all files except the ones named:

find . -type f ! \( -name 'hivemetastore.log' -o -name 'hiveserver2-report.json.tmp' -o -name 'hivemetastore-report.json.tmp' \)

Chain an exec to rm those files:

find . -type f ! \( -name 'hivemetastore.log' -o -name 'hiveserver2-report.json.tmp' -o -name 'hivemetastore-report.json.tmp' \) -exec rm -f {} +
0

Try this,

To get the list of files other than hivemetastore.log ,hiveserver2-report.json.tmp, hivemetastore-report.json.tmp :

find  /var/log/hive -type f ! -name "hivemetastore.log" ! -name "hiveserver2-report.json.tmp" ! -name "hivemetastore-report.json.tmp" -print

To delete and get the list of deleted files:

find  /var/log/hive -type f ! -name "hivemetastore.log" ! -name "hiveserver2-report.json.tmp" ! -name "hivemetastore-report.json.tmp" -delete -print

Not the answer you're looking for? Browse other questions tagged or ask your own question.