[O & M favorites] common CentOS commands

Source: Internet
Author: User
Tags i18n nameserver dmesg

[O & M favorites] common CentOS commands

1. view the system Port and release the port

[Root @ my_nn_01 WEB-INF] # lsof-w-n-I tcp: 80

COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME

Java 24065 root 34u IPv6 269149 TCP *: http (LISTEN)

[Root @ my_nn_01 WEB-INF] # kill-9 24065

2. display the file list in KB/MB format

[Root @ cncloud iso] # ls-lh

Total 5.8 GB

-Rw-r -- 1 root 4.1G 2011-08-01 CentOS-5.5-x86_64-bin-DVD-1of2.iso

-Rw-r -- 1 root 413 M 2011-08-01 CentOS-5.5-x86_64-bin-DVD-2of2.iso

-Rw-r -- 1 root 630 M 2009-12-07 Win2003.iso

-Rw-r -- 1 root 618 M 2010-09-08 Windows. Server.2003.R2. With. Sp2 X64.iso

3. view the number of CPU digits (32 or 64)

[Root @ cloud_test download] # getconf LONG_BIT

64

4. view the current linux version

[Root @ cncloud ~] # Cat/etc/redhat-release

CentOS release 5.4 (Final)

5. uname is used to view system information.

[Root @ cncloud ~] # Uname-r # print the released Kernel

2.6.18-164. el5xen

# Uname-a # view kernel/operating system/CPU Information

[Root @ cloud_test download] # uname-

Linux cloud_test 2.6.18-194. el5 #1 SMP Fri Apr 2 14:58:14 EDT 2010 x86_64 x86_64 x86_64 GNU/Linux

6. view the default system language

Echo $ LANG $ LANGUAGE

Cat/etc/sysconfig/i18n

7. Check the time zone and whether the UTC time is used.

[Root @ cncloud ~] # Cat/etc/sysconfig/clock

# The ZONE parameter is only evaluated by system-config-date.

# The timezone of the system is defined by the contents of/etc/localtime.

ZONE = "Asia/Shanghai"

UTC = false

ARC = false

8. view the Host Name

Hostname

Cat/etc/sysconfig/network

Modifying the host name is to modify this file, and it is recommended that you also modify the/etc/hosts file.

9. view the start time

[Root @ cncloud ~] # Uptime

13:56:21 up 97 days, 2 users, load average: 0.08, 0.08, 0.05

10. view the operating system version

[Root @ cloud_test download] # head-n 1/etc/issue

CentOS release 5.5 (Final)

# Cat/proc/cpuinfo # view CPU Information

# Hostname # view the computer name

# Lspci-TV # list all PCI devices

# Lsusb-TV # list all USB devices

[Root @ cloud_test download] # lsusb-TV

Bus #1

'-Dev #1 Vendor 0x0000 Product 0x0000

'-Dev #2 Vendor 0x0627 Product 0x0001

# Lsmod # list loaded Kernel Modules

# Env # view environment variable resources

11. Common cpu display commands

More/proc/cpuinfo | grep "model name"

Grep "model name"/proc/cpuinfo

[Root @ localhost/] # grep "CPU"/proc/cpuinfo

Model name: Intel (R) Pentium (R) Dual CPU E2180 @ 2.00 GHz

Model name: Intel (R) Pentium (R) Dual CPU E2180 @ 2.00 GHz

If you only want to display the second column:

Grep "model name"/proc/cpuinfo | cut-f2-d:

12. Common memory viewing commands

Grep MemTotal/proc/meminfo

Grep MemTotal/proc/meminfo | cut-f2-d:

Free-m | grep "Mem" | awk '{print $2 }'

Awk '/MemTotal/{printf ("%. 2f \ n", $2/1024)}'/proc/meminfo

13. view the total disk size:

[Root @ localhost ~] # Fdisk-l | grep Disk | cut-f2-d:

498.9 GB, 498999492608 bytes

1995.9 GB, 1995997970432 bytes

