Linux Common commands

Source: Internet
Author: User
Tags bz2 clear screen time interval

Linux distribution: Ubuntu (Desktop version very good), CentOS (free), Redhat (charge, command line very good), won the Kirin, Red Flag (closed)
--------------------------------------------------------------------------------------------------
The Vim editor is generally used to edit files under Linux.
Vim can either view files or edit files.
Three modes: command line, insert, bottom row mode.
Switch to command-line mode: Press the ESC key;
Switch to insert mode: Press I, O, a key;
I inserted at the current position
I Insert at the beginning of the current
A is inserted after the current position
A inserts at the end of the current line
o Insert a row after the current line
O insert a row before the current line

Toggle to the bottom line mode: press: (colon);

Open files: Vim file
Exit: Esc:q
Modify FILE: Enter I into insert mode
Save and exit: Esc:wq

Do not save exit: esc:q!

Enter insert mode in 3:
I: Insert at current cursor location
O: Insert the next line in the row where the current cursor is located
A: Insert at the next character where the cursor is located

Shortcut keys:
dd– quickly delete a row
R – Replacement

--------------------------------------------------------------------------------------------------
> REDIRECT output, overwrite the original content;
>> redirect output, and additional functions;
Example:
CAT/ETC/PASSWD > A.txt Directing output to A.txt
CAT/ETC/PASSWD >> a.txt Output and append

Ifconfig > Ifconfig.txt
--------------------------------------------------------------------------------------------------
Pipelines are an important concept in Linux commands that use the output of one command as input to another command.
Example
LS--help | More paging query Help information
Ps–ef | grep Java query name contains Java in the process

Ifconfig | More
Cat Index.html | More
Ps–ef | grep AIO Search for AIO-related processes
--------------------------------------------------------------------------------------------------
Use && connections between commands to implement logic and functionality.

Only the command on the left of && returns True (command return value $?). = = 0),&& to the right of the command will be executed.

As long as there is a command return False (command return value $?) = = 1), the subsequent command will not be executed.

mkdir Test && CD test create test directory and enter this directory
--------------------------------------------------------------------------------------------------
Ifconfig display or set up network devices.
Ifconfig Display Network devices
Ifconfig eth0 up enable eth0 NIC
Ifconfig eth0 down disable eth0 nic
Ping detects whether the network is unobstructed.
Ping 192.168.0.1
Netstat view the network ports.
Netstat-an | grep 3306 Query 3306 port occupancy
--------------------------------------------------------------------------------------------------
System administration Commands
Date Displays or sets the system time
Date Displays the current system time
Date-s "2014-01-01 10:10:10" set the system time
DF Display disk Information
Df–h Friendly display size
Free Show Memory status
Free–m display memory Group in MB units head
Top display, managing programs in execution

Clear Clear Screen

Status of a process in which PS is running
PS–EF View All Processes
PS-FU Search Application
Ps–ef | grep SSH finds a process
Kill kills a process
Kill 2868 kills 2868 numbered processes
Kill-9 2868 forced Kill process

Du displays the size of the directory or file.
Du–h shows the size of the current directory

WHO displays user information currently logged into the system.

Hostname View current host name
Modified: Vi/etc/sysconfig/network

UNAME displays system information.
UNAME-A displays native details.
In order: Kernel name (category), hostname, kernel version number, kernel version, kernel compile date, hardware name, processor type, hardware platform type, operating system name
--------------------------------------------------------------------------------------------------
1.5.1 Management of users
Useradd Adding a user
Useradd Test Add test user
Useradd test-d/home/t1 Specify user home directory

passwd setting, changing password
passwd test sets the password for the test user

Switch Login:
Ssh-l test-p 22 192.168.19.128 switch to test user

su– User name Switch user

Userdel Delete a user
Userdel Test Delete test user (does not delete home directory)
Userdel–r Test Delete user and home directory
1.5.2 Group Management:
When you create a new user, if you do not specify the group to which he belongs, create a private group with the same name as the user

You can also specify a group when you create a user

Groupadd creating groups
Groupadd Public Create a group named public
Useradd u1–g Public Create user U1 specify group public
Groupdel Delete a group, if the group has a user member, you must remove the user before you can delete the group.
Groupdel Public
ID to view the current user group
--------------------------------------------------------------------------------------------------
"ID Command"
Function: View the UID and GID of a user
Usage: ID [options] ... [User Name]


Use ID directly
Direct use of ID user name
"Su Command"
Function: Switch user.
Usage: su [options] ... [-] [user [parameters] ...]
Example:
Su U1 switch to U1 user
SU-U1 switch to U1 user, and also switch the environment to U1 User's environment (recommended)

"Account File"
/etc/passwd User Files
/etc/shadow Password file
/etc/group Group Information file
"User Files"
Root:x:0:0:root:/root:/bin/bash
Account name: Unique in the system
User password: This field holds the encrypted password
User id: It is used inside the system to mark the user
Group ID: Used internally by the system to identify user attributes
User-related information: such as user's full name, etc.
User directory: The directory that the user enters after logging in to the system
User environment: The environment in which the user works
"Password File"
Each record in the shadow file consists of 9 fields with a colon interval.
User name: The name used when the user logs on to the system, and is unique
Password: Store encrypted password
Last modified: Identifies the last modification time from one time to the user
Maximum time interval: The maximum number of days the password remains valid, that is, the password must be changed after a few days
Minimum time interval: the minimum number of days between password changes
Warning Time: Number of days from system start warning to official password expiration
Inactivity Time: The password expires a few days later, the account is disabled
Expiry time: The absolute number of days to indicate that the password has expired (calculated from January 1, 1970)
Flag: Not used

