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

How to bind domain name to nginx service

Configure multiple servers in nginx.conf: When pr...

Vue uses mixins to optimize components

Table of contents Mixins implementation Hook func...

Tutorial on Migrating Projects from MYSQL to MARIADB

Prepare the database (MySQL). If you already have...

MySQL learning database backup detailed explanation

Table of contents 1.DB,DBMS,SQL 2. Characteristic...

Sample code for implementing menu permission control in Vue

When people are working on a backend management s...

How to pull the docker image to view the version

To view the version and tag of the image, you nee...

Mysql 5.7.19 free installation version encountered pitfalls (collection)

1. Download the 64-bit zip file from the official...

Detailed explanation of the use of Refs in React's three major attributes

Table of contents Class Component Functional Comp...

Script to quickly list all host names (computer names) in the LAN under Linux

Recently, I have a need to list all host names in...

Vue el-date-picker dynamic limit time range case detailed explanation

There are two situations 1. Start time and end ti...

HTML table markup tutorial (14): table header

<br />In HTML language, you can automaticall...

Summary of the use of CSS scope (style splitting)

1. Use of CSS scope (style division) In Vue, make...

Let's talk about the storage engine in MySQL

Basics In a relational database, each data table ...

Add a floating prompt for the header icon in the ElementUI table

This article mainly introduces how to add floatin...