When we run the free command to view the idle memory of the machine, we will find that the free value is very small. This is mainly because there is such an idea in linux, the memory does not need to be white, so it tries its best to cache and buffer some data for the next use. But in fact, these memories can also be used immediately.

So free memory = free + buffers + cached = total-used

14. view the software packages installed during system installation.

Cat-n/root/install. log

More/root/install. log | wc-l

Check the software packages that have been installed.

Rpm-qa

Rpm-qa | wc-l

Yum list installed | wc-l

But it is strange that the number of installation packages I query through rpm and yum is not the same. No reason is found.

15. view the keyboard layout

Cat/etc/sysconfig/keyboard

Cat/etc/sysconfig/keyboard | grep KEYTABLE | cut-f2-d =

16. View selinux Information

Sestatus

Sestatus | cut-f2-d:

Cat/etc/sysconfig/selinux

Disable selinux

1. [root @ linux ~] # Vi/etc/selinux/config
# Change the following settings to the following:
SELINUX = disabled

2. Modify the settings of grub when the machine is on.
[Root @ linux ~] # Vi/boot/grub/menu. lst
... Omitted .....
Kernel/boot/vmlinuz-2.6.9 ro root =/dev/hda1 rhgb selinux = 0
... Omitted .....

3. Reboot
[Root @ linux ~] # Sync; reboot

17. Resources

# Free-m # view memory usage and swap zone usage

[Root @ cloud_test download] # free-m

Total used free shared buffers cached

Mem: 2453 2402 50 0 272 799

-/+ Buffers/cache: 1330 1123

Swap: 4094 0 4094

# Df-h # view the usage of each partition

[Root @ cloud_test download] # df-h

Filesystem Size Used Avail Use % Mounted on

/Dev/hda2 55 GB 11G 41G 21%/

/Dev/hda1 99 M 12 M 82 M 13%/boot

Tmpfs 1.2G 0 1.2G 0%/dev/shm

# Du-sh <Directory Name> # view the size of a specified directory

[Root @ cloud_test download] # du-sh

2.7 GB

[Root @ cncloud ~] # Du/etc-sh

126 M/etc

# Grep MemTotal/proc/meminfo # view total memory

[Root @ cloud_test download] # grep MemTotal/proc/meminfo

MemTotal: 2512164 kB

# Grep MemFree/proc/meminfo # view the Amount of idle memory

# Uptime # view system running time, number of users, and load

[Root @ cloud_test download] # uptime

20:25:06 up 9 days, 3 users, load average: 0.00, 0.00, 0.00

# Cat/proc/loadavg # view system load disks and partitions

[Root @ cloud_test download] # cat/proc/loadavg

0.00 0.00 0.00 1/195 19443

[Root @ aca80a67 ~] # Cat/proc/meminfo

MemTotal: total memory

MemFree: idle memory size

Buffers: used for temporary disk cache

Cached: I/O read/write cache, excluding SwapCached

SwapCached

In fact, MemFree does not represent the total amount of idle memory in the system. The cache used by the system for I/O should also be included in the idle memory range. Memory idle:

MemFree + Buffers + Cached + SwapCached

[Root @ aca80a67 ~] # Ll-h/proc/kcore

Idle memory = free + buffers + cached = total-used

[Root @ aca80a67 ~] # Grep MemTotal/proc/meminfo

MemTotal: 2058016 kB

18. disks and partitions

# Mount | column-t # view the status of the mounted Partition

[Root @ cloud_test download] # cat/proc/loadavg

0.10 0.03 0.01 1/195 19445

[Root @ cloud_test download] # mount | column-t

/Dev/hda2 on/type ext3 (rw)

Proc on/proc type proc (rw)

Sysfs on/sys type sysfs (rw)

Devpts on/dev/pts type devpts (rw, gid = 5, mode = 620)

/Dev/hda1 on/boot type ext3 (rw)

Tmpfs on/dev/shm type tmpfs (rw)

None on/proc/sys/fs/binfmt_misc type binfmt_misc (rw)

Sunrpc on/var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)

# Fdisk-l # view all partitions

