忍者ブログ

◆当blogは、Linuxサーバ構築する際の実際の設定手順を個人的メモとして記載しております。LinuC試験の役に立つ情報があるかも…?

LinuC(Linux技術者認定資格)&リナックスサーバ構築設定事例

   

【Linux】テストデータ作成と削除の例

#=============================
# テストデータの作成(0バイト)
#-----------------------------
ls -ltr /tmp | grep test.txt
touch -d "2024-08-01 00:00:00" /tmp/test.txt_2024-08-01
touch -d "2024-08-02 00:00:00" /tmp/test.txt_2024-08-02
touch -d "2024-08-03 00:00:00" /tmp/test.txt_2024-08-03
touch -d "2024-08-04 00:00:00" /tmp/test.txt_2024-08-04
touch -d "2024-08-05 00:00:00" /tmp/test.txt_2024-08-05
touch -d "2024-08-06 00:00:00" /tmp/test.txt_2024-08-06
touch -d "2024-08-07 00:00:00" /tmp/test.txt_2024-08-07
touch -d "2024-08-08 00:00:00" /tmp/test.txt_2024-08-08
touch -d "2024-08-09 00:00:00" /tmp/test.txt_2024-08-09
touch -d "2024-08-10 00:00:00" /tmp/test.txt_2024-08-10
touch -d "2024-08-11 00:00:00" /tmp/test.txt_2024-08-11
touch -d "2024-08-12 00:00:00" /tmp/test.txt_2024-08-12
touch -d "2024-08-13 00:00:00" /tmp/test.txt_2024-08-13
touch -d "2024-08-14 00:00:00" /tmp/test.txt_2024-08-14
touch -d "2024-08-15 00:00:00" /tmp/test.txt_2024-08-15
touch -d "2024-08-16 00:00:00" /tmp/test.txt_2024-08-16
touch -d "2024-08-17 00:00:00" /tmp/test.txt_2024-08-17
touch -d "2024-08-18 00:00:00" /tmp/test.txt_2024-08-18
touch -d "2024-08-19 00:00:00" /tmp/test.txt_2024-08-19
touch -d "2024-08-20 00:00:00" /tmp/test.txt_2024-08-20
touch -d "2024-08-21 00:00:00" /tmp/test.txt_2024-08-21
touch -d "2024-08-22 00:00:00" /tmp/test.txt_2024-08-22
touch -d "2024-08-23 00:00:00" /tmp/test.txt_2024-08-23
touch -d "2024-08-24 00:00:00" /tmp/test.txt_2024-08-24
touch -d "2024-08-25 00:00:00" /tmp/test.txt_2024-08-25
touch -d "2024-08-26 00:00:00" /tmp/test.txt_2024-08-26
touch -d "2024-08-27 00:00:00" /tmp/test.txt_2024-08-27
touch -d "2024-08-28 00:00:00" /tmp/test.txt_2024-08-28
touch -d "2024-08-29 00:00:00" /tmp/test.txt_2024-08-29
touch -d "2024-08-30 00:00:00" /tmp/test.txt_2024-08-30
touch -d "2024-08-31 00:00:00" /tmp/test.txt_2024-08-31
#-----------------------------
touch -d "2024-09-01 00:00:00" /tmp/test.txt_2024-09-01
touch -d "2024-09-02 00:00:00" /tmp/test.txt_2024-09-02
touch -d "2024-09-03 00:00:00" /tmp/test.txt_2024-09-03
touch -d "2024-09-04 00:00:00" /tmp/test.txt_2024-09-04
touch -d "2024-09-05 00:00:00" /tmp/test.txt_2024-09-05
touch -d "2024-09-06 00:00:00" /tmp/test.txt_2024-09-06
touch -d "2024-09-07 00:00:00" /tmp/test.txt_2024-09-07
touch -d "2024-09-08 00:00:00" /tmp/test.txt_2024-09-08
touch -d "2024-09-09 00:00:00" /tmp/test.txt_2024-09-09
#-----------------------------
touch -d "2024-09-10 00:00:00" /tmp/test.txt_2024-09-10
touch -d "2024-09-01 12:12:12" /tmp/test.txt_2024-09-01
ls -ltr /tmp | grep test.txt
#=============================
# 指定した日付以前のファイルを削除
#-----------------------------
find /tmp/ -daystart -mtime +6 -name "test.txt_*" -delete
ls -ltr /tmp | grep test.txt
 #-----------------------------
 追加オプション
 -type f ⇒ファイルの場合
 -type d ⇒ディレクトリの場合
 #-----------------------------
 類似したコマンド
 find /tmp/ -daystart -mtime +6 -name "test.txt_*" -exec rm -f {} \;
 find /tmp/ -daystart -mtime +6 -name "test.txt_*" | xargs rm
#=============================
# 日付と時間の取得
#-----------------------------
Date_now=`date "+%Y%m%d_%H%M%S"`
echo ${Date_now}
PR

更新日付

03 2025/04 05
S M T W T F S
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30

RECOMMEND

プロフィール

HN:
Account
HP:
性別:
非公開
職業:
--- NODATA ---
趣味:
--- NODATA ---
自己紹介:
◆当blogは、Linuxサーバ構築する際の実際の設定手順を個人的メモとして記載しております。LinuC試験の役に立つ情報があるかも…?

リンク

<<【Linux】スクリプト用メモ  | HOME |  【Linux】インストール設定例>>
Copyright ©  -- LinuC(Linux技術者認定資格)&リナックスサーバ構築設定事例 --  All Rights Reserved
Design by CriCri / Photo by Melonenmann / powered by NINJA TOOLS / 忍者ブログ / [PR]