Joke Collection Website - Mood Talk - Talk about commonly used UNIX commands?

Talk about commonly used UNIX commands?

Common commands in UNIX systems

Common command formats in UNIX systems:

command [flags] [argument1] [argument2] ...

The flags start with -, multiple flags can be connected with a -, for example, ls -l -a is the same as ls -la.

Depending on the command, parameters are optional or required; all commands accept input from standard input and output

The results are displayed on standard output, and error messages are displayed on the standard error output device.

These devices can be redirected using the redirection feature.

The command returns a 0 value after normal execution. If the command fails and is not completely completed, a

non-zero value is returned (can be viewed in the shell using the variable $?). This return value can be used in shell scripts as part of the control logic

.

Note: The flags may be different in different UNIX versions.

1. User-related commands

1.1 login

(The function of this command under LINUX Redhat is different from that of Solaris/BSD. Executing login will exit the current task ).

login:

Password:

Related files:

In the following files, set the necessary settings for shell operation. Path, terminal type, other variables or special programs.

$HOME/.profile (Bourne shell, sh, bash)

$HOME/.cshrc (csh, tcsh)

p>

$HOME/.tcshrc (tcsh)

The shell of each user is listed in the /etc/passwd file

/etc/csh.cshrc

/etc/csh.login

/etc/profile (Bourne shell, bash)

/etc/login (Bourne shell, bash)

csh: /etc/csh.cshrc and $HOME/.cshrc are read every time they are executed.

And /etc/csh.login and $HOME/.login are only executed when the shell is registered

After modifying the corresponding file, use source .cshrc to enable related modifications. If the path is modified,

You also need to use rehash to refresh the executable file hash table.

tcsh: $HOME/.tcshrc, there are no files to read .cshrc

sh: /etc/profile and $HOME/.profile register shell

bash: /etc/profile and $HOME/.bash_profile are read by registered shells

.bashrc can only be read by interactive non-registered shells.

Manually execute related files under sh/bash:

. /etc/profile

Execution sequence of related files

sh: / etc/profile -> $HOME/.profile

csh/tcsh: /etc/csh.cshrc -> /etc/csh.login -> $HOME/.cshrc

- > $HOME/.login

Variable settings:

sh/bash: TERM=vt100; export TERM

OR: export TERM=vt100 (bash)

csh: setenv TERM vt100

Commonly used variables:

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

stty erase ^H

(2)umask protection attribute for new files or directories

(3)TERM

(4) Do not add it to PATH.

p>

1.2. rlogin

Similar to telnet, connect to the remote host.

rlogin remotehost [ -l loginname ]

Or:

rsh [-l loginname] remotehost [command]

Related files:

/etc/hosts.equiv and $HOME/.rhosts of the remote host

Related network configuration files:

The r system service in the /etc/inetd.conf file. Under Redhat, it is shell, login, exec, corresponding to the

network daemon ( daemon) are in.rshd, in.rlogind, in.rexecd.

Recommendation: From a security perspective, close r series services.

1.3. telnet

telnet remotehost [port]

Related files:

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

/etc/issue.net

p>

TIPS: strings /usr/sbin/in.telnetd |egrep issue

1.4. passwd changes password

1.5 exit exits current shell

2. Search 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 built-in command of bash/tcsh

[hbwork@toshiba]$ which which

which: shell built-in command.

2.2 where(tcsh)

Syntax: where command

2.3 locat

e (LINUX)

Syntax: locate filename

Related commands: updatedbchange locate filename database

3. View the usage of the command

man

Related files:

/etc/man.config

4. Common administrator commands

4.1 install

Used to install a new command or daemon, etc. Generally, it is not necessary, but many software uses install in its installation

shell script to copy the target file to the corresponding directory and set it correctly. attributes, etc.

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] [--owner=owner] [--help] [--version]

4.2 shutdown

Different unix parameters Same, the following methods are commonly used to shut down under Linux:

shutdown -h now

shutdown -r now (equivalent to reboot)

4.3 halt

poweroff

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

4.4 ulimit

This is available in korn shell and bourne shell command, the corresponding command in the csh series is limit.

Used to limit the system resources that each process can use, usually divided into two types of limits:

. Hard limits defined by the system resources, only root can change

. The soft limit on the use of new processes can be added to the Hard Limit of the system.

Flags:

- a List soft limit

-Ha List Hard Limit

-c size Set coredump size block size

-t size cputime

< p>-f size file size

4.5 umask is used by system administrators to set the user's default umask value.

5. Process-related commands

