Linux elective course: UNIX common command

xiaoxiao2021-03-06  42

Sender: Albin (Aile Bin), News District: Linux

Title: Linux Elective Class: UNIX Common Order

Sending station: Bihai Qingtian (Wed Apr 21 23:14:19 1999), transfer

Copyright Notice:

This article is the Linux elective course of Dalian University of Technology. You are welcome to reprint, but it is forbidden to use this material.

Any commercial or profitable event. Please keep this copyright statement when you reprint.

Author: He Binwu, hbwork @ dlut.edu.cn, Network Center of Dalian University of Technology, April 1999.

URL: ftp://ftp.dlut.edu.cn/pub/people/albin/

-------------------------------------------------- ----------------------------

Fourth, UNIX system common command

UNIX system commonly used command format:

Command [Flags] [argument1] [argument2] ...

Where Flags is started, multiple FLAGs can be used to connect, such as LS -L -A is the same as LS -LA.

Depending on the command, the parameters are divided into optional or must; all commands are entered from the standard input, output

The result is displayed in the standard output, and the error message is displayed in the standard error output device. Redirect function

These devices are redirected.

The command returns an 0 value after normal execution, if the command error can be complete, then return one

Non-zero value (available variables available in Shell). This return value can be used as control logic in Shell Script

a part of.

Note: Different UNIX version of FLAGS may vary.

1. Command related to the user

1.1 Login

(This command function is different from the Solaris / BSD under Linux Redhat, and the execution login exits the current task).

Login:

PASSWORD:

Related documents:

Set the necessary paths, terminal types, other variables, or special programs when the shell runtime is set in the following files.

$ HOME / .profile (Bourne Shell, SH, BASH)

$ HOME / .CSHRC (CSH, TCSH)

$ HOME / .TCSHRC (TCSH)

/ etc / passwd file lists each user's shell

/etc/csh.cshrc

/etc/csh.login

/ etc / profile (bourne shell, bash)

/ ETC / Login (Bourne Shell, Bash)

CSH: /etc/csh.cshrc and $ home / .cshrc will read each time,

And /etc/csh.login and $ home / .login only registered shell

After modify the corresponding file, use the source .cshrc to enable relevant modifications, if the PATH is modified

You also need to use a REHASH to refresh the executable Hash table.

TCSH: $ homen / .tcshrc, no files read .cshrc

SH: / etc / profile and $ home / .profile registration shell

Bash: / etc / profile and $ home / .bash_profile registration shell read

.bashrc interactive non-registration shell is read.

Handmade related files in Sh / Bash:

. / etc / profile

Related file execution order

SH: / etc / profile -> $ home / .profile

CSH / TCSH: /etc/csh.cshrc -> /etc/csh.login -> $ home / .cshrc

-> $ home / .login

Variable setting:

SH / BASH: TERM = VT100; EXPORT TERM

Al: Export Term = VT100 (Bash) CSH: STENV TERM VT100

Common variables:

(1) Backspace $ homen / .profile $ homen / .cshrc

Stty Erase ^ h

(2) UMASK new file or directory protection properties

(3) TERM

(4) Do not join the PATH.

1.2. Rlogin

Similar to Telnet, connect to the remote host.

Rlogin Remotehost [-l loginname]

OR:

RSH [-l loginname] Remotehost [Command]

Related documents:

Remote host /etc/hosts.equiv and $ home / .rhosts

Related network configuration files:

The R system service in the /etc/inetd.conf file.redhat is Shell, Login, Exec, Correspondence

The network daemon (daemon) is in .rshd, in .rlogind, in.rexecd.

Recommendation: Off from the security perspective, turn off the R series service.

1.3. Telnet

Telnet Remotehost [Port]

Related documents:

Telnet service in the /etc/inetd.conf file.

/etc/issue.net

Tips: strings /usr/sbin/in.telnetd | Egrep Issue

1.4. Passwd changed the password

1.5 EXIT exits the current shell

2. Look for commands or files

Related shell variables:

CSH / TCSH: $ PATH