"Group Files"
root:x:0:
Group name: Group to which the user belongs
Group password: generally not used
GID: Group ID
User list: All users who belong to this group
--------------------------------------------------------------------------------------------------
Permissions

Owner (group) other users
Rwxrwxrwx
421421421

1.6.2Linux of three file types:
Normal files: Include text files, data files, executable binaries, and so on.

Catalog files: The Linux system sees the directory as a special kind of file, which makes up the tree structure of the file system.

Device files: The Linux system sees every device as a file
1.6.3 File type identification
Normal file (-)
directory (d)
Symbolic link (l)
* Enter etc can be viewed, equivalent to shortcut
character device file (c)
Block device file (s)
socket (s)
named pipe (p)
1.6.4 File Rights Management:
chmod Change permissions for a file or directory.
chmod 755 a.txt
chmod u=rwx,g=rx,o=rx a.txt
chmod a.txt/chmod 777 a.txt
Chown change file or directory to the user and group to which the file belongs
Chow N u1:public a.txt: Change the owning user and group of the current directory or file
chown-r u1:public dir: Change all subdirectories in the directory and the users and groups to which the files belong
--------------------------- -----------------------------------------------------------------------
------------------------------------ --------------------------------------------------------------

CD app switch to app directory
Cd.. Switch to the previous level directory
CD/switch to the system root directory
CD ~ Switch to user home directory
CD-Switch to the previous directory
CD enter switch to user home directory
--------------------------------------------------------------------------------------------------
ls command (format: ls[parameter] [path or file name])
* ls
* Ls-a Show All files or directories (including hidden files)
* Ls-l abbreviated to LL show in another style
Ll-h Friendly display file size
--------------------------------------------------------------------------------------------------
mkdir command (mkdir [-p][directory name])
mkdir app? Create an app directory under the current directory
Mkdir–p app2/test? Cascade create AAP2 and test

rmdir command (rmdir [-p][directory ...]) The command can be used to delete the "empty" subdirectory:
RmDir app? Delete App Directory

--------------------------------------------------------------------------------------------------
Cat command
Used to display the contents of a file.
Format: cat[parameter]< file name >

* Cat Textfile1 is displayed on the screen
* Cat-n textfile1 > Textfile2 Add the file contents of Textfile1 and enter the Textfile2 file, N displays the number of rows


More commands
Generally used to display more than a picture length of the case. Press SPACEBAR to display the next screen.
Enter to display the next line of content.
Press the Q key to exit the view.
* More yum.conf
* Space Display next page data return to display the next row of data

Less command
The usage is similar to more, the difference is that less can be controlled by PgUp, PgDn keys.
* Less yum.conf
* PgUp and PgDn to page up and down.

Tail command
The tail command is used in the actual use of a very many commands, its function is: used to display the file after a few lines of content.
Usage:
TAIL-10/ETC/PASSWD? View the following 10 rows of data
Tail-f Catalina.log? Dynamic View Log (* * * * *)


CTRL + C End View
--------------------------------------------------------------------------------------------------
RM command
Usage: RM [options] ... File...
RM a.txt? Delete a.txt file
Delete requires user confirmation, y/n
RM Delete Does not ask
Rm-f a.txt? -F or--force forces the deletion of files or directories without asking.
RM Delete Directory
Rm-r a? Recursive deletion
Do not ask for recursive deletion (use caution)
RM-RF a? Do not ask for recursive deletions
RM-RF *? Delete all Files
RM-RF/*? Suicide (disabled)


CP command cp[source file or directory [destination file or directory]

The CP (copy) command allows you to copy files from one place to another. Typically when you use the CP command to copy a file to another file or to a directory, you need to specify the source file name and the destination file name or directory.
CP a.txt B.txt? Copy a.txt to B.txt file
CP A.txt. / ? Copy the A.txt file to the previous level directory


MV command MV [source file or directory] [destination file or directory]

MV Move or rename
MV A.txt. / ? Move the A.txt file to the previous level directory
MV a.txt b.txt? Rename the A.txt file to B.txt

--------------------------------------------------------------------------------------------------
"grep" command

grep [-abcefghhillnqrsvvwxy][-a< Displays the number of columns >][-B< displays the number of columns >][file or directory ...]

Finds a string that matches a condition.
Usage: grep [options] ... PATTERN [FILE] ...
Example:
grep lang anaconda-ks.cfg find lang in a file
grep Lang Anaconda-ks.cfg–color highlighting

Highlight and display the first two lines and the last two lines
grep Xie A.txt-a2-b2--color

--------------------------------------------------------------------------------------------------
"PWD"
Show current directory
"Touch"
Create an empty file
* Touch A.txt
"Wget"
Download Information
* Wget http://nginx.org/download/nginx-1.9.12.tar.gz
--------------------------------------------------------------------------------------------------

Package Unpacking
TAR-CVF Xx.tar XX
TAR-XVF Xx.tar [-C D]
tar.gz Compression Decompression
TAR-ZCVF xx.tar.gz XX
TAR-ZXVF xx.tar.gz [-C D]
TAR.BZ2 Compression Decompression
TAR-JCVF xx.tar.bz2 XX
TAR-JXVF xx.tar.bz2 [-C D]

-Z: With gzip properties
-j: With the bz2 attribute

-C: Create compressed archives
-X: Unzip

-V: Show All procedures

-F: Use the file name, remember that this parameter is the last parameter, can only be followed by the file name.


Unzip Xxx.zip


-----------------------------------------------------
Linux Networks related to:
Ifconfig command temporarily configures IP address, reboot will fail
Ifconfig eth0 192.168.1.1 netmask 255.255.255.0
Setup tool permanently configures IP address
Service network restart required after Setup

Linux Common commands

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.