Linux stoppt den Dienst nicht, um die Protokolldatei schnell zu löschen (einschließlich aller Dateien, nicht nur des Protokolls).

Mit den folgenden Vorgängen können nicht nur Protokolle wie nohup.log, sondern auch alle Dateien, einschließlich txt usw., gelöscht werden.

Der erste: cat /dev/null > ./nohup.log

[root@redhat75::~]# ll -h
total 216K
-rw-------. 1 root root 2.0K May 27  2020 anaconda-ks.cfg
-rw-r--r--  1 root root  41K Apr  7 14:00 nohup.log         #待清空的日志文件
-rw-r--r--  1 root root  41K Apr  7 14:00 nohup.log.bak    #备份的日志文件

[root@redhat75::~]# cat /dev/null > ./nohup.log     #清空日志文件

[root@redhat75::~]# ll
total 172
-rw-------. 1 root root  2012 May 27  2020 anaconda-ks.cfg
-rw-r--r--  1 root root     0 Apr  7 14:01 nohup.log   #日志文件大小已经为0,已经清空
-rw-r--r--  1 root root 41490 Apr  7 14:00 nohup.log.bak

Fügen Sie hier eine Bildbeschreibung ein

Der zweite Typ: >./nohup.log

[root@redhat75::~]# ll -h
total 216K
-rw-------. 1 root root 2.0K May 27  2020 anaconda-ks.cfg
-rw-r--r--  1 root root  41K Apr  7 14:00 nohup.log         #待清空的日志文件
-rw-r--r--  1 root root  41K Apr  7 14:00 nohup.log.bak    #备份的日志文件

[root@redhat75::~]# >./nohup.log      #清空日志文件

[root@redhat75::~]# ll
total 172
-rw-------. 1 root root  2012 May 27  2020 anaconda-ks.cfg
-rw-r--r--  1 root root     0 Apr  7 14:02 nohup.log   #日志文件大小已经为0,已经清空
-rw-r--r--  1 root root 41490 Apr  7 14:00 nohup.log.bak

Fügen Sie hier eine Bildbeschreibung ein

Der dritte Typ: echo "" >./nohup.log oder echo >./nohup.log

[root@redhat75::~]# ll -h
total 216K
-rw-------. 1 root root 2.0K May 27  2020 anaconda-ks.cfg
-rw-r--r--  1 root root  41K Apr  7 14:09 nohup.log
-rw-r--r--  1 root root  41K Apr  7 14:00 nohup.log.bak
[root@redhat75::~]# echo "" >./nohup.log
[root@redhat75::~]# ll -h
total 176K
-rw-------. 1 root root 2.0K May 27  2020 anaconda-ks.cfg
-rw-r--r--  1 root root    1 Apr  7 14:10 nohup.log
-rw-r--r--  1 root root  41K Apr  7 14:00 nohup.log.bak
[root@redhat75::~]# cat nohup.log

Fügen Sie hier eine Bildbeschreibung ein

Der vierte Typ: :>./nohup.log (häufig in Skripten verwendet)

[root@redhat75::~]# ll
total 216
-rw-------. 1 root root  2012 May 27  2020 anaconda-ks.cfg
-rw-r--r--  1 root root 41490 Apr  7 14:12 nohup.log
-rw-r--r--  1 root root 41490 Apr  7 14:00 nohup.log.bak

[root@redhat75::~]# :>./nohup.log

[root@redhat75::~]# ll -h
total 172K
-rw-------. 1 root root 2.0K May 27  2020 anaconda-ks.cfg
-rw-r--r--  1 root root    0 Apr  7 14:12 nohup.log
-rw-r--r--  1 root root  41K Apr  7 14:00 nohup.log.bak

Fügen Sie hier eine Bildbeschreibung ein

Der fünfte Typ: cp /dev/null ./nohup.log

[root@redhat75::~]# ll -h
total 216K
-rw-------. 1 root root 2.0K May 27  2020 anaconda-ks.cfg
-rw-r--r--  1 root root  41K Apr  7 14:16 nohup.log
-rw-r--r--  1 root root  41K Apr  7 14:00 nohup.log.bak

[root@redhat75::~]# cp /dev/null ./nohup.log
cp: overwrite ‘./nohup.log’? y

[root@redhat75::~]# ll -h
total 172K
-rw-------. 1 root root 2.0K May 27  2020 anaconda-ks.cfg
-rw-r--r--  1 root root    0 Apr  7 14:16 nohup.log
-rw-r--r--  1 root root  41K Apr  7 14:00 nohup.log.bak

Fügen Sie hier eine Bildbeschreibung ein

Sechstens: dd if=/dev/null of=./nohup.log (wenn bedeutet Eingabedatei, oder bedeutet Ausgabedatei)

[root@redhat75::~]# ll -h
total 216K
-rw-------. 1 root root 2.0K May 27  2020 anaconda-ks.cfg
-rw-r--r--  1 root root  41K Apr  7 14:37 nohup.log
-rw-r--r--  1 root root  41K Apr  7 14:00 nohup.log.bak

[root@redhat75::~]# dd if=/dev/null of=./nohup.log
0+0 records in
0+0 records out0 bytes (0 B) copied, 0.000278986 s, 0.0 kB/s

[root@redhat75::~]# ll -h
total 172K
-rw-------. 1 root root 2.0K May 27  2020 anaconda-ks.cfg
-rw-r--r--  1 root root    0 Apr  7 14:37 nohup.log
-rw-r--r--  1 root root  41K Apr  7 14:00 nohup.log.bak

Fügen Sie hier eine Bildbeschreibung ein

Siebter Typ: dd if=/dev/null of=./nohup.log (wenn bedeutet Eingabedatei, oder bedeutet Ausgabedatei)

[root@redhat75::~]# ll -h
total 216K
-rw-------. 1 root root 2.0K May 27  2020 anaconda-ks.cfg
-rw-r--r--  1 root root  41K Apr  7 14:44 nohup.log
-rw-r--r--  1 root root  41K Apr  7 14:00 nohup.log.bak

[root@redhat75::~]# truncate -s 0 ./nohup.log

[root@redhat75::~]# ll -h
total 172K
-rw-------. 1 root root 2.0K May 27  2020 anaconda-ks.cfg
-rw-r--r--  1 root root    0 Apr  7 14:44 nohup.log
-rw-r--r--  1 root root  41K Apr  7 14:00 nohup.log.bak

Fügen Sie hier eine Bildbeschreibung ein

[Persönliches öffentliches Konto]

【非著名运维】、【暴科技】 --》 公众号回复 “资料” 送运维自学资料大礼包哦!Ich werde oben auch einige Betriebs- und Wartungskenntnisse weitergeben. Bitte achten Sie darauf. Vielen Dank an alle.

Acho que você gosta

Origin blog.csdn.net/qq_44895681/article/details/130553848
Recomendado
Clasificación