[Root @ cloud_test download] # fdisk-l

Disk/dev/hda: 64.4 GB, 64424509440 bytes

255 heads, 63 sectors/track, 7832 cylinders

Units = cylinders of 16065*512 = 8225280 bytes

Device Boot Start End Blocks Id System

/Dev/hda1*1 13 104391 83 Linux

/Dev/hda2 14 7309 58605120 83 Linux

/Dev/hda3 7310 7831 4192965 82 Linux swap/Solaris

# Swapon-s # view all swap partitions

[Root @ localhost ~] # Swapon-s

Filename Type Size Used Priority

/Dev/sda3 partition 2096472 0-1

# Hdparm-I/dev/hda # view disk parameters (only applicable to IDE devices)

[Root @ localhost ~] # Hdparm-I/dev/hdc

/Dev/hdc:

Model = VMware Virtual ide cdrom Drive, FwRev = 00000001, SerialNo = 10000000000000000001

Config = {SoftSect Fixed Removeable DTR <= 5Mbs DTR> 10Mbs nonMagnetic}

RawCHS = 0/0/0, TrkSize = 0, SectSize = 0, ECCbytes = 0

BuffType = unknown, BuffSize = 32kB, MaxMultSect = 0

(Maybe): CurCHS = 0/0/0, CurSects = 0, LBA = yes, LBAsects = 0

IORDY = on/off, tPIO = {min: 120, w/IORDY: 120}, tDMA = {min: 120, rec: 120}

PIO modes: pio0 pio1 pio2 pio3 pio4

DMA modes: sdma0 sdma1 sdma2 mdma0 mdma1 mdma2

UDMA modes: udma0 udma1 * udma2

AdvancedPM = no

Drive conforms to: ATA/ATAPI-4 T13 1153D revision 17: ATA/ATAPI-1 ATA/ATAPI-2 ATA/ATAPI-3 ATA/ATAPI-4

* Signifies the current active mode

# Dmesg | grep IDE # view the network of the IDE Device Detection Status at startup

[Root @ localhost ~] # Dmesg | grep IDE

Uniform Multi-Platform E-IDE driver Revision: 7.00alpha2

PIIX4: IDE controller at PCI slot :00:07. 1

Probing IDE interface ide0.0...

Probing IDE interface ide1...

Hdc: VMware Virtual ide cdrom Drive, atapi cd/DVD-ROM drive

Probing IDE interface ide0.0...

Target0: 0: 0: FAST-40 wide scsi 80.0 MB/s ST (25 ns, offset 127)

19. Network

# Ifconfig # view the attributes of all network interfaces

# Iptables-L # view firewall settings

Disable Firewall

# Service iptables stop (temporarily disable. The next time you restart the system, it will no longer work)

# Chkconfig iptables off. (permanently used)

Or disable the enabled option of iptables in system-config-firewall.

# Route-n # view the route table

[Root @ localhost ~] # Route-n

Kernel IP routing table

Destination Gateway Genmask Flags Metric Ref Use Iface

192.168.171.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0

169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0

0.0.0.0 192.168.171.2 0.0.0.0 UG 0 0 0 eth0

# Netstat-lntp # view all listening ports

[Root @ localhost ~] # Netstat-lntp

Active Internet connections (only servers)

Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name

Tcp 0 0 0.0.0.0: 111 0.0.0.0: * LISTEN 3517/portmap

Tcp 0 0 127.0.0.1: 631 0.0.0.0: * LISTEN 3038/cupsd

Tcp 0 0 127.0.0.1: 25 0.0.0.0: * LISTEN 3791/sendmail: acce

Tcp 0 0 0.0.0.0: 763 0.0.0.0: * LISTEN 3549/rpc. statd

Tcp 0 0: 22: * LISTEN 3769/sshd

# Netstat-antp # view all established connections

[Root @ localhost ~] # Netstat-antp

Active Internet connections (servers and established)

Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name

Tcp 0 0 0.0.0.0: 111 0.0.0.0: * LISTEN 3517/portmap

