Linux basic commands

Source: Internet
Author: User
Tags builtin echo display

Help commands
Man eg: man ls
Help eg: help cd
Info eg: info ls
-- Help eg: ls -- help
Command for viewing Environment Variables
Export, printenv, env, set
Command for viewing time
Date, hwclock, cal
Date: displays or sets the system clock.
-S: set the time
-D: display the time or date specified by the string.
Display time
# Date-d "$ date"
# Date "+ % y" display year
# Date '+ % y-% m-% d-% k-% M-% s' display year, month, day, hour, minute, second
# Date "+ % y" display year
# Date '+ % y-% m-% d-% k-% M-% s' display year, month, day, hour, minute, second
Set the time # date-s 2013-07-14
# Date-s 19:22:22
# Date-s "19:22:22"
Hwclock: displays the hardware clock.
# Hwclock
Set hardware time
# Hwclock -- set -- date = "13/07/14 12:05:22"
Cal: display kilometer calendar (calendar)
# Cal
Which
# Which COMMAND
Type indicates the type of the command (internal command/external command)
# Type COMMAND
File display file type
# File filename
Echo display string
# Echo $ PATH
Hash is used to display, add, and clear hash tables.
Simply put, a function compresses messages of any length to a fixed-length message digest.
# Display hash-l
Builtin (Internal Command) hash-p/usr/bin/file
Builtin hash-p/bin/chmod
Builtin hash-p/bin/date
Builtin hash-p/usr/bin/stat
Builtin hash-p/usr/bin/man
Builtin hash-p/usr/bin/info
Builtin hash-p/bin/ls
Builtin hash-p/usr/bin/clear
Directory command
Cd
Cd ~ Home Directory
Cd home directory
Cd-dirname: Enter the specified directory
Cd-switch back and forth between the previous directory and the current directory
Dirname specifies the path directory
Mkdir create directory
Rmdir Delete directory
Pwd displays the current directory
Commands related to text files
View
Cat, tac
# Attributes of cat/etc/passwd users
# Cat/etc/shadow password put the password in another file, which can only be accessed by administrators
# Cat/etc/group attributes
# Cat/etc/gshadow group password
More/less
More: Allows forward turning before turning to the end of the file
Less forward flip
Head/tail
N (first 10 by default) rows before the head File
Tail ~ After
-N #-n 20
-#-20
Create
Nano
Ctrl + o save
Ctrl + x exit
Touch
Modify file Timestamp
Access time-
Modify modification time-m
-T specifies the time format [cc] yymmddhhmm. ss
Stat file
Display file Property Information
Access time
Modify
Change
Edit
Nano
Vim
Copy
Cp src (source )... DEST (target directory)
-R recursive Replication
-A-r comprehensive, archive
-V process
-I interactive Replication
Mobile
Mv
Delete
Rm
-R Step-by-Step Deletion
-I reminder
-F force Delete
Command alias
Alias command = command
# Alias cls = clear
Wildcard
Bash supports file configuration, globbing
* Any character of any length
? Any single character
[] Any single character in the specified range [a-z]
[^] Single character out of the specified range [^ 0-9]
Add User
Useradd, adduser
# Useradd USERNAME: Create a group with the same name, home directory, and private group for the user when creating the user
-U UID, valid range: 0-65535
-G GID; valid range: Existing GID
-C Annotation
-D/path/to/somewhere
-S/path/to/shell_command switch to the shell command
-R: Create a system user between ID-1 and 499 (although the Home Directory of the System user has a path, it does not actually create a directory for him)
-M does not create a home directory for the user
-M must create a home directory for the user
Conversion user
Su (switch user)
Su USERNAME
Su-l USERNAME = su-USERNAME

View the user id
Id USERNAME
-U
-G
-N (name)
-Un
-Gn

Create group:
Groupadd USERNAME
/Etc/group
Group Name: Password placeholder, GID, which is a list of users in this additional group. Users are separated by commas (,).
-Create a group for g GID
-R: Create a system group
Modify user attributes
Usermod
-U
-G: change the basic group.
-G additional group and-a use-a (append) to retain the original additional group, add additional group
-S shell
-L modify the logon name of a user
-M-d/path/to/sommewhere: Modify the new home directory for the user, and move the users in the original home directory together.
Groupmod
-G GID
-N NEW_NAME
Password Management
Passwd: change your password
Passwd
-L lock the user account
-U unlock
Modification of key attributes
Passwd
-E: Set the expiration time.
-N: set the minimum number of days for Password Use.
-X: set the maximum number of days to use.
-W warning days
-I: inactive duration
Chage
-D. Last password modification time
-M -- mindays MIN_DAYS: minimum service life
-M -- maxdays MAX_DAYS maximum service life
-W -- warndays WARN_DAYS warning days
-I -- inactive days
-E -- expiredate expiration time
Usermod
-E: Specifies the Account expiration time.
-I keep up with the number of days: indicates the number of days not active
Set the password for the gpasswd Group
Newgrp GROUP temporarily sets the specified GROUP as its basic GROUP