.cshrc set path = (/ usr / bin / usr / local / bin $ path)

SH / BASH: $ PATH

.profile.bash_profile

Path = / usr / local / bin: $ PATH; Export Path

2.1 Which

SYNTAX: Which Command

Which is the Bash / TCSH command

[hbwork @ Toshiba] $ Which Which

Which: Shell Built-in Command.

2.2 WHERE (TCSH)

Syntax: Where command

2.3 Locate (Linux)

SYNTAX: LOCATE FILENAME

Related Commands: Updatedb Change Locate File Name Database

3. View the usage of the command

MAN

Related documents:

/etc/man.config

4. Administrator common command

4.1 INSTALL

Used to install a new command or Daemon, etc., in general, but many software installed

Use install to copy the target file to the appropriate directory and set the correct properties.

Name

INSTALL - COPY FILES AND SET THEIR Attributes

Synopsis

Install [Options] [-s] [--strip] Source Dest

Install [options] [-s] [--Strip] Source ... Directory

Install [Options] [-D, - Directory] Directory ...

Options:

[-C] [-g group] [-m mode] [-o owner] [--Group = group]

[--Mode = mode] [- Wener = Owner] [--help] [--Version]

4.2 Shutdown

Different UNIX parameters are different, and it is often shut down under Linux:

SHUTDOWN-H now

Shutdown -r now (equivalent to Reboot)

4.3 Halt

Poweroff

Shutdown, under multi-user mode (Runlevel 3) is not recommended,

4.4 Ulimit

This command can be used in Korn Shell and Bourne Shell, in the CSH series, the corresponding command is limit. Used to limit system resources available to each process, usually divide two restrictions:

The resource defined by the Hard Limits system, only root can change

Soft restrictions on the restrictions used by the new process, can increase to the system's HARD LIMIT.

Flags:

-a lists soft restrictions

-HA lists Hard Limit

-c size sets the block size of Coredump SIZE

-t size cputime

-f Size File Size

4.5 UMASK System Administrator is used to set the user's default umask value.

5. Command related to the process

Process Basic Concept: The process is related to the execution of the command, but it is not one or one; a command may correspond to a number

Processes (such as shell script, pack, etc.). But the simplest command is only one process with umask.

Process classification:

Interactive Process: Can be executed at the front desk or background, the front and back can be switched

Batch Process: Do not submit through the terminal, generally put them in the order in the task queue.

Tasks submitted by AT and crontab.

.deamon: Never terminated process, waiting to respond to service requests from other processes. Such as Sendmail,

Named (DNS), POP3 and Apache, etc.

Process related properties:

PID

Real uid

Effective Uid (SUID)

Real gid

Effective GID (SGID)

Priority (Nice Number) Executive Priority

5.1 ps

Process status lists the currently running process status, and can list all or some processes depending on the option.

Only the process (SysV) or the current user ($ user) process (BSD) starting from the current terminal is not available.

There is a difference between different UNIX versions. Linux uses BSD version of PS

BSD version PS command usage:

PS

PS AUX lists the details of all processes in the system

PS AUX | EGREP inetd

Output information content:

PID

TERMINAL is in -4 without the corresponding terminal

CPU TIME

Userid or username

Process start time or date