Tcp 0 0 127.0.0.1: 631 0.0.0.0: * LISTEN 3038/cupsd

Tcp 0 0 127.0.0.1: 25 0.0.0.0: * LISTEN 3791/sendmail: acce

Tcp 0 0 0.0.0.0: 763 0.0.0.0: * LISTEN 3549/rpc. statd

Tcp 0 0: 22: * LISTEN 3769/sshd

# Netstat-s # view network statistics process

Ifconfig eth0 172.10.15.12

Note: The IP address configured with ifconfig becomes invalid after linux is restarted.

If you want the address to always take effect, you can use the command

System-config-network command

You can set the second ip address for the NIC: ifconfig eth0: 1 172.10.15.13

You can also add netmask to add a subnet mask.

[Root @ cncloud ~] # Cat/etc/sysconfig/network-scripts/ifcfg-eth0 | grep IPADDR

IPADDR = 172.10.15.3

[Root @ cncloud ~] # Cat/etc/sysconfig/network-scripts/ifcfg-eth0 | grep IPADDR | cut-f2-d =

172.10.15.3

[Root @ cncloud ~] # Ifconfig eth0 | grep "inet addr:" | awk '{print $2}' | cut-c 6-

172.10.15.3

[Root @ cncloud ~] # Ifconfig | grep 'inet addr: '| grep-V' 127. 0.0.1' | cut-d:-f2 | awk '{print $1 }'

172.10.15.3

192.168.122.1

20. view the Gateway

[Root @ cncloud ~] # Cat/etc/sysconfig/network

NETWORKING = yes

NETWORKING_IPV6 = no

HOSTNAME = cncloud.com.cn

GATEWAY = 172.10.15.254

21. View dns

[Root @ cncloud ~] # Cat/etc/resolv. conf

Nameserver 172.10.15.3

Nameserver 202.96.128.86

22. Process

# Ps-ef # view all processes

# Top # real-time display of Process status users

23. User

# W # view active users

# Id <User Name> # view specified user information

[Root @ localhost ~] # Id root

Uid = 0 (root) gid = 0 (root) groups = 0 (root), 1 (bin), 2 (daemon), 3 (sys), 4 (adm ), 6 (disk), 10 (wheel) context = root: system_r: unconfined_t: SystemLow-SystemHigh

# Last # view User Logon logs

[Root @ localhost ~] # Last

Root pts/1: 0.0 Thu Mar 24 still logged in

Root: 0 Thu Mar 24 :02 still logged in

Root: 0 Thu Mar 24)

Reboot system boot 2.6.18-164. el5 Fri Mar 25 (-7:-4)

Root: 0 Mon Mar 21 20:24-crash (3 + 06: 35)

Root: 0 Mon Mar 21)

Reboot system boot 2.6.18-164. el5 Tue Mar 22 (2 + 16: 22)

Wtmp begins Tue Mar 22 03:33:26 2011

# Cut-d:-f1/etc/passwd # view all users in the system

# Cut-d:-f1/etc/group # view all groups in the system

# Crontab-l # view the scheduled Task Service of the current user

The time table format is as follows: f1 f2 f3 f4 f5 program

Use VI to edit a cronfile file, and then enter a time table in good format in the file. After editing, save and exit.

Enter

$: Crontab cronfile

In this way, the cronfile file is submitted to the c r o n process, a copy of the newly created cronfile has been stored in the/v a r/s p o l/c r o n directory. The file name is the user name.

After the program is executed at the specified time, the system will send you a letter showing the program execution content. If you do not want to receive such a letter, add>/dev/null 2> & 1 after each line is empty.

Useradd user1

Useradd user2

Groupadd group1

Gpasswd-a user1 group1

Adding User "user1" to group "group1"

24. Service

# Chkconfig -- list # list all system services

# Chkconfig -- list | grep on # list all started system service programs

25. Program

# Rpm-qa # view all installed software packages

26. Chinese garbled characters

Download the Chinese support package:

Fonts-chinese-3.02-12.el5.noarch Chinese Character bag

Fonts-ISO8859-2-75dpi-1.0-17.1.noarch font display pack

