Common commands for the Linux command line

Source: Internet
Author: User
Tags control characters diff nslookup

1. Download command wget
Wget-c Http://the.url.of/incomplete/file
C support for the continuation of the breakpoint

-S,--server-response print server response.
--hlep View additional Help


2. Load and unload Query Package command
Rpm-qa | grep tomcat4 to see if TOMCAT4 is installed;
Rpm-i example.rpm installation example.rpm package;

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;
E installation packages that need to be uninstalled

3.source command

The source command, also known as a Point command, is a dot symbol (.). The source command is typically used to re-execute the initialization file you just modified to take effect immediately without having to log off and log back on.
Method 1: Make the/etc/profile file effective immediately after modification, you can use the following command:
# . /etc/profile Note:. and/etc/profile have spaces
Method 2:
To make the/etc/profile file effective immediately after modification, you can use the following command:
# Source/etc/profile


4. Unzip the command tar

Unzip to the specified folder TAR-XVF file.tar-c./dir2/dir1


5.patch and diff


Diff "Options" source file (folder) destination file (folder), is to give the source file (clip) to a patch, so that it becomes the destination file (folder),
-R is a recursive option that sets this option, and diff will compare all of the corresponding files in the two different versions of the source code directory, including the subdirectory files.
The-n option ensures that the patch file will correctly handle the case where the file has been created or deleted.
The-u option creates a patch file in a uniform format that is more compact than the default format.

Patch is the use of diff-made patches to achieve source file (clip) and destination file (clip) conversion.
-P0 option to find the destination file (clip) from the current directory
-P1 option to ignore the first level of the directory, starting from the current directory to find.
The-e option indicates that if an empty file is found, delete it
The-r option indicates that the "new" file and the "old" file in the patch file are now being switched over.

Single File
Diff–un from-file To-file >to-file.patch
Patch–p0 < To-file.patch
Patch–re–p0 < To-file.patch
Multiple files
Diff–unr FROM-DOCU TO-DOCU >to-docu.patch
Patch–p1 < To-docu.patch
PATCH–R–P1 <to-docu.patch

6.lsof command

The ls-l/proc/self/fd,/proc/self itself is a symbolic link to the current running process ID.

If we log in through the IPMI serial port, this should be/dev/ttysx, and if it is local login that should be/dev/ttyx, if it is single-user login that would be/dev/console.

/DEV/PTS/X is a virtual terminal

/dev/ttysx is a serial control terminal

/dev/ttyx is the console

/dev/console is a single-user console

Echo $$
Lsof-p 3174 Viewing the files that the process opens,
COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME
Bash 3174 root cwd DIR 8,1 4096 32577/root
Bash 3174 root rtd DIR 8,1 4096 2/
Bash 3174 root txt REG 8,1 797784 309511/bin/bash
Bash 3174 root mem REG 8,1 47520 147727/lib/libnss_files-2.7.so
......
Bash 3174 root 0u CHR 136,1 3/dev/pts/1
Bash 3174 root 1u CHR 136,1 3/dev/pts/1
Bash 3174 root 2u CHR 136,1 3/dev/pts/1
Bash 3174 root 255u CHR 136,1 3/dev/pts/

Ls-l/proc/3174/fd to view open files in/proc
lrwx------1 root root 2010-10-10 13:13 0,/DEV/PTS/1
lrwx------1 root root 2010-10-10 13:13 1,/DEV/PTS/1
lrwx------1 root root 2010-10-10 13:13 2,/DEV/PTS/1
lrwx------1 root root 2010-10-10 13:15 255-/DEV/PTS/1
Lsof not only shows the file descriptor, the last four files in the lsof output are file descriptors for the open file of the process, 0
The u represents a file descriptor of 0, while 255u represents a file descriptor of 255,u that is readable and writable.

In addition to these four file descriptors, there are several types of cwd,rtd,txt,mem in the FD column, which have the following meanings:
CWD represents the current directory, this is/root
The RTD represents the root directory, here is/
TXT represents the execution of the program, here is/bin/bash
MEM represents a file mapped to memory, this is a dynamic link library such as/lib/libc-2.7.so

The type column represents the file/directory types, dir represents the directory, Reg represents the ordinary file, and CHR represents the character device.

In fact, we can confirm the current system's pseudo-terminal through W, and then through Lsof|grep ' pts/0 ' to view the PID using the pseudo-terminal, and finally use the Lsof-p PID to see what the user is doing.