Process Status (STAT: S (Unnable) D (Unnterrupt Sleep) Z (OMBIE)

The W process has no resident page, N: The NICE value of the process is negative.

5.2 Kill

Kill [-signal] PID

Kill -l lists the available semaphore

Common information quantity:

-HUP (1) Restart process

PS AX | EGREP inetd

Kill -Hup PID_OF_INETD

-Kill (9) forced suspension

PID value meanings:

> 0 refers to a specific process (actual process)

= 0 All Process (PGID) of the same group

= -1 Effective Uid = Uid execute the user

<0 &&! = 1 Take the process of absolute value

5.3 Nice

Used to change the priority of one or more processes; but only root or improve the priority of the process, ordinary users can only

Reduce the priority of the process.

NICE uses a negative number to increase priority, while positive numbers indicate that the priority is lowered, usually the range is -20 to 20.

If no priority is not specified, Nice will reduce or do not change the priority of the process. Of course, if there is no authority

The priority of the process will not have any changes.

Under normal circumstances we use nice to reduce the priority of the background process (the default priority is 10).

Nice find. -name "* .c" -print &

Nice 16 Find. -Name "* .c" -print &

5.4 Wait

Wait Pid

Waiting for the job, the parameter is PID, which is sometimes used in Shell Script.

5.5 NOHUP

Nohup Command &

5.6 SLEEP

Sleep Seconds

Process front and rear replacement: Ctrl-Z, FG, BG

6. Communication 6.1 FTP

6.2 Mailx

6.3 minicom (serial terminal, modem)

7. Document comparison

CMP

COMM

DIFF (for comparison text file)

DIFF3 (compared 3 files)

SDIFF

8. File operation

Touch creates files, modify file dates, etc.

chmod

Chwon

chgrp

RM caution RM -RF

MV mobile file or rename

CP CP -R Copy Directory

Cat

RCP Remote Replication

Ln is hard connection by default, each file has the same inode

Ln -s Sourcefile Targetfile

9. Directory operation

Mkdir [-p] [-m mode] Directory

RMDir [-P] Directory

10. File information command

LS

Find

The most basic function is to find a file name or directory, the common format is as follows:

Find. -print (similar to ls -lr)

Find can use the following properties to find:

-Name finds the file name, the file name of the incomplete group *?

-Perm 00x000 eight-on-file attribute

-time N N days before visiting files

-Mtime N modified files

-ctime n file modified between N

-EXEC Command Returns the code of the command to zero (find the corresponding file), true, Command must

/; The result, in addition, {} is the file path name in the execution of the command.

-ok Command is similar to the Exec, but the user is required to confirm between each command.

-Print prints the current path name

-newer filename If the final modification date of the file is true than that of FileName.

-Type C C = [B, C, D, L, P, F] file type

-user username, as a file owner, is true for UserName

-nouser file owner does not exist in the / etc / passwd file

-group grouname file group

Logical operator: -a -o!

List:

Find $ homen / (-name a.out -o -name "* .o" /) -time 7 -exec rm {} /;

Find. -Atime 0 -Print

Find / .name .profile -print

Find. -perm 777 -a -mtime 7 -EXEC CHMOD 755 {} /

File

More

Less

Tail (tail -f filename)

HEAD

WC

Read for shell programming

COL

PG (Sysv)

11. Editor

vi

ED

Joe

12. File content lookup

GREP

EGREP

Regular expression:. * ^ $ ? []

Strings

13. Task Scheduling

AT

ATQ lists the tasks in the queue

crontab

14. Storage, induction, and compression

Compress .z

Uncompress .z

CPIO

DD DD if = inputfile of = OutputFile

DD if = boot.img of = / dev / fd0h1440

Pack .Z 30% -50% text file

PCAT PACT file.z

gzip .gz

gunzip

Tar Tar - [TXC] vf targetfile [SourceFile]

Tar -cvf target.tar sourcefilelist

Tar -tvf target.tar [filename]

Tar -xvf target.tar [filename]

GNU Tar:

Tar -zcvf target.tar.gz SourceFileList

Tar -zxvf target.tar.gz [filelist]

Tar -ztvf target.tar.gz [filelist]

Zcat .z

Uuencode

Uudecode

15. Other orders

date

ENV

Unix2dos (linux is not)

Dos2unix

uname

Uptime

Free

Time

TOP

16. Text Processing

CUT

The FMT is converted to 72 columns per row, used for email formatting

Fold folding, one line to multi-line, generally 80 columns

Join

Paste

Sort

TR

Tr '/ "' '

#! / bin / sh

For i in *

DO

MV $ I `Echo $ I | TR / [A-Z] / [A-Z] /`

DONE

UNIQ report / delete files in the same copy line

SED stream editor

SED 'S / 96 / TT /' Student.txt

awk

AWK '{Print $ 1 "" $ 2}' Sourcefile

awk -f class.awk student.txt> Linux-student.txt

The contents of the file Class.awk are as follows:

#

# Class.awk

#

Begin {Printf "% -12S% S / N", "class", "student name";

Printf "---------------------------------------- / n / n" }

/ [1-9] / b * $ / {Class = $ 0}

/ ^ 9 [5-8] / {PrintF "% -12S% S / N", Class, $ 0 | "sort"}

#ENF of class.awk

awk -f trafficient.awk traffic.txt

The document traffic.awk content is as follows:

#

# Traffic.awk

#

{IF ($ 2 <10000) T_0 = $ 2;

IF ($ 2> 10,000 && $ 2 <50000) T_10 = $ 2;

IF ($ 2> 5000 && $ 2 <100000) T_50 = $ 2;

IF ($ 2> 100000) T_100 = $ 2;

Total = $ 2}

End {Printf "T_0 =% DKB% 5.2F ​​/% / N", T_0, T0 * 100 / Total

Printf "T_10 =% DKB% 5.2F ​​/% / N", T_10, T10 * 100 / Total

Printf "T_50 =% DKB% 5.2F ​​/% / N", T_50, T_50 * 100 / Total

Printf "T_100 =% DKB% 5.2F ​​/% / N", T_100, T_100 * 100 / Total

Printf "total =% DKB / N", Total}

#End of traffic.awk

17. Network configuration commands and troubleshooting commands

17.1 ifconfig

Interface Config, NIC configuration command, related files: / proc / net / dev

Detailed inspection: man ifconfig

Example:

#ifconfig

Lo Link ENCAP: LOCAL LOOPBACK card logo package type: Local loopback

INET Addr: 127.0.0.1 Bcast: 127.255.255.255 Mask: 255.0.0.0

IP address: 127.0.0.1 Broadcast address: 127.255.255.255 Subnet mask: 255.0.0.0

Up Broadcast Loopback Running MTU: 3584 Metric: 1

Launched the Broadcast Local Roal Running Maximum Transmission Unit: 3584 Route Distance Vector: 1

Rx Packets: 718 Errors: 0 Dropped: 0 overruns: 0 frame: 0

Accept data package: 718

TX Packets: 718 Errors: 0 Dropped: 0 overruns: 0 Carrier: 0

Sended data package: 718

Collisions: 0

Collision: 0

Eth0 Link ENCAP: Ethernet Hwaddr 00:80: C8: 4C: 6A: D0

NIC logo package type: Ethernet Hardware (MAC) Address: 00: 80: C8: 4C: 6A: D0

INET Addr: 202.118.66.81 Bcast: 202.118.66.255 Mask: 255.255.255.0

IP address: 202.118.66.81 Broadcast address: 202.118.66.255 Subnet mask: 255.255.255.0

Up Broadcast Running Multicast MUNTU: 1500 metric: 1

Laked Accept Broadcasting Multi-Broadcast Maximum Transmission Unit: 1500 Route Distance Vector: 1

RX Packets: 13900 Errors: 0 Dropped: 0 overruns: 0 frame: 0

Accept data package: 13900

TX Packets: 5859 Errors: 0 Dropped: 0 overruns: 0 Carrier: 0

Sended data package: 5859

Collisions: 0

Collision: 0

Interrupt: 10 Base Address: 0xE400

Interrupt (IRQ): 10 Port Address: 0xE400

#ifconfig eth0 Display information about Eth0

#ifconfig -a Displays configuration information for all network devices

#ifconfig eth0 down Down Eth0

#ifconfig eth0 202.118.66.81 Broadcast 202.118.66.255 [UP]

#ifconfig eth0 202.118.6.81 Broadcast 202.118.66.255 Netmask 255.255.255.0

#ifconfig eth0 up

17.2 ROUTE

Routing Table Maintenance Command, Related Files: / Proc / Net / Route

$ / SBIN / ROUTE

Kernel IP Routing Table

Destination Gateway Genmask Flags Metric Ref Use Iface

LocalNet * 255.255.255.0 U 0 0 49 ETH0

192.168.1.0 * 255.255.255.0 u 0 0 655 Eth1

192.168.2.0 * 255.255.255.0 U 0 0 498 Eth2

192.168.3.0 * 255.255.255.0 U 0 0 825 Eth3

127.0.0.0 * 255.0.0.0 U 0 0 13 LodeFault Olive.dlut.edu. 0.0.0.0 UG 1 0 4834 Eth0

# ROUTE Add Default GW 202.118.66.1

# ROUTE Add Default GW 202.118.66.1 Eth0

# / sbin / route add -net 202.118.68.0 Netmask 255.255.252.0 GW 202.118.66.16

# / sbin / rouet Del Default 202.118.66.1

# / sbin / route del -net 202.118.68.0 Netmask 255.255.252.0 GW 202.118.66.16

17.3 NetStat

Display host current routing table, related files: / proc / net / route

Netstat -Rn

/ home / hbwork [102] netstat -rn

Routing Table:

Destination Gateway Flags Ref Use Interface

----------------------------------- ------ ---------

202.118.70.27 202.118.66.16 UGHD 0 1

202.118.69.254 202.118.66.16 UGHD 0 1

202.118.68.243 202.118.66.16 UGHD 0 1

202.118.70.21 202.118.66.16 UGHD 0 0

202.118.71.10 202.118.66.16 UGHD 0 1

202.118.71.204 202.118.66.16 UGHD 0 1

202.118.68.160 202.118.66.16 UGHD 0 1

202.199.128.52 202.118.66.254 UGHD 0 2

202.118.68.66 202.118.66.16 UGHD 0 1

202.118.69.69 202.118.66.16 UGHD 0 1

202.118.69.228 202.118.66.16 UGHD 0 1

202.118.71.68 202.118.66.16 UGHD 0 1

202.118.70.37 202.118.66.16 UGHD 0 1

202.118.66.0 202.118.66.18 U 3 12259 HME0

224.0.0.0 202.118.66.18 U 3 0 HME0

Default 202.118.66.1 ug 0 70354

127.0.0.1 127.0.0.1 UH 0 41316 LO0

Destionation: Target Network or Host Gateway: The next route, thinks the IP address of the route closer to the target, will be sent to the data transfer

This IP address.

Flags:

U Router IS UP, target can be reached

H Specific Router, route to a specific host

G This route is indirectly accessed for other routing. If there is no G flag, it indicates the corresponding

Routers or hosts are directly connected to the corresponding router.

D This route is established by the path redirection information of the ICMP protocol.

M modified by the re-direction information of ICMP

REFS: The number of links currently in this route now, these connections may be ftp longer than a continuous time or

Telnet Task, each of which uses TCP services or applications to add 1.

USE: The amount of data package through this router since the TCP / IP starts.

Interface: NIC logic name, Unix different names.

17.4 NSLOOKUP

Name Server Lookup, DNS Server Diagnostic Tools

Use the quote:

[hbwork @ helily hbwork] $ nslookup www.dlut.edu.cn

Server: Cedrus.dlut.edu.cn

Address: 202.118.66.6

Name: peony.dlut.edu.cn

Address: 202.118.66.18

Aliases: www.dlut.edu.cn

[HBWork @ Helius HBwork] $ nslookup

Default Server: Cedrus.dlut.edu.cn

Address: 202.118.66.6

> www.dlut.edu.cn

Server: Cedrus.dlut.edu.cn

Address: 202.118.66.6

Name: peony.dlut.edu.cn

Address: 202.118.66.18

Aliases: www.dlut.edu.cn

> Set Q = NS # Query the DNS server of the corresponding domain

> dlut.edu.cn # Enter the domain name you want to query

Server: Cedrus.dlut.edu.cn # default domain server is CEDRUS.DLUT.EDU.CN

Address: 202.118.66.6 # Reference /etc/resolv.conf file

DLUT.EDU.CN NAMESERVER = Gingko.dlut.edu.cn

DLUT.EDU.CN NAMESERVER = Olive.dlut.edu.cn

DLUT.EDU.CN NAMESERVER = CEDRUS.DLUT.EDU.CN

Gingko.dlut.edu.cn internet address = 202.118.66.8

Olive.dlut.edu.cn internet address = 202.118.68.1

Olive.dlut.edu.cn internet address = 202.118.69.1

Olive.dlut.edu.cn internet address = 202.118.70.1

Olive.dlut.edu.cn internet address = 202.118.71.1

Olive.dlut.edu.cn internet address = 202.118.66.16

Cedrus.dlut.edu.cn internet address = 202.118.66.6

> dl.lnpta.net.cn # Query DL.Lnpta.Net.cn domain name server

Server: Cedrus.dlut.edu.cnaddress: 202.118.66.6

Non-Authoritative Answer:

Dl.lnpta.net.cn nameserver = ns.lnpta.net.cn

Authoritative Answers Can Be Found from:

Ns.lnpta.net.cn Internet address = 202.96.64.68

> Server ns.lnpta.net.cn

DEFAULT Server: ns.lnpta.net.cn

Address: 202.96.64.68

Server: ns.lnpta.net.cn

Address: 202.96.64.68

Non-Authoritative Answer:

Www.dlut.edu.cn canonical name = peony.dlut.edu.cn

> dlut.edu.cn # 查询 域 dlut.edu.cn MX record

Server: ns.lnpta.net.cn

Address: 202.96.64.68

Non-Authoritative Answer:

DLUT.EDU.CN Preference = 1, mail exchanger = gingko.dlut.edu.cn

Authoritative Answers Can Be Found from:

DLUT.EDU.CN NAMESERVER = Gingko.dlut.edu.cn

DLUT.EDU.CN NAMESERVER = CEDRUS.DLUT.EDU.CN

DLUT.EDU.CN NAMESERVER = Olive.dlut.edu.cn

Gingko.dlut.edu.cn internet address = 202.118.66.8

Cedrus.dlut.edu.cn internet address = 202.118.66.6

Olive.dlut.edu.cn internet address = 202.118.71.1

Olive.dlut.edu.cn internet address = 202.118.66.16

Olive.dlut.edu.cn internet address = 202.118.68.1

Olive.dlut.edu.cn internet address = 202.118.69.1

Olive.dlut.edu.cn internet address = 202.118.70.1

> EXIT

17.5 ping

TCP / IP ICMP (Internet Control Message Protocol) Diagnostic Tools

ping [Hostname | ipaddress]

Error Message: Host Unreachable

NetWork unreachable

[HBWork @ helily hbwork] $ ping 202.118.66.1

Ping 202.118.66.1 (202.118.66.1): 56 Data Bytes

64 bytes from 202.118.66.1: ICMP_SEQ = 0 TTL = 255 TIME = 23.1 MS

64 bytes from 202.118.66.1: ICMP_SEQ = 1 TTL = 255 TIME = 2.1 MS

64 bytes from 202.118.66.1: ICMP_SEQ = 2 TTL = 255 TIME = 1.9 ms

--- 202.118.66.1 Ping Statistics --- 3 Packets Transmitted, 3 Packets Received, 0% Packet LOSS

Round-trip min / avg / max = 1.9 / 9.0 / 23.1 ms

17.6 Hostname

Show or set host name

17.7 DomainName

Show or set host domain names

17.8 Traceroute

Windows 95: Tracert

Traceroute hostname

Traceroute Destinationation_IP_Address

17.9 ARP

Display or set the MAC address of the corresponding host / IP address

Related files: / proc / net / arp

CAT / Proc / Net / ARP

$ ARP HOSTNAME

$ ARP -A

$ ARP IP_ADDRESS

Show or set host names require root privileges

#arp -s hostname eth_address [TEMP] [PUB]

#arp -d hostname

#arp -d ip_address

#arp -f mac_ip_map_file common file name / etc / ether

-

[M [1; 32M ※ Source:. Bihai Youth bbs.dlut.edu.cn. [From: apple.dlut.edu.c] [M

转载请注明原文地址:https://www.9cbs.com/read-77743.html

New Post(0)