1

I have a folder in linux that contains .csv files of the results of some simulations.

The name of the files are like:

run_0_0.020000_0.010000_15.0_10.0_T0_RealNet.csv
run_0_0.030000_0.090000_10.0_10.0_T0_RealNet.csv
run_0_0.030000_0.080000_12.0_10.0_T0_RealNet.csv

I want to remove all the files except the ones with 15.0_10.0_T0_

emax
  • 6,965
  • 19
  • 74
  • 141
  • 2
    Possible duplicate of [Remove all files except some from a directory](https://stackoverflow.com/questions/4325216/remove-all-files-except-some-from-a-directory) – NanoPish Jul 26 '18 at 12:16
  • Please avoid *"Give me the codez"* questions. Instead show the script you are working on and state where the problem is. Also see [How much research effort is expected of Stack Overflow users?](https://meta.stackoverflow.com/q/261592/608639) – jww Jul 26 '18 at 20:38

4 Answers4

3

You could use the find command with its built in -delete feature but probably simpler if you just $ cp /path/to/dir/*15.0_10.0_T0_* /other/dir then remove the original directory. You can then move the new directory in place of the original. You can remove the old directory with all its contents at once with $ rm -rf /path/to/dir.

HoldOffHunger
  • 18,769
  • 10
  • 104
  • 133
marekful
  • 14,986
  • 6
  • 37
  • 59
1

For example, if you dont want to delete files that contain 15.0_10.0_T0_, you can use find:

find . -type f ! -name '*15.0_10.0_T0_*' -delete
NanoPish
  • 1,379
  • 1
  • 19
  • 35
0

Another variant to remove everything but the requested files:

ls --ignore="*15.0_10.0_T0_*" | xargs rm

Or a shortened, don't ask and remove also dir version (take with care :) ):

ls -I "*15.0_10.0_T0_*" | xargs rm -rf
Giuseppe Ricupero
  • 6,134
  • 3
  • 23
  • 32
-2

use mv /dire/15.0_10.0_T0_* to destination dir then delete whole directory by using sudo rm -rf directory name. Hope it works.

Admin Hack
  • 67
  • 2
  • 4