How to do not stop the service under Linux, empty the Nohup.out file

Source: Internet
Author: User
Tags jboss server

Tips: Recently found a lot of people in Baidu this problem, as easy as I am also a beginner, casually search from the internet, turned around, but in order to avoid the homogeneity of search results, for everyone to provide more informative reference, I will nohup.out related knowledge collation summarized as follows:

The origin and function of 1.nohup.out

Purpose: Linux command usage, do not hang up to run the command.

Syntax: Nohup Command [Arg ...] [&] Description: The nohup command runs commands specified by the command parameter and any related ARG parameters, ignoring all hang-up (SIGHUP) signals. Use the Nohup command to run a program in the background after logging off. To run the Nohup command in the background, add & (the symbol representing "and") to the end of the command. Example: Nohup./startweblogic.sh & means that even if you exit the SSH interface, the command is still in the background, and the print process log to nohup.out, of course, you can also turn nohup.out output to other files, advanced applications please refer to the extended reading.

How and how to view 2.nohup.out

The actual use of the process, often people in order to worry (ah, yes, is lazy), often did not give nohup.out to redirect output, also did not split the file by date, will cause this file is particularly huge, to 2G or 3G, this use want to view files, search error content is more painful. There are generally two ways of

1.linux Native View: Use the tail command to view the latest logs, or scroll through the monitoring log for printing.

For example Command tail-1000 nohup.out (view last 1000 lines of log text) Tail-f nohup.out (monitoring log printing)

2.ftp Download to Windown host view: The general small log file is not a problem, but over the G, the general text document view will appear powerless. It is recommended to open with UltraEdit.

3.nohup.out Maintenance Management Method (empty nohup.out)

As mentioned above the appearance of super-large files is simply annoying things, and nohup.out will have been growing, if your server hard disk, it is easy to put the application also hung (hard disk space, nothing to play), but can not blindly directly deleted. Because the direct deletion, may cause the application cannot print the subsequent error log, this problem is common in the WebLogic server, the JBoss server and so on these large-scale middleware, this in the production environment to pay particular attention.

So there is a way to empty the Nohup.out file without stopping the service directly.

Two commands that can empty the nohup.out without stopping the Web service.

The first type: Cp/dev/null nohup.out

Second type: cat/dev/null > Nohup.out

I have used both, do not worry about the online performance issues, usually 2/3 g of files are 1-2 seconds to complete

4. Extended Reading

1.nohup Redirect, once and for all solve nohup.out file too big problem
The
following is the definition of the log print level, except that the alarm information above level 2 is logged to the log file, the remainder is not recorded directly
only output error messages to the log file
nohup./program >/dev/null 2>log &
What information is not
nohup ./program >/dev/null 2>&1 &
3 redirect in 2.Linux
0: Indicates standard input
1: Standard output, in general use, the default is the standard output
2: standard error message output
Can be used to specify the standard input or output that needs to be redirected. For example, output a program's error message to the log file:./program 2>log. The standard output is still on the screen, but the error message is output to the log file. In addition, redirects can be implemented between 0,1,2. 2>&1: redirect error messages to standard output. 3. About/dev/null file Linux also has a special file/dev/null, it is like a bottomless pit, all the information redirected to it will disappear into a trace. This is useful when we do not need to echo all of the program's information, so we can redirect the output to/dev/null.

How to do not stop the service under Linux, empty the Nohup.out file

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.