How to recover accidentally deleted messages files in Linux

How to recover accidentally deleted messages files in Linux

If there are files that are being used by a process and are deleted by mistake, they can be recovered. If no process is using it, the accidentally deleted files cannot be recovered.

If the /var/log/messages file is deleted by mistake:

1. Query the process that is using the file.

[root@www]# lsof |grep message
rsyslogd 1717 root 1w REG 8,2 243321 654968 /var/log/messages

2. According to the query results, the process with PID 1717 is using the file. Enter the directory /proc/1717/fd under the process /proc:

[root@www fd]#ll
total 0
lrwx------ 1 root root 64 Jan 10 14:34 0 -> socket:[11015]
l-wx------ 1 root root 64 Jan 10 14:34 1 -> /var/log/messages
l-wx------ 1 root root 64 Jan 10 14:34 2 -> /var/log/secure
lr-x------ 1 root root 64 Jan 10 14:34 3 -> /proc/kmsg
l-wx------ 1 root root 64 Jan 10 14:34 4 -> /var/log/maillog
l-wx------ 1 root root 64 Jan 10 14:34 5 -> /var/log/cron

3. Query file 1, which corresponds to the messages log. Use cat 1 > /var/log/messages to copy it back, and then restart the syslogd service.

Summarize

The above is the full content of this article. I hope that the content of this article will have certain reference learning value for your study or work. Thank you for your support of 123WORDPRESS.COM. If you want to learn more about this, please check out the following links

You may also be interested in:
  • Linux uses join -a1 to merge two files
  • How to deal with the prompt "Operation not permitted" when deleting files in Linux
  • Linux shell command counts the value of a column after deduplication
  • Tips for viewing History records and adding timestamps in Linux
  • Several ways to run Python programs in the Linux background
  • Creating and executing Linux shell scripts
  • Python uses paramiko to operate Linux
  • Android's implementation method of executing shell scripts in the Linux terminal to directly print the log of the currently running app
  • Use of Zabbix Api in Linux shell environment
  • How to count the number of specific characters in a file in Linux

<<:  Detailed explanation of data transmission between React parent components and child components

>>:  Sharing of SQL optimization experience when offset is too large during MySQL paging

Recommend

Brief introduction and usage of Table and div

Web front end 1 Student ID Name gender age 01 Zha...

Summary of the Differences between find() and filter() Methods in JavaScript

Table of contents Preface JavaScript find() Metho...

Explore how an LED can get you started with the Linux kernel

Table of contents Preface LED Trigger Start explo...

Some summary of html to pdf conversion cases (multiple pictures recommended)

Due to work requirements, I recently spent some t...

Detailed installation process of MySQL5.6.40 under CentOS7 64

MySQL5.6.40 installation process under CentOS7 64...

Summary of MySQL database and table sharding

During project development, our database data is ...

Advertising skills in the Baidu Union environment (graphic tutorial)

Recently, students from the User Experience Team o...

Realize map aggregation and scattering effects based on vue+openlayer

Table of contents Preface: Result: 1. Polymerizat...

Docker container from entry to obsession (recommended)

1. What is Docker? Everyone knows about virtual m...

Recommend some useful learning materials for newbies in web design

Many people also asked me what books I read when ...

CocosCreator Skeleton Animation Dragon Bones

CocosCreator version 2.3.4 Dragon bone animation ...

JavaScript flow control (loop)

Table of contents 1. for loop 2. Double for loop ...