Common CentOS Commands

Source: Internet
Author: User
Tags i18n nameserver dmesg

1. View system usage port and release port

[Email protected]_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)

[[Email protected]_nn_01 web-inf]# kill-9 24065

2. Display the list of files in kb/mb form

[Email protected] iso]# LS-LH

Total 5.8G

-rw-r--r--1 root root 4.1G 2011-08-01 Centos-5.5-x86_64-bin-dvd-1of2.iso

-rw-r--r--1 root root 413M 2011-08-01 Centos-5.5-x86_64-bin-dvd-2of2.iso

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

-rw-r--r--1 root root 618M 2010-09-08 windows.server.2003.r2.with.sp2 x64.iso

3. View the number of CPU bits (+ or 64)

[Email protected]_test download]# getconf long_bit

64

4. View the current version of Linux

[Email protected] ~]# cat/etc/redhat-release

CentOS Release 5.4 (Final)

5. uname for viewing system Information

[Email protected] ~]# uname-r #打印发布的内核

2.6.18-164.el5xen

# uname-a # View kernel/Os/cpu information

[Email protected]_test download]# uname-a

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

6. View the system default language

Echo $LANG $LANGUAGE

cat/etc/sysconfig/i18n

7. Check your time zone and whether you use UTC time

[Email protected] ~]# 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 Host Name

Hostname

Cat/etc/sysconfig/network

Modify the hostname is to modify this file, and preferably also the/etc/hosts file also modified

9. Check the start-up run time

[Email protected] ~]# uptime

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

10. Viewing the operating system version

[Email protected]_test download]# head-n 1/etc/issue

CentOS Release 5.5 (Final)

# cat/proc/cpuinfo # View CPU Information

# hostname # View computer name

# LSPCI-TV # list all PCI devices

# LSUSB-TV # list all USB devices

[Email protected]_test download]# Lsusb-tv

bus# 1

'-dev# 1 Vendor 0x0000 Product 0x0000

'-dev# 2 Vendor 0x0627 Product 0x0001

# lsmod # List of loaded kernel modules

# env # View environment variable resources

11, CPU Common view command

More/proc/cpuinfo | grep "model name"

grep "model name"/proc/cpuinfo

[[email protected]/]# grep "CPU"/proc/cpuinfo

Model Name:intel (R) Pentium (r) Dual CPU E2180 @ 2.00GHz

Model Name:intel (R) Pentium (r) Dual CPU E2180 @ 2.00GHz

If you want to display only the second column of content:

grep "model Name"/proc/cpuinfo | Cut-f2-d:

12. Common Memory View command

grep memtotal/proc/meminfo

grep Memtotal/proc/meminfo | Cut-f2-d:

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

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

13. Check the total disk size:

[Email protected] ~]# fdisk-l |grep Disk | Cut-f2-d:

498.9 GB, 498999492608 bytes

1995.9 GB, 1995997970432 bytes

When we look at the idle memory of the machine with the free command, we find that the value of the. This is mainly because, in Linux there is such a thought, the memory is not white, so it as far as possible cache and buffer some data to facilitate the next use. But in fact, the memory is also available for immediate use.

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

14, check the system installation of the package installed

Cat-n/root/install.log

More/root/install.log | Wc-l

See which packages are now installed

Rpm-qa

Rpm-qa | Wc-l

Yum List Installed | Wc-l

But strangely enough, the number of installation packages I've queried through RPM, and Yum, is not the same. No reason was found.

15. View the keyboard layout

Cat/etc/sysconfig/keyboard

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

16. View SELinux Status

Sestatus

Sestatus | Cut-f2-d:

Cat/etc/sysconfig/selinux

Turn off SELinux

1.[[email protected] ~]# vi/etc/selinux/config
# Change the bottom setting to this:
Selinux=disabled

2. Modify the grub settings at the time of the machine
[Email protected] ~]# Vi/boot/grub/menu.lst
..... Omitted.....
kernel/boot/vmlinuz-2.6.9 ro root=/dev/hda1 rhgb selinux=0
..... Omitted.....

3. Re-start the machine
[[Email protected] ~]# sync; Reboot

17. Resources

# free-m # View memory usage and swap area usage

[Email protected]_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

[Email protected]_test download]# df-h

Filesystem Size used Avail use% mounted on

/dev/hda2 55G 11G 41G 21%/

/DEV/HDA1 99M 12M 82M 13%/boot

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

# du-sh < directory name > # View the size of the specified directory

[Email protected]_test download]# du-sh

2.7G

[Email protected] ~]# Du/etc-sh

126m/etc

# grep Memtotal/proc/meminfo # View Total Memory

[[Email protected]_test download]# grep memtotal/proc/meminfo

memtotal:2512164 KB

