Commonly used Centos commands

Source: Internet
Author: User

Commonly used Centos commands

Common CentOS commands are frequently used in our use. Therefore, we have thoroughly organized some frequently-used and important CentOS commands. The following describes common CentOS commands.

I. View cpu using common CentOS commands

  1. More/Proc/cpuinfo|Grep"ModelName"
  2. Grep"ModelName"/Proc/cpuinfo
  3. [Root @ localhost/] #Grep"CPU"/Proc/cpuinfo
  4. ModelName:Intel (R)Pentium (R)DualCPUE2180@2.00 GHz
  5. ModelName:Intel (R)Pentium (R)DualCPUE2180@2.00 GHz

If you feel more comfortable to watch
Grep "model name"/proc/cpuinfo | cut-f2-d:

Ii. view memory using common CentOS commands

  1. GrepMemTotal/Proc/meminfo
  2. GrepMemTotal/Proc/meminfo|Cut-F2-D:
  3. Free-M| Grep"Mem"|Awk'{Print$2 }'

Iii. Use common CentOS commands to check whether the cpu is 32-bit or 64-bit
View CPU bits (32 or 64)
Getconf LONG_BIT

4. Use common CentOS commands to view the current linux version
More/etc/redhat-release
Cat/etc/redhat-release

5. view the kernel version using common CentOS commands
Uname-r
Uname-

6. Use common CentOS commands to view the current time
Date. The preceding section describes how to synchronize the time.

7. View hard disks and partitions using common CentOS commands
Df-h
Fdisk-l
You can also view partitions.
Du-sh
The occupied space is displayed.
Du/etc-sh
The directory size is displayed.

8. Use common CentOS commands to view installed software packages
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.

9. view the keyboard layout using common CentOS commands
Cat/etc/sysconfig/keyboard
Cat/etc/sysconfig/keyboard | grep KEYTABLE | cut-f2-d =

10. Use common CentOS commands to view selinux Information
Sestatus
Sestatus | cut-f2-d:
Cat/etc/sysconfig/selinux

11: Use common CentOS commands to view ip addresses and mac addresses

  1. In ifcfg-eth0You can see the mac, gateway, and other information in the file.
  2. Ifconfig
  3. Cat/Etc/sysconfig/network-scripts/ifcfg-eth0|GrepIPADDR
  4. Cat/Etc/sysconfig/network-scripts/ifcfg-eth0|GrepIPADDR|Cut-F2-D =
  5. IfconfigEth0| Grep"InetAddr :"| Awk'{Print$2} '| cut-C6-
  6. Ifconfig|Grep'InetAddr: '|Grep-V'2017. 0.0.1'|Cut-D:-F2|Awk'{Print$1 }'
  7. View Gateway
  8. Cat/Etc/sysconfig/network
  9. View dns
  10. Cat/Etc/resolv. conf

12: Use common CentOS commands to view the default language
Echo $ LANG $ LANGUAGE
Cat/etc/sysconfig/i18n

Thirteen: Use common CentOS commands to check the time zone and whether UTC time is used
Cat/etc/sysconfig/clock

14. Run common CentOS commands to 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 host file.

15th: Use common CentOS commands to view the startup time
Uptime
09:44:45 up 67 days, 23:32 ,...
It seems that this is indeed a problem with the network segment. I started the machine 67 days ago.
# System resource usage

  1. Vmstat1-SM
  2. Procs----------- Memory ------------- Swap ------- Io ------ System ------- Cpu ------
  3. RBSwpdFreeBuffCacheSiSo bi boInCsUsSyIdWaSt
  4. 00 0 233 199 778 0 04 25 1 1309600
  5. 00 0 233 199 778 0 00010298561318600
Dmidecode | more

Sixteen: Practical commands
Download resources from wget URL
Decompress the tar zxvf compressed package name
Hostname or cat/etc/sysconfig/network
How does pkill mysqld kill the mysql process?
Find/-type f-size + 100000 k-ls Query files larger than MB

17: Common commands for CentOS files
Common CentOS commands for creating/changing file systems

NO1. create a file system type
[Root @ rehat root] # umount/dev/sdb1
[Root @ rehat root] # mkfs-t ext3/dev/db1
[Root @ rehat root] # mount/dev/sdb1/practice

Common CentOS commands used to change file or folder Permissions

Chmod
NO1. set your notes to be read only by yourself.
[Root @ rehat root] # chmod go-rwx test.txt
Or
[Root @ rehat root] # chmod 700 test.txt
NO2. Modify permissions for multiple files at the same time
[Root @ rehat root] # chmod 700 test1.txt test2.txt
NO3. modify the permissions of a directory, including its subdirectories and files
[Root @ rehat root] # chmod 700-R test

Common CentOS commands used to change the file or folder owner

