Common CentOS commands

Source: Internet
Author: User
Tags ssh port

1. View process ps-


2. Add a scheduled task crontab-e

Example: 3021 *** servicehttpdrestart

Restart apache at every day

View crontab status


3. find/

4. centos host name modification command

You need to modify either of them:/etc/sysconfig/network and/etc/hosts. modifying only one of them will cause system startup exceptions. Switch to the root user first. Vi/etc/sysconfig/network open the file with any of your favorite editors, which contains a line of HOSTNAME = localhost. modify localhost. localdomain is your host name. Vi/etc/ to open the file, there will be a line Here, is the local loop address, and localhost. localdomain is the host name (hostname), that is, what you want to modify. Localhost is the alias of the Host Name (alias). It appears at the Konsole prompt. Modify the second item to your host name. The third item is optional. After the above two files are modified, they cannot take effect immediately. If the modification takes effect immediately, you can use hostnameyour-hostname to temporarily modify the host name. After the system is restarted, the host name will be restored to its original state. However, the modification of the above two files is permanent, and the new host name will be obtained after the system is restarted. Finally, check the host name uname-n after restart.

5. View and uninstall software in centos

Rpm-qa | grepVirtualBox


I. View cpu using common CentOS commands
More/proc/cpuinfo | grep "modelname"
Grep "modelname"/proc/cpuinfo
[Root @ localhost/] # grep "CPU"/proc/cpuinfo
Modelname: Intel (R) Pentium (R) DualCPUE2180@2.00GHz
Modelname: Intel (R) Pentium (R) DualCPUE2180@2.00GHz
If you feel more comfortable to watch
Grep "modelname"/proc/cpuinfo | cut-f2-d:
Ii. view memory using common CentOS commands
GrepMemTotal/proc/meminfogrepMemTotal/proc/meminfo | cut-f2-d: 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 (32or64)
4. Use common CentOS commands to view the current linux version
5. view the kernel version using common CentOS commands

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
You can also view partitions.
The occupied space is displayed.
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 | wc-l
Yumlistinstalled | 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 | grepKEYTABLE | cut-f2-d =
10. Use common CentOS commands to view selinux Information
Sestatus | cut-f2-d:

11: Use common CentOS commands to view ip addresses and mac addresses
In the ifcfg-eth0 file you can see mac, Gateway and other information. Ifconfigcat/etc/sysconfig/network-scripts/ifcfg-eth0 | grepIPADDRcat/etc/sysconfig/network-scripts/ifcfg-eth0 | grepIPADDR | cut-f2-d = ifconfigeth0 | grep "inetaddr: "| awk '{print $2}' | cut-c6-ifconfig | grep 'inetaddr: '| grep-V' 127. 0.0.1 '| cut-d:-f2 | awk' {print $1} 'view gateway cat/etc/sysconfig/network view dnscat/etc/resolv. conf 12: Use common CentOS commands to view the default language
12: Use common CentOS commands to check the time zone and whether UTC time is used
Thirteen: Use common CentOS commands to view the Host Name
Modifying the host name is to modify this file, and it is recommended that you also modify the host file.
14. Run common CentOS commands to view the startup time
09: 44: 45up67days, 23:32 ,...
It seems that this is indeed a problem with the network segment. I started the machine 67 days ago.
# System resource usage
Vmstat1-Smprocs ----------- memory ------------- swap ------- io ------ system ------- cpu ------ memory

