Linux Common Command Collection

Source: Internet
Author: User
Tags syslog egrep

Use of the Mtime parameter of the 1.find command
For the use of find-mtime this parameter:
-mtime N to find the file according to the file change time, n is an integer.
n means that the file change time distance is n days, and-n means that the file change time distance is less than n days, and +n indicates that the file changed time distance before n days.
For example:
-mtime 0 represents files that are currently 0 days away from the file modification time, which is less than 1 days (24 hours) away from the current time.
-mtime 1 represents a file modified from a file that is currently 1 days long, that is, 1 days (24 hours-48 hours) from the current time.
-mtime+1 indicates file modification time is greater than 1 days, that is, 2 days (48 hours) away from the current time file
-mtime-1 indicates file modification time is less than 1 days files, that is, 1 days (24 hours) from the current time
-mtime+1 represents a file that has been modified for more than 1 days, that is, a file that is 48 hours away from the current time, not 24 hours
Because the N value can only be an integer, that is, the nearest integer greater than 1 is 2, all-mtime+1 is not greater than the current time of 1 days (24 hours), but is greater than the current time of 2 days (48 hours).

2. Deleting folders and files
Delete Folder Rm-rf/var/tmp where-R is recursive delete,-F is directly deleted, not prompted
deleting files rm-f/var/log/access.log


3.cat command Explanation
There are three major features of cat:
1. Display the entire file at once. $ cat FileName
2. Create a file from the keyboard. $ cat > FileName
Only new files can be created and existing files cannot be edited.

3. Merge several files into one file: $cat file1 file2 > file
Parameters:
-N or--number the number of rows for all outputs starting from 1
-B or--number-nonblank and-n similar, except for blank lines not numbered
-S or--squeeze-blank when you encounter a blank line that has more than two consecutive lines, replace the blank line with one line
-V or--show-nonprinting
Cases:
Add a line number to the Textfile1 file and enter the Textfile2 file.
Cat-n textfile1 > Textfile2

Append the contents of the Textfile1 and Textfile2 files to the textfile3 after adding the line number (blank line not added).
Cat-b textfile1 textfile2 >> textfile3

Throw the Test.txt file into the trash, and assign a null value Test.txt
Cat/dev/null >/etc/test.txt
Cat creates the file and appends the content, and after creating the file, to end with EOF or stop, this command can also be used to append content
[email protected] hhr]# cat >> hh.txt << EOF
> SSS
> DDD
> FFF
> EOF


4.rpm Introduction
Under the Linux operating system, almost all of the software is installed, uninstalled and managed through RPM. RPM is all called Redhat package Manager,
is a software that is proposed by Redhat company to manage Linux packages. Linux installation, in addition to a few core modules, almost all of the remaining modules are
Complete the installation via RPM. RPM has five modes of operation: Install, uninstall, upgrade, query and verify.
RPM Installation Operation:
Examples are as follows:
Rpm-i example.rpm installation example.rpm package;
Rpm-iv example.rpm installs the example.rpm package and displays the file information that is being installed during the installation process;
RPM-IVH example.rpm installs the example.rpm package and displays the file information and installation progress during the installation process;
RPM Query Operation:
A query all installed packages The following two additional commands are used to query the installation package information;
I display the information of the installation package;
L Display the directories in which all files in the installation package are installed;
s displays the status of all files in the installation version and which directories are installed; The following two additional commands are used to specify whether the installation package or the installed file needs to be queried;
P The information of the installation package is queried;
f The query is a file information that has been installed;
Examples are as follows:
Rpm-qa | grep tomcat4 to see if TOMCAT4 is installed;
RPM-QIP example.rpm View the information of the example.rpm installation package;
RPM-QIF/BIN/DF View information about the installation package where the/bin/df file is located;
RPM-QLF/BIN/DF to see which directory each file in the installation package of the/BIN/DF file is installed in;
RPM Unload Operation:
RPM-E installation packages that need to be uninstalled
RPM Upgrade operation
Command:
Rpm-u packages that need to be upgraded
Examples are as follows:
RPM-UVH example.rpm Upgrade EXAMPLE.RPM Package
RPM Verification Action
Command:
RPM-V packages that need to be validated
Examples are as follows:
Rpm-vf/etc/tomcat4/tomcat4.conf
The output information is similar to the following:
S.5 .... T c/etc/tomcat4/tomcat4.conf
Where S means that the file size has been modified and T indicates that the file date has been modified. For more information, please refer to the RPM Help file: Man rpm
Other additional commands for RPM
--force mandatory operation such as forced installation and removal;
--requires shows the dependency of the package;
--nodeps ignore dependencies and continue operation;


