As a Java development engineer, Linux should start to learn everything
–> Linux commands
The grep command
Grep the Global Regular Expression Print (grep) command is used to search for qualified strings in a file. By default, the qualified line is displayed.
Common parameters:
-c: number of lines (count) -a < number of lines > : displays the content after the target line (after) -b < number of lines > : displays the content before and after the target line (before) -c < number of lines > : displays the content before and after the target line (context) -d: displays the content before and after the target line (context) -e< rule > : Regular expression search (regexp) -i: ignore case (ignore case) -n: Line number for directoriesCopy the code
- Find the specified field in the file:
Grep 'Found string' file nameCopy the code
- Find the specified field in the file and count The Times:
Grep -c 'search string filename grep' search string filename | wc -lCopy the code
B: before the pipeline operators’ | ‘can be a command from the standard output information correctly, as a standard input is passed to the next command; Wc -l: indicates the wc command. The -l parameter displays the number of lines.
- Display the content before and after the target line:
Grep -a10-b5 'Search string' file nameCopy the code
- The system alarm shows the time, but the log file is too large to be viewed directly by CAT: (*.log can be found in all files with the suffix log)
grep -n '2019-10-24 00:01:11' *.log
Copy the code
The find command
Find command: finds files in the specified directory.
- The find command defaults to finding subdirectories and files in the current directory:
find *.log
Copy the code
The top and ps commands
Ps command (process status) : displays the status of the current process.
- Display all processes:
ps -A / ps -e
Copy the code
- Display all processes in full format:
ps -ef
Copy the code
- Specify a process name to find all processes that contain Java:
ps -ef | grep 'java'
Copy the code
The top command: Can monitor progress in real time and display a summary of the system.
The difference between the ps command and the top command:
- Ps process information is the process information immediately after the command is executed, while TOP can be continuously monitored.
- Ps focuses on what needs to be viewed;
- Top focuses on CPU and memory usage.
The sort command
Sort command: enables you to sort the contents of a file by line.
Common parameters:
-b: ignores the space before the line when sorting. -f: ignores the case difference in sorting. -n: Sort by value size. -r: Sort in reverse order. -u: output the result after deduplication. -o: outputs the specified file as the sorting result.Copy the code
- Forward sort/reverse sort:
sort -n file.log
sort -nr file.log
Copy the code
Tail and head commands
- Look at the first/last few lines of the file:
head -n 10 file.log
tail -n 10 file.log
Copy the code
- View the appended content at the end of the file in real time:
tial -f file.log
Copy the code
ls&cd&mkdir&rm
Basic command set:
Ls -lhrt Time change by easy-to-read mode Display file details in reverse order CD - Go to the last working path mkdir file Create a folder named file in the current directory mkdir -p/TMP /test/file Create the /test/file directory in TMP (-p can create multiple directories at a time) rm -rf file Delete all files in file directory and subdirectories mv test.log test. TXT Change the file name to test. TXT mv Log/TMP Move the test.log file to/TMP cp -r/TMP /file/TMP /file Copy the files in/TMP /file to a new directory/TMP /file cat -n test.log Display the entire file information (-n Displays the line number.) cat > test.log Creates a test.log fileCopy the code