The system needs to clean up the contents of the log file for a long time, but sometimes the log file is deleted because of carelessness, instead of clearing the log content. How to deal with this situation? In fact, the deleted log file syslog can be recovered, let's take a look at it.
Below Unbutu system as an example of how to undelete syslog:
First, lsof execute the following command as root user, open the query /var /log /messages The process ID (PID) of the file's process.
root@ www.linuxidc.com :/var/log# lsof |
Grep messages
rsyslogd 544 syslog 7w REG 8,1 214641 134422 /var/log/messages
From the above command output you can see that this process opens the /var/log/messages file. The PID is 544, and the file descriptor (FD) number of the file /var/log/messages is 7.
According to the above PID and FD, you can find the corresponding file in /proc:
root@ www.linuxidc.com :/var/log#ls -al /proc/544/fd /7
l-wx------ 1 root root 64 2012-07-14 14:48 7 -》 /var/log/messages
Will file /proc/544 Copy /fd/7 to /var/log/messages
cp /proc/544/fd/7 /var/log/messages
Then restart the syslog service to recover from accidental deletion. The log file, and the new log record can continue to be written to the log file.
Run the service command as the root user. The second parameter of the service command may be syslog or rsyslog.
Specifically, you can use the query to know.
root@ www.linuxidc.com :/proc/544/fd# service --status-all
[ ? ]. . .
[ ? ] rc.local
[ ? ] rsyslog
[ ? ] screen-cleanup
[ ? ]. . .
root@ www.linuxidc.com :/proc/544/fd# service rsyslog restart
rsyslog start/running, process 2673
BTW, really used to clear the log The file command should be:
cat /dev/null"/var/log/messages
The above is the method of Linux accidentally deleting the log file syslog. This article takes Ubuntu as an example, other The system can be used as a reference, and you need to pay attention to the next time you clean up the log files.
The ^M character will appear when you open the windows file in the Linux system, although this does
Because Ubuntu system does not prompt for updates, and many friends who want to update the system do
We all know that yum is a package manager in the CentOS system for downloading and
After Debian mounts the mobile hard disk, some partitions will be recognized, and some partitions wi
How to create symbolic links for Linux systems
Ubuntu system installation screen saver XScreenSaver steps
Linux uses KSysguard to monitor remote hosts
How to deal with the disappearance of ibus input method icon after upgrading Ubuntu 12.04?
RedHat6.5 network card common problems and solutions
How to change the jenkins port number on Ubuntu
What should I do if I get an error when installing LDAP on Linux under Linux?
Analysis of Linux memory exhaustion
Linux how to install and configure MariaDB database
How to directly execute PHP script files in Unix/Linux?
How to modify the time zone of CentOS6 system?
Parameters and function descriptions of the Linux system Xconfigurator command
Retrieve the disk icon such as the lost C drive under Windows 7
Microsoft Win10 Creator Update 15002 Preview Image Download Leaks New Features at
How to solve the problem of IE8 home page modification? Mining Windows 7 potential
What if CentOS uses MPlayer without sound?
How to achieve the notebook microphone and speaker output at the same time
The solution that can not be saved after the computer txt text file is modified
Win10 desktop, mobile version of the official comparison: look at where win10 is good
Win10 boot press F8 can not enter the safe mode how to do?
Three ways to uninstall Windows XP SP3
Q & A, Microsoft Surface RT must know a few details of the use of