5. grep command
2. Use
The grep command in a Linux system is a powerful text search tool that uses regular expressions to search for text and print matching lines. grep full name is global Regular Expression Print,
Represents a global regular expression version that uses permissions for all users.
2. Format
grep [Options]
3. Main parameters
[Options] Main parameters:
-C: Outputs only the count of matching rows.
-I: Case insensitive (only for single-character).
-H: The file name is not displayed when querying multiple files.
-L: Only file names that contain matching characters are output when querying multiple files.
-N: Displays matching lines and line numbers.
-S: does not display error messages that do not exist or have no matching text.
-V: Displays all lines that do not contain matching text.
Pattern Regular Expression Main parameters:
\: Ignores the original meaning of special characters in regular expressions.
^: matches the start line of the regular expression.
$: Matches the end line of the regular expression.
\<: Starts from the line that matches the regular expression.
\>: End of line to match regular expression.
[]: A single character, such as [a], a meets the requirements.
[-]: range, such as [A-z], i.e. A, B, C to Z all meet the requirements.
。 : all the individual characters.
*: There are characters, the length can be 0.
4.grep command uses a simple instance
$ grep ' test ' d*
Displays all rows that contain test in a file that begins with D.
$ grep ' test ' AA bb cc
Displays the line that matches test in the aa,bb,cc file.
$ grep ' [a-z]\{5\} ' AA
Displays all rows that contain a string of at least 5 consecutive lowercase characters for each string.
$ grep ' w\ (es\) T.*\1′aa
If West is matched, es is stored in memory, labeled 1, and then searched for any character (. *) followed by another ES (\1), which is found to display the row.
If you use Egrep or GREP-E, you do not have "\" number to escape, directly written as ' W (es) t.*\1′ on it.


6.ps Command
The PS command in Linux is the abbreviation for process status. The PS command is used to list those processes that are currently running on the system. The PS command lists the snapshots of those processes that are currently executing the PS command.
Those processes at that moment, if you want to display process information dynamically, you can use the top command. PS provides us with a one-time view of the process, it provides the view results are not dynamic continuous;
If you want to monitor process time, you should use the top tool.
There are 5 states of processes on Linux:
1. Running (running or waiting in the running queue)
2. Interrupt (dormant, blocked, waiting for a condition to form or receive a signal)
3. Non-interruptible (receive signal does not wake up and not run, process must wait until interrupt occurs)
4. Zombie (The process has been terminated, but the process descriptor exists until the parent process calls WAIT4 () after the system call is released)
5. Stop (process received Sigstop, SIGSTP, Sigtin, Sigtou signal after stop running run)
PS Tool identifies 5 status codes for the process:
D non-interruptible uninterruptible sleep (usually IO)
R run runnable (on run queue)
S Interrupt Sleeping
T stop traced or stopped
Z Zombie a defunct ("zombie") process
1. Command format:
ps[parameters]
2. Command function:
Used to display the status of the current process
3. Command parameters:
A Show All Processes
-a displays all programs under the same terminal
-A Show All processes
C Displays the real name of the process
-N Reverse Selection
-e equals "-A"
e Display Environment variables
F show the relationship between programs
-H Display tree structure
R shows the process of the current terminal
T displays all programs for the current terminal
U specify all processes for the user
-au Show more detailed information
-aux Show all itineraries that contain other users
-c< commands > lists the status of the specified command
--lines< lines > number of rows displayed per page
--width< characters > number of characters displayed per page
--HELP Display Help information
--version Display version display
Usage examples:
Example 1: Show all process information
Ps-a
Example 2: Displaying specified user information
Ps-u Root
Example 3: Show all process information, along with command line
Ps-ef
Example 4:ps and grep common use combinations to find specific processes
Ps-ef|grep SSH
Example 5: Make a list of the PID and related information that is currently your own log in
Ps-l
[Email protected] test6]# ps-l
F S UID PID PPID C PRI NI ADDR SZ Wchan TTY time CMD
4 S 0 17398 17394 0 0-16543 wait pts/0 00:00:00 bash
4 R 0 17469 17398 0 0-15877-pts/0 00:00:00 PS
The meaning of the relevant information:
F represents the flag of this program, 4 represents the user as Super user
S represents the status of this program (STAT), and the significance of each stat will be described in the text
The UID program is owned by the UID.
PID is the ID of this program!
PPID is the ID of its parent program
Percentage of resources used by the C CPU
PRI this is the abbreviation for priority (precedence order), which is described in detail later
NI This is a nice value
ADDR This is the kernel function, which points out the part of the program that is in memory. If it's a running program, it's usually "-"
SZ-Used memory size
Wchan whether the program is currently in operation, if it is-indicates that it is operating
TTY Login Terminal Location
Time used to consume the CPU.
What are the commands that CMD has issued?
In the case of presets, PS only lists the PID associated with the current bash shell, so when I use ps-l, there are only three PID.
Example 6: List all currently in-memory programs
[[Email protected] test6]# PS aux
USER PID%cpu%MEM VSZ RSS TTY STAT START time COMMAND
Root 1 0.0 0.0 10368 676? Ss Nov02 0:00 init [3]
Root 2 0.0 0.0 0 0? s< Nov02 0:01 [migration/0]
Root 3 0.0 0.0 0 0? SN Nov02 0:00 [ksoftirqd/0]
Root 4 0.0 0.0 0 0? s< Nov02 0:01 [MIGRATION/1]
Root 5 0.0 0.0 0 0? SN Nov02 0:00 [KSOFTIRQD/1]
Root 6 0.0 0.0 0 0? s< Nov02 29:57 [events/0]

