複数のファイルを削除する(exec、loop..)

複数のファイルを削除する(exec、loop..)

削除するファイルは次の形式でたくさんあります。

esymac_logEvents.log.5_2017-Feb-06_02-39-17.Z_2017-Feb-08_02-39-14.Z_2017-Feb-09_02-39-14.Z_2017-Feb-11_02-39-11.Z_2017-Feb-13_02-39-08.Z_2017-Feb-16_02-39-05.Z_2017-Feb-18_02-39-3.Z_2017-Feb-20_02-39-02.Z_2017-Mar-02_12-06-57

esymac_logEvents.log.6_2017-Feb-07_02-39-15.Z_2017-Feb-08_02-39-14.Z_2017-Feb-09_02-39-14.Z_2017-Feb-16_02-39-05.Z_2017-Feb-18_02-39-03.Z_2017-Feb-19_02-39-03.Z_2017-Feb-20_02-39-2.Z_2017-Feb-21_02-38-55.Z

esymac_logEvents.log.6_2017-Feb-07_02-39-15.Z_2017-Feb-09_02-39-14.Z_2017-Feb-12_02-39-10.Z_2017-Feb-15_02-39-06.Z_2017-Feb-16_02-39-05.Z_2017-Feb-17_02-39-04.Z_2017-Feb-19_02-39-3.Z_2017-Feb-20_02-39-02.Z_2017-Feb-21_02-38-55.Z

esymac_logEvents.log.6_2017-Feb-10_02-39-12.Z_2017-Feb-15_02-39-06.Z_2017-Feb-18_02-39-03.Z_2017-Feb-19_02-39-03.Z_2017-Feb-20_02-39-02.Z_2017-Feb-21_02-38-55.Z

esymac_logEvents.log.5_2017-Feb-06_02-39-17.Z_2017-Feb-07_02-39-15.Z_2017-Feb-10_02-39-12.Z_2017-Feb-19_02-39-03.Z_2017-Feb-22_02-39-05.Z_2017-Feb-23_02-39-09.Z

esymac_logEvents.log.5_2017-Feb-06_02-39-17.Z_2017-Feb-08_02-39-14.Z_2017-Feb-11_02-39-11.Z_2017-Feb-12_02-39-10.Z_2017-Feb-14_02-39-07.Z_2017-Feb-15_02-39-06.Z_2017-Feb-17_02-39-4.Z_2017-Feb-22_02-39-05.Z_2017-Feb-23_02-39-09.Z

esymac_logEvents.log.6_2017-Feb-09_02-39-14.Z_2017-Feb-13_02-39-08.Z_2017-Feb-17_02-39-04.Z_2017-Feb-19_02-39-03.Z_2017-Feb-21_02-38-55.Z

esymac_logEvents.log.6_2017-Feb-07_02-39-15.Z_2017-Feb-08_02-39-14.Z_2017-Feb-11_02-39-11.Z_2017-Feb-12_02-39-10.Z_2017-Feb-14_02-39-07.Z_2017-Feb-15_02-39-06.Z_2017-Feb-17_02-39-04.Z_2017-Feb-22_02-39-05.Z_2017-Feb-23_02-39-09.Z

削除したいのですが、rm()コマンドで「引数リストが大きすぎます」というエラーが発生します。同様の投稿を確認しても自分でコマンドを作成できない場合は、次のコマンドを取得する方法はありますか?

  • まず、すべてのesymac_logEvents.log.*ファイルを使用してパラメータリストを作成し、
  • ループまたはexecコマンドを使用してファイルを1つずつ削除します(
    一度に1つずつ削除しないことも、rm()関数が受け取ることができる引数の最大数を削除することをお勧めします)。

乾杯。

答え1

find /search/dir -name esymac*whatever*pattern* -exec rm \{\} \;

答え2

上記とは異なる形式のすべてのファイルを保持するには、次の手順を実行します。

  1. これを実行してください。これにより、FilesToDelete.txt削除するファイル/ディレクトリが入力されます。リストされているファイルが実際に削除したいファイルであることを確認するには、それを確認してください。

    find /path/to/dir/esymac_logEvents.log* | xargs ls -l > FilesToDelete.txt

  2. 手順1を確認したら、次の操作を行います。

    find /path/to/dir/esymac_logEvents.log* -type f | xargs rm -f

  3. 削除するディレクトリもある場合は、2をスキップして次の手順を実行します。

    find /dir/that/contains/esymac_logEvents.log* | xargs rm -rf

関連情報