# grep Memfree/proc/meminfo # View the amount of free memory

# uptime # View System uptime, number of users, load

[Email protected]_test download]# Uptime

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

# cat/proc/loadavg # View system load disks and partitions

[Email protected]_test download]# Cat/proc/loadavg

0.00 0.00 0.00) 1/195 19443

[Email protected] ~]# Cat/proc/meminfo

Memtotal: Total Memory

Memfree: Free Memory size

Buffers: for temporary disk caching

CACHED:I/O read-write cache, not including swapcached

Swapcached: The memory size that was swapped out but was swapped back while still remaining in Swapfile

In fact, Memfree does not represent the total amount of system memory idle, and the cache of the system for I/O should also be included in the free memory range. Memory Idle Amount:

Memfree+buffers+cached+swapcached

[Email protected] ~]# ll-h/proc/kcore

Free Memory =free+buffers+cached=total-used

[[email protected] ~]# grep memtotal/proc/meminfo

memtotal:2058016 KB

18. Disks and partitions

# Mount | COLUMN-T # Viewing the status of a mounted partition

[Email protected]_test download]# Cat/proc/loadavg

0.10 0.03 0.01) 1/195 19445

[Email protected]_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

[Email protected]_test download]# fdisk-l

disk/dev/hda:64.4 GB, 64424509440 bytes

255 heads, Sectors/track, 7832 cylinders

Units = Cylinders of 16065 * 8225280 bytes

Device Boot Start End Blocks Id System

/DEV/HDA1 * 1 104391 Linux

/dev/hda2 7309 58605120 Linux

/dev/hda3 7310 7831 4192965, Linux Swap/solaris

# swapon-s # View all swap partitions

[Email protected] ~]# swapon-s

Filename Type Size used priority

/dev/sda3 Partition 2096472 0-1

# hdparm-i/dev/hda # View disk parameters (for IDE devices only)

[Email protected] ~]# 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 IDE device detection network at startup

[Email protected] ~]# DMESG | grep IDE

Uniform Multi-Platform E-ide driver REVISION:7.00ALPHA2

Piix4:ide Controller at PCI slot 0000:00:07.1

Probing IDE interface ide0 ...

Probing IDE interface Ide1 ...

Hdc:vmware Virtual IDE CDROM Drive, ATAPI Cd/dvd-rom Drive

Probing IDE interface ide0 ...

target0:0:0:fast-40 WIDE SCSI 80.0 MB/s ST (NS, offset 127)

19. Network

# ifconfig # View the properties of all network interfaces

# iptables-l # View firewall settings

Shutting down the firewall

#service iptables Stop (temporarily closed.) The next time the system restarts, it doesn't work.)

#chkconfig iptables off. (Permanent works)

or cancel the iptables enabled option in System-config-firewall.

# route-n # View the routing table

[Email protected] ~]# 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

[Email protected] ~]# 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::: $:::* LISTEN 3769/sshd

# NETSTAT-ANTP # View all established connections

[Email protected] ~]# 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::: $:::* LISTEN 3769/sshd

# netstat-s # View the network statistics process

Ifconfig eth0 172.10.15.12

Note: IP addresses configured with ifconfig expire after the Linux system restarts

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

System-config-network command

You can set a second ip:ifconfig eth0:1 for the network card 172.10.15.13

You can also add a subnet mask after the netmask

[Email protected] ~]# Cat/etc/sysconfig/network-scripts/ifcfg-eth0 | grep ipaddr

ipaddr=172.10.15.3

[Email protected] ~]# Cat/etc/sysconfig/network-scripts/ifcfg-eth0 | grep ipaddr | Cut-f2-d=

172.10.15.3

[Email protected] ~]# ifconfig eth0 |grep "inet addr:" |awk ' {print $} ' |cut-c 6-

172.10.15.3

[Email protected] ~]# Ifconfig | grep ' inet addr: ' | Grep-v ' 127.0.0.1 ' | Cut-d:-f2 | awk ' {print '} '

172.10.15.3

192.168.122.1

20. View Gateway

[Email protected] ~]# cat/etc/sysconfig/network

Networking=yes

Networking_ipv6=no

hostname=cncloud.com.cn

gateway=172.10.15.254

21. View DNS

[Email protected] ~]# 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. Users

# w # View active Users

# ID < user name > # view specified user information

[[email protected] ~]# ID root

Uid=0 (Root) gid=0 (root) groups=0 (root), 1 (BIN), 2 (daemon), 3 (SYS), 4 (ADM), 6 (disk), ten (wheel) Context=root:system_r: Unconfined_t:systemlow-systemhigh

# last # View user log in log

[Email protected] ~]# last

Root pts/1:0.0 Thu Mar 19:04 still logged in