If you have a specific user name, you can use lsof-u username to view the files currently loaded by that user.

-I I select by ipv[46] Address: [46][proto][@host |addr][:svc_list|port_list]

7.strace command
Strace is commonly used to track system calls and received signals when a process executes.
In the Linux world, processes cannot directly access hardware devices, and when a process requires access to a hardware device (such as reading a disk file, receiving network data, and so on), it must be switched from user mode to kernel mode and access to the hardware device through system calls.
Strace can trace the system calls generated by a process, including parameters, return values, and time spent executing.

-F tracks the child processes that are generated by the fork call.
-O filename
Writes the output of the strace to the file filename
-P PID
Track the specified process PID

Debug the program with Strace
Resolve Library Dependency Issues

ls-d. * Show only hidden files (or L.)
-d means to display the folder like a directory, without displaying the files under the folder;

8.cut command
Byte (bytes), with option-b,cut-b 3-5,8
Character (characters), with options-c,cut-c 3-5,8
fields, with option-F, cut-d:-F 1,3-5

9. TR command
TR is used to convert characters from standard input through substitution or deletion operations. TR is primarily used to remove control characters from a file or to convert characters. To convert two strings when using tr: string 1 is used for queries, and string 2 is used to handle a variety of conversions. TR just
, the character in string 1 is mapped to the character in String 2, and then the conversion operation begins.
The TR command format with the most common options is:
Tr-c-d-s ["String1_to_translate_from"] ["string2_to_translate_to"] < Input-file
Over here:
-C replaces this character set with a complement to the character set in string 1, which requires the character set to be ASCII.
-d deletes all input characters in string 1.
-S Delete all occurrences of a sequence of characters, leaving only the first one; the string compression is about to recur to a string.
Input-file is the conversion file name. Although you can enter in other formats, this format is most commonly used.

Generate Random Password:
Cat/dev/urandom | TR-DC a-za-z0-9_ | Head-c 16

Netstat command

The netstat is used to display statistics related to IP, TCP, UDP, and ICMP protocols, and is typically used to verify the network connectivity of each port on the machine.

-A (All) displays all options and does not show listen related by default
-T (TCP) displays only TCP-related options
-U (UDP) displays only UDP-related options
-N refuses to display aliases, showing all numbers converted to numbers.
-l list only service status in Listen (listening)

-P Displays the program name that establishes the associated link
-R display routing information, routing table
-e display extended information, such as UID, etc.
-S statistics according to each protocol
-C executes the netstat command every other fixed time.

-I display list of network interfaces

Hint: The status of listen and listening can only be seen with-a or-l

Netstat-p can be used with other switches, you can add "Pid/process name" to the netstat output, so debugging can easily find a specific port to run the program.


11. Download common commands for exception diagnostics
1. Access ip138 to get the user IP
2. Ping www.example.com
3, nslookup www.example.com
4, nslookup www.example.com 8.8.8.8
5, Traceroute www.example.com
6, Wget-s Http://www.example.com/setup.exe

12. Network Grab Kit: tcpdump
Usage:tcpdump [-AADDEFIKLLNNOPQRSTUUVXX] [-B size] [-c Count]
[-C File_size] [-E Algo:secret] [-F file] [-G seconds]
[-I. Interface] [-M secret] [-R File]
[-S Snaplen] [-T type] [-W file] [-W FileCount]
[-y Datalinktype] [-Z Command] [-Z User]
[Expression]


1. tcpdump-d get the list of network adapters
2. Tcpdump-x-S 0-i eth1 src host 192.168.25.78 and TCP port 80
-X Displays the contents of the packet
-S 0 indicates that the length is automatically set to display all data
3.tcpdump tcp-i eth1-t-S 0-c and DST Port! and src net 192.168.1.0/24-w./target.cap
(1) tcp:ip icmp arp rarp and TCP, UDP, ICMP these options are put to the position of the first parameter, to filter the type of the datagram
(2)-I eth1: Only grab packets that pass through the interface eth1
(3)-T: Time stamp not shown
(4)-S 0: The default fetch length is 68 bytes when fetching packets. Plus-S 0 can catch complete packets
(5)-C 100: Fetch only 100 packets
(6) DST Port! 22: Packets that do not crawl the destination port are 22
(7) SRC net 192.168.1.0/24: The source network address of the packet is 192.168.1.0/24
(8)-W./target.cap: Save as a cap file for easy analysis

Common commands for the Linux command line

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.