Description
User: The process belongs to the user account
PID: The number of the process
%cpu: Percentage of CPU resources that the process uses
%MEM: Percentage of physical memory occupied by this process
VSZ: The amount of virtual memory that the process uses (Kbytes)
RSS: The amount of fixed memory that the process occupies (Kbytes)
TTY: The process is operating on that terminal, if it is not related to the terminal, then display?, in addition, TTY1-TTY6 is the machine above the login program, if it is pts/0 and so on, it is represented by the network connected to the host computer program.
STAT: The current state of the program, the main state has
R: The program is currently in operation or can be operated
S: The program is currently sleeping (can be said to be idle) but can be awakened by certain signals (signal).
T: The program is currently detecting or stopping
Z: The program should have been terminated, but the parent program could not properly terminate him, causing the state of the zombie (Xinjiang Corpse) program
Start: The time that the process was triggered to start
Time: The process actually uses the CPU to run
Command: The actual instruction of the program
Example 7: Listing programs showing similar program trees
Ps-axjf
[Email protected] test6]# PS-AXJF
Warning:bad syntax, perhaps a bogus '-'? See/usr/share/doc/procps-3.2.7/faq
PPID PID pgid SID TTY tpgid STAT UID time COMMAND
0 1 1 1? -1 Ss 0 0:00 init [3]
1 2 1 1? -1 s< 0 0:01 [migration/0]
1 3 1 1? -1 SN 0 0:00 [ksoftirqd/0]
Example 8: Find PID numbers related to cron and syslog services
[[Email protected] test6]# PS aux | Egrep ' (cron|syslog) '
Root 2682 0.0 0.0 83384 2000? Sl Nov02 0:00/sbin/rsyslogd-i/var/run/syslogd.pid-c 5
Root 2735 0.0 0.0 74812 1140? Ss Nov02 0:00 Crond
Root 17475 0.0 0.0 61180 832 pts/0 s+ 16:27 0:00 egrep (cron|syslog)
Other examples:
1. can be used | Pipe and more connect up paging view
Command:
Ps-aux |more
2. Display all the processes and output to the Ps001.txt file
Command:
Ps-aux > Ps001.txt
3. Output the specified field
Command:
Ps-o Pid,ppid,pgrp,session,tpgid,comm
Output:
[Email protected] test6]# Ps-o Pid,ppid,pgrp,session,tpgid,comm
PID PPID pgrp sess tpgid COMMAND
17398 17394 17398 17398 17478 Bash
17478 17398 17478 17398 17478 PS

7. Df-h
[Email protected] hhr]# df-h
Filesystem Size used Avail use% mounted on
/dev/sda2 3.9G 3.9G 0 100%/
Tmpfs 1004M 0 1004M 0%/dev/shm
/DEV/SDA1 49M 38M 8.3M 82%/boot
/dev/sda5 13G 167M 13G 2%/Home

Linux Common Command Collection

Related Article

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.