Process Basic concept: Processes are related to the execution of commands, but there is no one-to-one correspondence; one command may correspond to several processes (such as shell script, pipe, etc.). But the simplest command and umask only have one process. .

Process classification:

. Interactive process: can be executed in the foreground or background, and the front and backend can be switched

. Batch process: not submitted through the terminal, They are generally placed in the task queue for sequential execution. For example, tasks submitted through

at and crontab.

.deamon: a process that never terminates, waiting to respond to services from other processes Request. Such as sendmail,

named (DNS), POP3 and apache, etc.

Related attributes of the process:

PID

Real UID

Effective UID (SUID)

Real GID

Effective GID (SGID)

Priority (Nice Number) execution priority

5.1 ps

Process Status, lists the status of currently running processes. Depending on the options, all or part of the processes can be listed

. Without options, only those started from the current terminal are listed. Process (SYSV) or the process (BSD) of the current user ($USER),

There are differences between different UNIX versions. Linux uses the BSD version of ps

. The BSD version of ps Command usage:

ps

ps aux lists the details of all processes in the system

ps aux |egrep inetd

Output information content:

PID

Terminal If there is no corresponding terminal, it is -

cpu time

UserID or Username

Process startup time or date

Process status (Stat: S(leep) R(unnable) D(uninterrupt sleep) Z(ombie)

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

5.2 kill

kill [-signal] PID

kill -l lists available semaphores

Common information volume:

-HUP (1) Restart process

ps ax |egrep inetd

kill -HUP pid_of_inetd

< p>-KILL (9) Forced termination

PID value meaning:

>0 refers to a specific process (actual process)

=0 for users in the same group All processes (PGID)

=-1 Effective UID = uid of the user who executes the command

<0 && !=1 Process taking the absolute value

5.3 nice

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

reduce the priority of a process.

Nice uses negative numbers to indicate increasing the priority, while positive numbers indicate reducing the priority. Usually the value range is -20~20.

If increasing the priority is not specified, nice will reduce or not change the process. The priority of the process. Of course, if there is no permission

The priority of the process will not change.

Generally, we use nice to lower the priority of the background process (the default priority for 10).

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

nice 16 find . -name "*.c" -print &

< p>5.4 wait

wait PID

Wait for the job to end. The parameter is pid, which is sometimes used in shell scripts.

5.5 nohup

< p>nohup command &

5.6 sleep

sleep seconds

Process switching between front and back: Ctrl-Z, fg, bg

6 . Newsletter <

/p>

6.1 ftp

6.2 mailx

6.3 minicom (serial terminal, MODEM)

7. File comparison

cmp

comm

diff (for comparing text files)

diff3 (for comparing 3 files)

sdiff

8. File operations

touch to create files, modify file dates, etc.

chmod

chwon

chgrp

rm, use rm -rf with caution

mv moves files or renames

cp cp -r copies directories

cat

rcp Remote copy

ln is hard-connected by default, each file has the same inode

ln -s sourcefile targetfile

9. Directory operations

mkdir [-p] [-m mode] directory

rmdir [-p] directory

10. File information command

ls

p>

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 attributes to search:

-name searches for file names, file names containing wildcard characters *? are enclosed in quotation marks

-perm 00x000 octal file attributes< /p>

-atime n Files accessed n days ago

-mtime n Files modified n days ago

-ctime n File status n days ago Modified

-exec command If the return code of the command is zero (the corresponding file is found), it is true. The command must end with

\;. In addition, during the execution of the command {} For the found file path name

-ok command is similar to exec, but requires user confirmation before executing each command

-print prints the current path name

-newer filename is true if the last modification date of the file is newer than filename

-type c c=[b,c,d,l,p,f]File type

-user username True if the owner of the file is username

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

-group grouname file group

Logical operator: -a -o !

List:

find $HOME \( -name a.out -o -name "*.o" \ ) -atime +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

p>

ed

joe

12. File content search

grep

egrep

Formal Expression: . * ^ $ + ? []

strings

13. Task scheduling

at

atq is listed in the queue Tasks

crontab

14. Storage, summary 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 commands

date

env

unix2dos (not available in linux)

dos2unix

uname

uptime

uptime

dos2unix p>

free

time

top

16. Text processing

cut

fmt every The row format is converted into 72 columns, used for email formatting

fold line folding processing, from one row to multiple rows, usually 80 columns

join

paste < /p>

sort

tr

tr '\"' '' < file1

#!/bin/sh

for i in *

do

mv $i `echo $i |tr /[a-z]/[A-Z]/`

done

uniq reports/removes identical copied lines in files

sed stream editor

sed 's/96/tt/' student.txt

awk

awk '{print $1" "$2}' sourcefile

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

File The content of class.awk is as follows:

#

#class.awk

#

BEGIN {printf "%-12s%s\ n","class","student number and 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 traffic.awk traffic.txt

The content of the file traffic.awk is as follows:

#

#traffic.awk

#

{ if ( $2 < 10000 ) t_0 += $2;

if ( $2 > 10000 && $2 < 50000) t_10 += $2;

if ( $2 > 50000 && $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

p>

17. Network configuration commands and troubleshooting commands

17.1 ifconfig

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

Detailed instructions: man ifconfig

Example:

#ifconfig

lo Link encap:Local Loopback

Network card identification encapsulation 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

Started to accept broadcasts Local loopback is running Maximum transmission unit: 3584 Routing distance vector: 1

RX packets:718 errors:0 dropped:0 overruns:0 frame:0

Accepted packets:718

TX packets:718 errors:0 dropped:0 overruns :0 carrier:0

Packets sent: 718

collisions:0

Collisions:0

eth0 Link encap:Ethernet HWaddr 00:80:C8:4C:6A:D0

Network card identification encapsulation type: Ethernet Hardware (MAC) address: 0

0: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 MTU: 1500 Metric: 1

Started accepting broadcasts Running multicast Maximum transmission unit: 1500 Routing Distance vector: 1

RX packets:13900 errors:0 dropped:0 overruns:0 frame:0

Received packets: 13900

TX packets: 5859 errors:0 dropped:0 overruns:0 carrier:0

Packets sent: 5859

collisions:0

Collisions:0

Interrupt:10 Base address:0xe400

Interrupt (IRQ): 10 Port address: 0xe400

#ifconfig eth0 displays eth0 related information

# ifconfig -a displays the configuration information of all network devices

#ifconfig eth0 down Down eth0

#ifconfig eth0 202.118.66.81 broadcast 202.118.66.255 [up]

#ifconfig eth0 202.118.66.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

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 lo

default 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 the current routing table of the host, related files: /proc/net/route

< p>netstat -rn

/home/hbwork[102]netstat -rn

Routing Table:

Destination Gateway Flags Ref Use Interface

< p>-------------------- -------------------- ----- --- -- ------ ---------

202.118.70.27 202.118.66.16 UGHD 0 1

202.118.69.254 202.118.66.16 UGHD 0 1 < /p>

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

< p>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 U 3 12259 hme0

202.118.70.37 202.118.66.16 U 0 1

202.118.66.18 p>

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, the IP address of the route considered to be closer to the destination, will be sent to

this IP address during data transmission.

Flags:

U Router is up, target reachable

H Specific router, route to specific host

G This route is for other routes Accessed indirectly, if there is no G flag, it indicates that the corresponding

router or host is directly connected to the corresponding router.

D This route is a path redirection of the ICMP protocol. Information established.

M Modified by ICMP redirect information

REFS: The number of links currently in use on this route. These connections may be caused by long continuous times. ftp or

telnet tasks, each service or application that uses tcp increases the value of this column by 1 when executed.

Use: The traffic passing through this router since TCP/IP started The amount of data packets.

Interface: The logical name of the network card, the name is different for different UNIX.

17.4 nslookup

Name Server Lookup, DNS server diagnostic tool

Usage example:

[hbwork@helius 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

p>

[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 to be queried

Server: cedrus.dlut.edu.cn #The default domain name server is cedrus.dlut.edu.cn

< p>Address: 202.118.66.6 #Refer to the /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 < /p>

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 < /p>

cedrus.dlut.edu.cn internet address = 202.118.66.6

> dl.lnpta.net.cn #Query the domain name server of dl.lnpta.net.cn

Server: cedrus.dlut.edu.cn

Address: 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 #Query the MX record of domain dlut.edu.cn

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 Tool

ping [hostname|IpAddress]

Error Message: host unreachable

network unreachable

[hbwork@helius 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

Display or set the host name

17.7 domainname

Display or set the host domain name

17.8 traceroute

Windows 95: tracert

traceroute hostname

traceroute destionation_ip_address

17.9 arp

Display or set the mac address of the corresponding host/ip address

Related File: /proc/net/arp

cat /proc/net/arp

$arp hostname

$arp -a

$arp ip_address

Root permission is required to display or set the host name

#arp -s hostname eth_address [temp] [pub]

#arp -d hostname < /p>

#arp -d ip_address

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