root:0 Thu Mar 19:02 still logged in

root:0 Thu Mar 24 19:02-19:02 (00:00)

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

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

root:0 Mon Mar 21 20:24-20:24 (00:00)

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

Wtmp begins Tue Mar 22 03:33:26 2011

# cut-d:-f1/etc/passwd # View All users of the system

# cut-d:-f1/etc/group # View all system groups

# crontab-l # View the current user's scheduled tasks service

The format of the schedule table is as follows: F1 F2 F3 f4 f5 program

Edit a file Cronfile with VI and enter a well-formed time table in this file. When the edits are complete, save and exit.

At the command line, enter

$: crontab cronfile

This submits the Cronfile file to the C R o N process, and a copy of the newly created cronfile has been placed in the/V a r/s P o o l/c R o n directory, and the file name is the user name.

When the program executes at the time you specify, the system will send you a letter showing what the program is doing, and if you do not wish to receive such a letter, please add >/dev/null 2>&1 after each line.

Useradd user1

Useradd User2

Groupadd group1

Gpasswd-a user1 group1

Adding user "User1" to the "group1" group

24. Service

# chkconfig--list # list all system services

# chkconfig--list | grep on # Lists all started system services programs

25. Procedure

# rpm-qa # View all installed Packages

26, Chinese garbled

Download Chinese Support package:

Fonts-chinese-3.02-12.el5.noarch Chinese Font pack

Fonts-iso8859-2-75dpi-1.0-17.1.noarch Font Display Package

L in the installation of "supported language" inside the hook "Chinese", you can. Note that it is different to distinguish between the languages that are used for installation and the languages that are supported.

Or

If it is already installed, you can install the Chinese font with Yum installed Fonts-chinese. In this way, Firefox, Gedit will be able to display the correct Chinese.

LOCALE-A viewing system-supported languages

vi/etc/sysconfig/i18n

Changed to Lang= "ZH_CN. UTF-8 "Restart can

27. Backup and Recovery

Restore the GRUB configuration file

Remember the GRUB configuration file structure first

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

Root (hd0,0) #表示要从系统中的第一块硬盘的第一个分区去找配置文件

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

#ro表示只读的意思

#LABEL =/means looking under the root directory

Initrd/initrd-2.6.18-164.el5.img

Delete/boot/grub/grub.conf

The system won't start.

You can use the following command at startup

grub> Root (hd0,0)

Filesystem type is EXT2FS, partition type 0x83

grub> 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, it will be in the/boot directory first

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

Logout: Logout

Immediate shutdown: Shutdown–h now

Shutdown after 5 minutes: Shutdown +5

Shutdown at 10:30: Shutdown 10:30

Shut down the system immediately and restart: Shutdown–r now

Specified at 23:59 restart: shutdown–r 23:59

Reboot can be used alone to restart the system, you can also add parameters

-F parameter: Shut down the system and restart the computer if the program is not in normal operation

-L parameter: Shut down all network interfaces before restarting

29. NewLine Characters

Dos2unix "\ r \ n" into "\ n", unixtodos the "\ n" into "\ r \ n".

Commands Dos2unix and Unix2dos are very simple to use, in the format: Dos2unix filename

30, Mirror production:

DD If=/dev/zero of=./win2003.img Bs=1 count=0 seek=50g

31. Formatted Date

[Email protected] rc5.d]# date +%y/%m/%d

2011/05/17

[Email protected] rc5.d]# date +%h:%m

10:31

Displays the calendar for the specified month

Cal [Month] [year]

One-click Install SSH command

Ssh-keygen-t Dsa-p "-F ~/.SSH/ID_DSA

32. Auto-Start

[Email protected] ~]# chkconfig--list vncserver
Vncserver 0:off 1:off 2:off 3:off 4:off 5:off 6:off
[[email protected] ~]# chkconfig--level 5 vncserver on
[Email protected] ~]# 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 a user group
Groupadd Hadoop


Add user to User group
Gpasswd-a HDP Hadoop

Or


Create user groups First, and then add the created users directly to the group
Groupadd Hadoop
Mkdir/tmp/test
Useradd-g hadoop-d/tmp/test-m HDP
G: The user's Group D: Indicates the location of the user's own directory to give the specified
M: Do not create a default home directory, which means that there is no directory

Chown hdp.hadoop/tmp/test----This means to make/tmp/test the owner of HDP

chmod 750/tmp/test----7 means WRX 5 means Rx 0 means no permissions

34. Install Gnome

Yum Grouplist

Yum groupinstall "GNOME Desktop Environment"

StartX

35. Copy one type of file from the specified directory to another directory

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

36. Delete the specified folder under a directory

Find./-name. SVN | Xargs RM-RF

Common CentOS Commands

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.