L check "Chinese" in "supported language" during installation. Note that the language used for installation is different from the supported language.

Or

L if the chinese font is already installed, run yum install fonts-chinese to install the chinese font. In this way, firefox and gedit can correctly display Chinese characters.

Locale-a: view supported languages

Vi/etc/sysconfig/i18n

Change to LANG = "zh_CN.UTF-8" to restart

27. backup and recovery

Restore the grub configuration file

Remember the structure of the grub configuration file

Title Red Hat Enterprise Linux Server (2.6.18-164. el5)

Root (hd0, 0) # indicates to find the configuration file from the first partition of the first hard disk in the system

Kernel/vmlinuz-2.6.18-164.el5 ro root = LABEL =/rhgb quiet

# Ro indicates read-only

# LABEL =/indicates searching in the root directory

Initrd/initrd-2.6.18-164.el5.img

Delete/boot/grub. conf

The system cannot be started.

You can use the following command when starting

Grub> root (hd0, 0)

Filesystem type is ext2fs, partition type 0x83

Grub & gt; kernel/vmlinuz-2.6.18-164.el5 ro root = LABEL =/

[Linux-bzImage, setup = 0x1e00, size = 0x1c31d4]

Grub> initrd/initrd-2.6.18-164.el5.img

[Linux-initrd @ 0x10c64000, 0x27b258 bytes]

28. System Startup

When linux is started

Load the vmlinuz * kernel file, and then load the initrd * memory disk file

Logout: logout

Shutdown now: shutdown-h now

Shutdown in 5 minutes: shutdown + 5

Shutdown at: shutdown

Immediately shut down the system and restart: shutdown-r now

Restart at: shutdown-r

Reboot can be used independently to restart the system or add parameters.

-F parameter: Shut down the system and restart the computer without running the program normally.

-L parameter: Disable all network interfaces before restarting

29. line breaks

Dos2unix converts "\ r \ n" to "\ n", and unixtodos converts "\ n" to "\ r \ n ".

Dos2unix and unix2dos commands are easy to use in the format of dos2unix filename.

30. Image Creation:

Dd if =/dev/zero of =./win2003.img bs = 1 count = 0 seek = 50G

31. format the date

[Root @ localhost rc5.d] # date + % Y/% m/% d

[Root @ localhost rc5.d] # date + % H: % M

10: 31

Display the calendar table of a specified year or month

Cal [month] [year]

One-click installation of ssh commands

Ssh-keygen-t dsa-p'-f ~ /. Ssh/id_dsa

32. Automatic Start

[Root @ expedia-cloud ~] # Chkconfig -- list vncserver
Vncserver 0: off 1: off 2: off 3: off 4: off 5: off 6: off
[Root @ expedia-cloud ~] # Chkconfig -- level 5 vncserver on
[Root @ expedia-cloud ~] # Chkconfig -- list vncserver
Vncserver 0: off 1: off 2: off 3: off 4: off 5: on 6: off

33. Create users and user groups

Create user
Useradd hdp

Create Password

Passwd hdp

Create user group
Groupadd hadoop


Add User to user group
Gpasswd-a hdp hadoop

Or


Create a user group, and then add the user to the group.
Groupadd hadoop
Mkdir/tmp/test
Useradd-G hadoop-d/tmp/test-M hdp
G: User's Group d: Specifies the location where the user's own directory is created.
M: do not create a default home directory, that is, there is no home directory.

Chown hdp. hadoop/tmp/test ---- This indicates that the owner of/tmp/test is hdp

Chmod 750/tmp/test ---- 7 indicates wrx 5 indicates rx 0 indicates no Permissions

34. Install GNOME

Yum grouplist

Yum groupinstall "GNOME Desktop Environment"

Startx

35. Copy a certain type of file under the specified directory to another directory.

Find/home/hdpusr/. ivy2/cache/-name *. jar | xargs-I {} cp-r {}/tmp/jars/

36. delete a specified folder in a directory

Find./-name. svn | xargs rm-rf

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.