Among the many Linux terminal commands, we should introduce them by category. Here we will first talk about the file directory class, driver mounting class, program installation class, compression and decompression class, and process control class, all Linux terminal commands are frequently used here. It should be much easier to get familiar with these commands.
I. File directory
1. Create a directory: mkdir directory name
2. Delete the empty directory: rmdir directory name
3. Delete the subdirectory unconditionally: rm-rf directory name
4. Change the current directory: cd directory name (go to the user's home directory: cd ~; Go to the upper-level Directory: cd -)
5. view your own directory: pwd
6. view the current directory size: du
7. display the directory file list: ls-l (-a: add an implicit directory)
Blue: Directory; Green: executable file; Red: compressed file; light blue: linked file; Gray: other files; Red: Wrong link file
8. Browse File: morefile name .txt;lessfile name. txt
9. copy the file: the target file of the cp source file (-r: Contains directory)
10. find the file: (1) find (2) locate command name
11. Link: (1) create a hard link: ln to link the source file (-d: create a directory link); (2) create a symbolic link: ln-s to link the source file

Ii. Driver mounting
1. Check hard disk usage: df-T-h
2. Check the disk partition: fdisk-l
3. mount the hardware and software areas: mount-t/dev/fdx | hdax/mnt/directory name
Among them: modos -- FAT16; vfat -- FAT32; ntfs -- NTFS; optical drive -- iso9660
Supported Chinese names: mount-oiocharset = x/dev/hdax/mnt/directory name (where: x = cp936 or
Mount the optical drive: mount-tauto/dev/cdrom/mnt/cdrom
Mounting ISO files: mount-tiso9660-oloopxxx.iso/path
4. unmount: umount/mnt/directory name
Unmount all: umount-
5. Create a file system: mkfs-t/dev/hdxx. Ftype: ext2, ext3, and swap

Iii. Program Installation
1. RPM package installation :( 1) install rpm-ivhsomesoft.rpm
(2) reverse installation of rpm-esomefost.rpm
(3) query rpm-qsomefost or rpm-qpisomefost.rpm (where: p is not installed; I contains information)
(4) query after installation location: rpm-qlsomefost.rpm
(5) upgrade installation: rpm-Uvhsomesoft.rpm
(6) force installation: rpm-ivh -- nodepssomesoft. rpm or rpm-ivh -- nodeps -- forcesomesoft. rpm
2. Install the source code package:
Basic usage (1) configuration: extract the directory./configure
(2) Compile: extract the make
(3) install makeinstall in the decompressed directory
3. Install src. rpm

Iv. compression and decompression
1.tar.gz class: (1) decompress: tar-xvzffile .tar.gz((2)tar.gz to tar: gzip-dfile .tar.gz (2) Compressed: gzip file to be compressed
2.tar uncompressed class: (1) Unpack: tar-xvf file .tar; (2) package: tar-cvf file .tar file list (1) unzipfile. Zip-ddir; (2) Compressed: zipzipfile list of files to be compressed
4.bz2: (1) decompress: bunzip2 file .bz2or bzip2-dfile .bz2; (2) compress: bzip2 File to be compressed
5. z class: (1) decompress: uncompress file. z; (2) compress: compress File

5. Process Control
1. List the current process ID: ps-auxw
2. terminate processes: (1) terminate a single process: kill process ID
(2) terminate all processes of the program: Killall program name
(3) Terminate the X-Window program: xkill
3. View resource usage: (1) top (2) free (3) dmesg
4. view the environment variable value: env
5. Restart: (1) reboot (2) CtrlAltDel (3) init6
6. shutdown: (1) shutdown-hnow (2) halt (3) init0
7. Switch the desktop: switchdeskgnome | KDE |...
Next we will introduce program running, user account, vi editing, network services, and other Linux terminal commands.

In order to allow other new users like me to get started faster and not afraid of "commands", we will sort out the following frequently used commands for reference:

(The following experiences mainly come from Ubuntu, RedHat, and CentOS. If there is any inconsistency in other Linux versions, please leave a message to correct them)

--------------- Directory -----------------

1. ifconfig-IP View Management command

2. Run the man command and the -- help parameter to view the Command help document.

3. cd directory switch command

4. ls and ll (ls-l) browse directories and file commands

5. find resource search command

6. sudo and su use the root account permission command

7. passwd password modification command

8. apt-get and yum software installation and uninstallation commands

9. service Management and ps process viewing commands

10. chkconfig service management commands (not included in the system, need to be installed separately)

11. vi text editing tool

12. chmod file and directory permission management commands

13. Copy, move (rename), and delete commands for cp, mv, rm files and directories

14. scp remote Copy command

15. wget Remote resource access and download commands

16. ssh remote logon command

------------------ Details of this article --------------------

1. ifconfig-IP View Management command

Put the IP View Management command in the first introduction,

It is because you know the IP address of the installed linux system that you can log on to the system through remote ssh for learning and management.

You can enter "ifconfig" or "ifconfig-a" to view the system IP address and press Enter.

Note that it is not ipconfig in windows, but ifconfig!

For more information, see "how to view the local IP address in Linux" and "how to modify the configuration file in Ubuntu to set the static IP Address".

NOTE: If CentOs is used, the/sbin PATH is not added to the environment variable $ PATH by default. To view the value of this environment variable, run echo $ PATH ),

You can enter the absolute path of the command to execute it, that is, "/sbin/ifconfig ".

Other commands are as follows.

2. Run the man command and the -- help parameter to view the Command help document.

Before proceeding, I would like to introduce a very useful command and parameter, which is used to view the help documentation of the command.

If you want to see the detailed parameters of the ls command and how to use them,

Enter "ls -- help" or "manls" and press Enter,

The system will print out all the use instructions related to ls.

Almost all commands can use the -- help parameter, or use the man command to view their usage methods.

Note: When the man command is used to view the help document of a command, exit the help document and enter the letter "q.

3. cd directory switch command

Like cd in windows's doscommand, cd is used to switch the current directory.

Usage example:

After logging on to linux, it will be in the user directory of the current user by default. If the user name is user, the absolute path of the directory will be "/home/user /";

If you want to switch to the/etc directory, enter the command "cd/etc" and press Enter.

4. ls and ll (ls-l) browse directories and file commands

Compared with the dir command in windows, it is not difficult to understand its usage.

It must be noted that there are no ll (two lower-case L) commands in Ubuntu, but they can be replaced by the ls-l command.

5. find resource search command

Find is equivalent to the file search function opened by the Ctrl + F shortcut in windows.

If you want to find a file test.html in the entire folder,

Input: "find/-nametest.html"

Wildcards can be used in the searched file name, for example, "find/-name *. html".

6. sudo and su use the root account permission command

Generally, the root account is not used,

Because it is the highest privilege user in linux, a slight carelessness may cause serious consequences.

Occasionally, some operations require temporary use of the root account permission. What should I do?

You can add sudo to the command. For example, use the root account to open an apache configuration file: sudovi/etc/httpd/conf/httpd. conf.

The first time you use sudo, you will be prompted to enter the current user's password. If you use sudo for a while, you do not need to enter the password again.

In addition to using sudo, you can also use the User Switching command: su to switch to the root account,

Enter the command "su" or "suroot". Press enter and enter the password of the root account as prompted.

7. passwd password modification command

In Ubuntu, after the system is installed, the password of the root account is usually not set,

To use the root account for the first time, you must set a password for the root account.

Run "sudopasswdroot" and press Enter,

The system will prompt you to enter the new password of the root account twice. Repeat the password twice.

You can use the new password to log on to the root account.

Related Articles: Setting the root account password after Ubuntu Installation

8. apt-get and yum software installation and uninstallation commands

New software is required when you are new to linux or a newly installed linux system.

A great charm of linux is that most of the open-source software you want to use,

Both Ubuntu and CentOs collect these open source software together,

It also provides a software management tool to help users easily download, install and configure the software.

The tool provided by Ubuntu is apt-get, while CentOs (RedHat) provides yum.

This section only describes how to use them to install a software,

If you install apache2, enter the command: "sudoapt-getinstallapache2" or "sudoyuminstallapache2"

Related Articles: Install the php extension library mcrypt, curl, AND gd in Ubuntu

9. service Startup stop management and ps process view commands

Linux also has the same concept of "service" as windows:

A software automatically runs on the background after the system is started. This software can be called a "service".

In linux, the command used to manage services is "service". Generally, services support three parameters (start, stop, and restart): "start", "stop", and "restart".

If you restart the apache2 service, enter "sudoserviceapache2restart".

Generally, "ps-ef" is used to view all processes currently;

To filter out the process name, add the grep command: "ps-ef | grephttp"

10. chkconfig service management commands (not included in the system, need to be installed separately)

The Service Management here is different from the above service start, stop, and restart management,

The preceding service commands can be regarded as the startup, stop, and restart management of a software,

While chkconfig manages the service itself, such as setting a service to run automatically upon startup, or setting a service to run without startup, or even delete it from the service.

This tool can be installed through "sudoapt-getinstallchkconfig" or "yuminstallchkconfig.

For example, in CentOs, set apache2 to boot automatically: "chkconfig -- level2345httpd>
Note: The service name of apache2 may not be apache2, but httpd.

Command: chkconfig -- list to view all services

Related Articles: CentOS: Building an apache + mysql + php environment and configuring a virtual directory for apache

11. vim text editing tool

Vi (vim) can be seen as a notepad software similar to windows. It is a plain text editor, but its function is far more powerful than notepad.

Vim is too powerful. Here we will only introduce its basic usage:

Open a file test.html with example, and enter "Export vitest.html",

The following parameters can be the absolute or relative paths of one or more files (For details, refer to this article: VI commands for opening and editing multiple files ).

In vim, enter the letter "I" to enter the editing mode. I indicates insert;

Press Esc in edit mode to exit edit mode;

The letters "H", "J", "K", and "L" respectively indicate that the cursor is "Left", "up", "down", and "right;

Enter the colon character ":", that is, press "shift + semicolon;" to enter the command mode;

In command mode, enter "w" and press enter to save the file;

In command mode, enter "x" and press enter to save the file and exit vim;

In command mode, enter "q" and press enter, or press Shift + Z + Q to save the file and exit vim;

For other common operations, see vim related documents.

Related Articles: vim simple settings in linux and vim color scheme colorscheme settings

Vim common folding operations and settings automatic saving and folding view, vi save and edit session and operation record information

12. chmod file and directory permission management commands

In linux, file permissions include read, write, and execution, which correspond to "r", "w", and "x" respectively ";

For example, to add execution permissions to a script file test. sh, enter "chmod + xtest. sh"

The plus sign "+" indicates that this permission is added, and the minus sign "-" indicates that this permission is removed.

If you want to set the directory test and all the files in it to read/write and execute by anyone,

Enter the command: chmod-R777test"

Here, the read r value is 4, the write w value is 2, and the execution x value is 1.

13. Copy, move (rename), and delete commands for cp, mv, rm files and directories

Copy a file or directory command: cp. for example, if test.htmlis copied to test2.html, enter export cptest.htmltest2.html ";

Command for moving files or directories: mv, for example, to move test.html to the upper-level directory, input: Export mvtest.html ../";

Command for deleting a file or directory: rm. for example, to delete the file test.html, enter "Export rmtest.html ";

If the preceding three operations are for directories, add the-R parameter.

14. scp remote Copy command

It is often used to copy a file from one linux server to another,

Using the scp remote Copy command is very convenient and convenient.

For example, copy the test.html file of the local machine to the/usr/test directory of the machine whose IP address is,

You can enter: Export scptest.html root@", and then press enter,

Enter the password of the root account on the machine 102 as prompted.

15. wget Remote resource access and download commands

If you download a file from the web to your local machine,

You can enter "wgethttp: //", and then go back to the car to confirm,

Upload the qq.exefile to the current directory named qq.exe.

16. ssh remote logon command

If you remotely log on to another server through ssh from a linux server,

This situation is usually used when multiple servers are used.

Because a firewall is often set up for the server and cannot directly access a server on the internet,

To be accessible, you must first connect to a machine outside the firewall and then connect to the server in the firewall.

If you use the root account to connect to a machine with the IP address, enter "ssh192.168.1.102-lroot ",

Enter the password of the root account and then press enter to confirm.

If the ssh port of the server is not the default port 22 and is a custom port 1234, you can add the parameter-p after the command,

For example: "ssh192.168.1.102-lroot-p1234"

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: 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.