Chown this command can only be used by the root user
NO1. change the owner of a file
[Root @ rehat root] # chown jim: usergroup test.txt
NO2. change the owner of a directory and contain sub-Directories
[Root @ rehat root] # chown jim: usergroup-R test

Common CentOS commands for viewing text files

Cat
NO1. view the file content and add a line number before each line
[Root @ rehat root] # cat-n test.txt
NO2. view the file content and add the row number before the non-empty row
[Root @ rehat root] # cat-B test.txt
NO3. merge the content of two files
[Root @ rehat root] # cat test1.txt test2.txt> test_new.txt
NO4. complete the content of the two files and trace back to a file
[Root @ rehat root] # cat test1.txt test2.txt> test_total.txt
NO5. clear the content of a file
[Root @ rehat root] # cat/dev/null> test.txt
NO6. create a new file
[Root @ rehat root] # cat> new.txt press CTRL + C to end the input

Common commands for editing file CentOS

Vi
NO1. create a file
[Root @ rehat root] # vi newfile.txt
NO2. modify an archive file
[Root @ rehat root] # vi test.txt already exists
Two working modes of NO3. vi: Command mode and edit mode
NO4. after entering vi, it is in command mode. Press the Insrt key to enter edit mode.
Press ESC to enter the command mode. You cannot edit the command mode. You can only enter the command
NO5. Common commands in command mode
: W Save the current document
: Q: Exit vi directly.
: Wq is saved first and then exited.

18: replacing files in batches
After using svn for system migration today, we found that the initial path was wrong, and thus the source server could not be accessed. Check. svn/entries for details. It takes too long to re-migrate the data. Please replace the file directly.

For f in $ (find./-type f-name 'entries ')
Do
Sed-I "s/202 \. 68 \. 134 \. 18/202 \. 68 \. 134 \. 34/g" $ f
Done

Sed:

Sed "s/sourcestring/newstring/g" $ f

Replace sourcestring in the $ f file with newstring and output it to the terminal. S indicates replacement of search,/g indicates global.

Sed-I $ f

This parameter is directly modified in $ f.

Sed-iback $ f

Save the modified file as $ fback.

All regular expressions in sed must use a strict Escape Character \ to limit

Sed's regular expression is strict :"\/! \"\/\\\! Escape.

\ N indicates line feed

19. shell variable string operation
When mono runs in linux, apache + mod_mono sometimes needs to load the Assembly to be configured in GAC. The following is a script to complete this function.

Cd bin

For f in $ (find./-name "*. dll ")

Do

Gacutil-I $ f

Done

To uninstall these assemblies in batches from GAC, you can:

For f in $ (ls *. dll)

Do

Gacutil-u $ {f %. dll}

Done

Replace string variables with $ {f %. dll}

$ {F %. dll} indicates deleting $ f variable. dll and all subsequent content.

Related variable operations include:

$ {F ##.}.

20. view the current connection

Netstat-

21. Restart
Shutdown-r now restart the system to make the settings take effect
Shutdown-h now shutdown
Reboot restart
Power off

22. Automatic startup settings
Edit the rc. local file
# Vim/etc/rc. d/rc. local

# Du-sh # view the size of a specified directory

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

# Cat/proc/loadavg # view system load

# Iptables-L # view firewall settings
# Route-n # view the route table
# Netstat-lntp # view all listening ports
# Netstat-antp # view all established connections
# Netstat-s # view network statistics

# W # view active users
# Id # view specified user information
# Last # view User Logon logs
# 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 tasks of the current user
# Chkconfig-list # list all system services
# Chkconfig-list | grep on # list all started system services

Common ssh commands in centOS

Directory operation:
Rm-rf mydir
Cd mydir
Cd-
Cd ..
Cd ~
Mv tools tool
Ln-s tool bac
Cp-a tool/home/vpser/www

File Operations:
Rm go.tar
Find mt. cgi
Df-h

Decompress:
Tar xvf wordpress.tar
Tar-tvf myfile.tar

Tar cf toole.tar tool
Tar cfz vpser.tar.gz tool

Tar jcvf/var/bak/www.tar.bz2/var/www/
Tar xjf www.tar.bz2

Gzip-d ge.tar.gz
Unzip phpbb.zip

Download:
Wget http://soft.vpser.net/web/nginx/nginx-0.8.0.tar.gz

Http://soft.vpser.net/web/nginx/nginx-0.8.0.tar.gz wget-c

Process Management:
Ps-aux

Description of the ps command output field:
[List]
[*] USER: the USER name of the process owner.
[*] PID, process ID, which uniquely identifies a process.
[*] % CPU, percentage of CPU time and total time occupied by the process since the last refresh.
[*] % MEM, percentage of memory used by the process.
[*] VSZ, virtual memory used by the process, in K.
[*] RSS, total number of physical memory occupied by processes, in K.
[*] TTY, the terminal name related to the process.
[*] STAT, Process status, used (R-run or prepare to run; S-sleep status; I-idle; Z-frozen; D-uninterrupted sleep; w-the process does not reside on the page; T stops or tracks .) These letters.
[*] START, the process START time.
[*] TIME, total cpu time used by the process.
[*] COMMAND, the COMMAND line to be executed.
[/List]

Ps-aux | grep nginx
Killed 1234
Killall nginx

Vim operation:

Mobile class:
H/j/k/l: move one cell to the left/bottom/up/right
W: Move backward words (How many words are added before the number)
B: Move the forward word (How many words are added before the number)
E: Move backward to the end of the word
Ge: move forward to the end of the word
$: End of a row
0: Beginning of the line
Tx: Search for x in the row to the right and move it there (to the left in uppercase)
33G: Move to the 33rd rows of the file
Gg: first line of the file
G: The end of the file.
33%: 33% of the file
H/M/L: the beginning, middle, and end of the screen.
Zt/zz/zb: Move the current row to the beginning/center/Bottom of the screen

Jump:
": Return to the jump location.
CTRL-O: Jump to an older place
CTRL-I: jump to a newer place

Search:
/: Search down (add a keyword)
? : Search up (followed by a keyword)
N: The next matched record

Edit:
I: Switch to insert mode
X: Delete the current character
.: Repeat the last modification operation (same as ctrl + f in PS to execute the filter)
U: Undo operation
CTRL-R: redo
P: insert the deleted characters to the current position (put)

Exit and save:
: Q: Exit
: Q! : Do not save and exit
ZZ: Save and exit
: E! : Abandon modification and re-edit

The following command applies to and selects the http server when installing centos. apache, mysql, and php services are installed by default.

1. Start and Stop apache
Service httpd start;
Disable service httpd stop;
Service httpd restart.
Note that apche is not started by default in centos. Ii. View apache version
Method 1: run the command directly in the system to check if apache is installed in the system. If the rpm package is used for installation, check whether the rpm has been installed.
Rpm-qa | grep httpdYou can see whether apache is installed in the system. Simply enter the command and the version is displayed in apachectl-v;
Method 2: apache installed in the tar package. The method for viewing the installation and compilation of the tar package is/usr/local/apache2/bin/apachectl.-V (note that the installation path is customized). The following content is displayed:
Server version: Apache/2.2.13 (Unix)
Server built:Aug 26 2009 15:29:07
/Usr/local/apache2/bin/is the full path of apache source code installation, which is determined based on your installation location.

Iii. mysql Start and Stop
Service mysqld start; service mysqld stop.

4. View mysql version: mysql-version

5. Check whether mysql is started: netstat-Nat: If Port 3306 is the mysql port, it is started.

6. Check whether php, mysql, or apache commands are installed.
For example, rpm-q php, rpm-q mysql, and rpm-q httpd

7. The default installed apache on centos is located in/etc/httpd.
The root directory of the website is/var/www/html/. If you create a file internally, you must grant the File Permission to apache for read and write. Otherwise, the file cannot be accessed.

8. view the data storage address of mysql: Enter mysql and then enter show variables like '% dir %' to view the data.

9. Check the installation path of mysql, php, and apche: whereis mysql. Check the running program path which mysql. You can switch to another service, such as httpd (apache) and php.

10. shutdown-h now shut down shutdown-r now and restart immediately.

Common CentOS commands for file operations

Common CentOS commands for creating Directories

Mkdir
NO1. create a level-1 directory in the current path
[Root @ rehat root] # mkdir test
NO2. create a multi-level directory in the current path
[Root @ rehat root] # mkdir-p mytest/test1/test1_1
NO3. grant permissions to the newly created directory while creating the Directory
[Root @ rehat root] # mkdir-m 777 testmod
In this way, anyone has any permission for this directory.

Common commands for copying files and folders using CentOS

Cp
NO1. copy the files in the specified directory to the current directory and rename
[Root @ rehat root] # cp ~ /. Bashrc bashrc_bak
NO2. force copy the file from the specified directory to the current directory, regardless of whether the current directory contains the file
[Root @ rehat root] # cp-f ~ /. Bashrc
NO2. copy the specified directory to the current directory
[Root @ rehat root] # cp-r/root/test.
[Root @ rehat root] # cp-r/root/test /.
The two have the same effect. When copying a directory, all the last-level directories in the source path will be copied, including the directory itself.
NO3. copy files from the specified directory to the specified directory
[Root @ rehat root] # cp ~ /. Bashrc/bak/. bashrc
NO4. during replication, all the attributes of the source file are also copied. If no parameter is specified, the properties of the target file and the source file may be inconsistent.
[Root @ rehat root] # cp-~ /. Bashrc/bak/. bashrc
NO5. if two folders need to be synchronized, one file is changed and the other file is changed, but ensure that the files of both files are up-to-date.
[Root @ rehat root] # cp-u/src/. bashrc/bak_src/bashrc

Create a link file, including common CentOS commands for hard and soft links

Ln
NO1. create a shortcut similar to Windows
[Root @ rehat root] # ln-s test.txt _ slnk
NO2. if you want to back up a file with insufficient space, you can create a hard connection for the file. In this way, even if the original file is deleted
If the linked file is not deleted, it is still not deleted in the bucket.
[Root @ rehat root] # ln-l test.txt _ hlnk

Common CentOS commands for path operations

Cd pwd
NO1. display current path
[Root @ rehat root] # pwd
NO2. return the user's home directory
[Root @ rehat root] # cd
NO3. change to another path
[Root @ rehat root] # cd/etc
NO4. return to the upper-level directory
[Root @ rehat root] # cd ..
NO5. return to the root directory
[Root @ rehat root] # cd/

Common CentOS commands used to query files or folders

Find
NO1. search for all files in the current user's home directory
[Root @ rehat root] # find ~
NO2. grant the file owner in the current directory read and write permissions, and the users in the file group and other users have read permissions;
[Root @ rehat root] # find.-perm 644-exec ls-l {}\;
NO3. in order to find all common files with a length of 0 in the system and list their full paths;
[Root @ rehat root] # find/size 0-type f-exec ls-l {}\;
NO4. search for common files that were modified seven days ago in the/var/logs directory and ask them before deletion;
[Root @ rehat root] # find/var/logs-mtime + 7-type f-OK rm-I {}\;
NO5. find all files belonging to the root group in the system;
[Root @ rehat root] # find/-group root-exec ls-l {}\;
The NO6. find command will delete the admin. log file that contains the numeric suffix since the last seven days.
[Root @ rehat root] # find. -name "admin. log [0-9] [0-9] [0-9] "-atime-7-OK rm {}\;
NO7. to find and sort all directories in the current File System
[Root @ rehat root] # find.-type d | sort
NO8. to find all rmt tape devices in the system
[Root @ rehat root] # find/dev/rmt

Common CentOS commands for displaying file/folder lists

Ls/dir
NO1. display all files, including hidden files starting.
[Root @ rehat root] # ls-
NO2. display file details
[Root @ rehat root] # ls-l
NO3. display information about the current directory and all subdirectories
[Root @ rehat root] # ls-Rl
NO4. display directories in chronological order, which is useful for finding the latest file
[Root @ rehat root] # ls-tl
NO5. sort by file size
[Root @ rehat root] # ls-Sl
NO6. display the file size and sort by size
[Root @ rehat root] # ls-s-l-S

Common CentOS commands for moving or changing file/folder names

The usage of mv and cp commands is similar.
NO1. if the target file already exists, back up the original directory file before moving it.
[Root @ rehat root] # mv-B test.txt test2/
In this way, there will be two test.txt and text.txt ~ files under test2 ~
Test.txt ~ Is the hosts file. test.txt is the new file.
NO2. if the target object already exists but you do not want to overwrite it
[Root @ rehat root] # mv-f test.txt test2/
NO3. when both the source and target have the same file, if the source file matches the new object, the object will be moved; otherwise, the object will not be moved.
[Root @ rehat root] # mv-u test.txt test2/
NO4. change file name
[Root @ rehat root] # mv test.txt test2.txt
NO5. change the directory name
[Root @ rehat root] # mv/test2/test2_2 [/size]

Common commands for disk CentOS sorting

Common CentOS commands for checking disk space

Df
NO1. displays the space usage of all storage systems and the file system type s of the storage system.
[Root @ rehat root] # df-
NO2. display space usage of the specified file system
[Root @ rehat root] # df-t ext3
NO3. display the size of each storage space in a user-friendly manner
[Root @ rehat root] # df-ah
NO4. sometimes a Network File System is mounted. If you only want to view the local file system, use the following command:
[Root @ rehat root] # df-ahlT
NO5. view disk usage of a file system
[Root @ rehat root] # df-h/dev/cdrom

Common CentOS commands used to check the directory space size

Du
NO1. view the current folder size
[Root @ rehat root] # du-sh
NO2. view the size of the subfolders in the current file and file
[Root @ rehat root] # du-ch
NO3. view the file size
[Root @ rehat root] # du-h test1.txt
NO4. view the size of multiple files at the same time
[Root @ rehat root] # du-h test1.txt test2.txt

Now, we will collect a large area, a large range, a large density, and a large scratch.

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.