Change File Permissions
Chmod change mode
Chmod [Option] Permission File
Permission definition method
1. Modify permissions of three types of users by using an octal number.
2. modify the permissions of some or some class users: u, g, o
U = rw
U =, g =
Ug =
3. operate only one or more permissions of a user: u, g, o,
+ /-
U + w
+ X
-X
G-rw (delete the read and write permissions of the owner)
Option
-R: recursively Modify permissions
-- Reference =/path/to/somefile FILE
Modify the owner and group of a file
Chown [Option] User File
Chgrp [Option] group file
Option
-R: recursively Modify permissions
-- Reference =/path/to/somefile FILE
Delete A User:
Userdel
Userdel [options] USERNAME
-R
Delete Group
Groupdel
Groupdel kgname
Bash shortcut
Ctrl + a jump to the beginning of the command line
Ctrl + e tail
Ctrl + u Delete the content from the beginning of the command line to the cursor location
Ctrl + k delete all contents from the current cursor to the command line
Ctrl + l clear screen, equivalent to the clear command
Ctrl + c cancel or terminate
Ctrl + z send the current command to the background
Cut: Text Cutting
The most common function is to use the specified symbol as the delimiter of the content in the row. Each row is sliced and only some slices are taken.
Cut [options] FILE
-D: The default Delimiter is blank. Generally, the separator ":" is added to the backend and "-d:" is used:
-F 1-5 (first-fifth) (first and fifth)
Join: concatenates rows with the same column content in two files.
Parameters:
-A <1 or 2> not only displays the original output content, but also displays rows without the same column in the command file.
-E <string> If the specified field is not found in [file 1] and [file 2], enter the string in the options in the output.
-I or -- igore-case when comparing the content of a column, case sensitivity is ignored.
-O <format> displays results in the specified format.
-T <character> use column-separated characters.
-V <1 or 2> is the same as-a, but only the rows without the same column in the file are displayed.
-1 <field> connects to the specified field in [file 1.
-2 <field> connect to the specified field in [file 2.
-- Help: displays help.
-- Version: displays the version information.
Grep
Global serach regular exmpression and printing use regular expressions to describe Selection Conditions
A regular expression is a pattern written by a type of characters)
Metacharacters :(*,?) It does not represent the meaning of the character, but is used for additional functional descriptions.
Grep [options] 'pattern' file
Regular Expression: Basic regular expression, extended Regular Expression
Basic Regular Expression: greedy mode (de matches the content in the matching mode as long as possible)
^: Specifies the qualified content at the beginning of the line. Format: "^ pattern"
$: Specifies the conforming content at the end of the anchor line. Format: "pattern $"
^ Pattern $ self-contained row
^ $ Blank line
.: Match any single character
*: The character on the front can be matched only when it is closest to the nearest character.
A * B: AB, aab, and B match
Acb Mismatch
. *: Match any character of any length
[]: Match any character in the specified range
[^]: Match any character out of the specified range
[0-9]: All numbers
[A-z]: All lowercase letters
[A-Z]: all uppercase letters
[A-zA-Z]: All letters
[0-9a-zA-Z]: All numbers and letters
Grep options
-- Color = auto
-V: reverse selection. Only rows that do not conform to the mode are displayed.
-O: only the strings matched by the pattern are displayed, but not the entire row.
-A # row number: displays the matched row, followed by the # Line
-B #: the first line #
-C #: front and back #

Sort: Sorting
-F ignore uppercase and lowercase characters
-N is sorted by numerical values.
-R in descending order
-U: removes duplicate rows. Only one row with the same content is retained.
-R random sorting
Uniq: No repeated rows after sorting is completed
-C: count the number of duplicates in each row
-U; only show rows with no duplicates
-D: only show repeated rows

Linux Command cd

Cat for Linux commands

Linux Command alias/unalias

Linux Command Parsing: su root and su-root

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.