Linux basic commands

Source: Internet
Author: User
Tags set time stdin what date

Linux command format:

COMMAND [OPTIONS ...] [ARGUMENTS ...]

Options: One or some of the features used to enable or disable commands;

Parameters: The Action object of the command, providing data to the command;

(1) LS

Displays a list of files under the specified path

ls [OPTION] ... [DIR] ...

-A,--all: Displays all files, including hidden files;

-L: Long format

-rw-r--r--1 root root 44800 14:32 Install.log

-rw-r--r--:

Leftmost first bit: file type

-, D, L, B, C, p, s

9 bits in the back: access rights, Perm

Number: The number of times a file has been hard-linked;

Left Root: Owner of File

Right root: Group of files

44800: Size of File

14 14:32: Last modified time for a file

Install.log: File name

-H,--human-readable: unit conversion

-D: Displays the relevant properties of the directory itself, usually with-l;

-R,--reverse: Reverse Display

-R,--recursive: recursive


Example: Working with the following command occasionally

View files in the/etc directory with the largest file size: ls-lhs/etc/| Head

View the latest several files in the/etc directory: ls-lt/etc/| head


(2) CD

Switch directories

CD or CD ~: Back to the current user's home directory

CD ~username: Switch to the home directory of the specified user

CD-: Switch back and forth between the previous directory and the current directory


(3) Type : query command Types

(4) TTY: View current terminal equipment

(5) Cat: File View command

(6) which: show the program file path of the command
which [OPTION] COMMAND

--skip-alias: Disable alias display

Locates the location of the executable file in the system.

(8) PWD: Current directory

(9) Echo: Echoing command

- N: Prevents the automatic addition of newline symbols;

- e: Allow the use of escape characters;

\\n: Line break

\\t: Tab


echo "$VAR _name": Variable is replaced , double quotation mark table weak reference

Echo ' $VAR _name ': variable does not replace , strong reference


Date: Display and set time

Date

Date [OPTION] ... [+format]: Display

Format: Formatting symbols

%d

%F

%T

Date [MMDDHHMM[[CC]YY][.SS]]: Set

MM: Monthly

DD: what date

hh: Hours

mm: minutes

YY: two-digit year

CCYY: four-bit year

. SS: Seconds


Example: View yesterday time: Date +%y%m%d-d '-1 day '

(11) Shut down the machine

Halt, Poweroff, shutdown, init 0

(12) Restart

Reboot, shutdown, init 6

(13) associated with user login

Who, WhoAmI, W


History: Command Histories

Environment variables:

Histsize: The number of records in the command history;

Histfile:~/.bash_history;

Histfilesize: The Order History file records the history of the number of bars;


History-d OFFSET

-C

History #: Shows the most recent # command in the past;

-A: Manually append the current session buffer's command history to the history file;


(mkdir): Create a directory

mkdir [Options]/path/to/somewhere

-P: exists in no error, and can automatically create the required directories;

-V: Show more information

-M MODE: Specify permissions directly when creating a directory;

(+) Tree:

-D: Show only directories

-L Level: Specifies the number of levels to display

-P Pattern: Displays only the path that is matched by the specified pattern;

(+) RmDir: Delete Empty directory

rmdir [OPTION] ... DIRECTORY ...

-V: Display process;

(18) View File Class command:

More

More [OPTIONS ...] FILE ...

-D: Show page flipping and exit tips


Less

Less [OPTIONS ...] FILE ...


Head

Head [OPTION] ... [FILE] ...

-C #: Specify get before # bytes

-N #: Specifies the first # line to get

-#:


Tail

tail [OPTION] ... [FILE] ...

-C #: Specifies the # bytes after fetching

-N #: Specifies the # line after fetch

-#:

-F: Trace displays the new content of the file;


Touch: Timestamp management tool for files

Touch [OPTION] ... FILE ...

-a:only Atime

-m:only Mtime

-T STAMP:

[[Cc]yy] MMDDHHMM[.SS]

-C: If the file does not exist, it is not created

() CP Copy command

Common options:

-I: Interactive

-R,-r: recursively copy directories and all internal content;

-A: archive, equivalent to-DR--preserv=all

-d:--no-dereference--preserv=links

--preserv[=attr_list]

Mode: Permissions

ownership: Belong to the main group

Timestamp:

Links

xattr

Context

All

-P:--preserv=mode,ownership,timestamp

-V:--verbose

-F:--force

MV: Moving, renaming files or directories

MV [OPTION] ... [-T] SOURCE DEST

MV [OPTION] ... SOURCE ... DIRECTORY

MV [OPTION] ...-t DIRECTORY SOURCE ...

Common options:

-I: Interactive

-F: Mandatory

RM: Delete command

RM [OPTION] ... FILE ...


Common options:

-I: Interactive

-F: Force delete

-R: Recursive


RM-RF

WC command: See how many lines or words are in the contents of a file

WC [OPTION] ... [FILE] ...

-l:lines

-w:words

-c:characters

Cut command: Cut file

Cut [OPTION] ... [FILE] ...

-D DELIMITER: Indicates delimiter

-F Fileds:

#: Section # Fields

#,#[,#]: Discrete multiple fields, such as 1,3,6

#-#: Multiple consecutive fields, such as 1-6


Mixed use: 1-3,7

--output-delimiter=string

Sort command: Text content sorting

Sort [OPTION] ... [FILE] ...

-F: Ignore character case

-R: Reverse order

-T DELIMITER: Field delimiter

-K #: Sort the specified fields as standard

-N: Sorting by numeric size

-u:uniq, sort after go heavy


(+) Uniq command: File content to go heavy

Uniq [OPTION] ... [FILE] ...

-C: Shows the number of repetitions of each line;

-D: Show only the rows that have been repeated;

-U: Displays only rows that have not been duplicated;


Note: Repeat for continuous and identical sides

Useradd: User-created

useradd [Options] LOGIN

-U UID: [Uid_min, Uid_max], defined in/etc/login.defs

-G GID: Indicates that the user belongs to the basic group, can be a group name, can also GID;

-C "COMMENT": User's comment information;

-d/path/to/home_dir: The home directory with the specified path;

-S Shell: Indicates the user's default shell program, the available list is in the/etc/shells file;

-G group1[,group2,... [, GROUPN]] : Specifies additional groups for the user, and the group must exist beforehand;

-r: Create a System user

CentOS 6:id<500< p= "" >

CentOS 7:id<1000< p= "" >

(groupadd): Group creation

Groupadd [OPTION] ... group_name


-G GID: Specifies the GID number; [Gid_min, Gid_max]

-r: Create a system group;

CentOS 6:id<500< p= "" >

CentOS 7:id<1000< p= "" >

ID: View user-related ID information

ID [OPTION] ... [USER]

-u:uid

-g:gid

-g:groups

-n:name


SU: Switch users or execute commands as other users

Su [Options ...] [-] [user [args ...]]


How to switch users:

Su UserName: Non-login switch, that is, the target user's configuration file will not be read;

Su-username: Login switch, will read the target user's configuration file; switch completely;


Note:root Su to other users do not need a password, non-root user needs a password when switching;


To change the identity of the execution command:

Su [-] username-c ' COMMAND '


Options:

-L: "Su-l UserName" equals "Su-username"



(+) Usermod: User attribute modification:

usermod [OPTION] Login


-U uid: New UID

-G GID: New Basic Group

-G group1[,group2,... [, GROUPN]] : The new add-on group, the original additional group will be overwritten, if the original, you want to use the-a option at the same time, indicating append;

-S shell: new default shell;

-C ' COMMENT ': new annotation information;

-D Home: New home directory, files in the original home directory will not be moved to the new home directory at the same time, to move, then use the-M option;

-L login_name: new name;

-l:lock the specified user

-u:unlock the specified user

-E YYYY-MM-DD: Indicates the user account expiration date;

-F INACTIVE: set inactivity period;


(+) passwd: add password to User

passwd [OPTIONS] UserName: Modify the password of the specified user, only the root user rights

passwd: Modify your password;


Common options:

-L: Lock the specified user

-U: Unlock the specified user


-N mindays: Specifying the shortest period of use

-X maxdays: Maximum lifespan

-W Warndays: How many days in advance to start warning

-I inactivedays: inactivity period;


--stdin: Receive user password from standard input;

echo "PASSWORD" | passwd--stdin USERNAME


Note:/dev/null, bit buckets

/dev/zero,

(userdel): Delete user

Userdel [OPTION] ... login

-r: Delete user home directory;


(GROUPMOD): Group Property Modification

Groupmod [OPTION] ... group

-N group_name: New name

-G GID: New Gid;


(+) Groupdel: Group Delete


(GPASSWD): group password


(PNS) Chage: Modify User Properties

chage [OPTION] ... LOGIN

-D Last_day

-E,--expiredate expire_date

-I.,--inactive inactive

-M,--mindays min_days

-M,--maxdays max_days

-W,--warndays Warn_days

(chmod): Modify file Permissions

chmod [OPTION] ... Octal-mode FILE ...


-R: Recursive Modify permissions


chmod [OPTION] ... Mode[,mode] ... FILE ...

MODE:

To modify all permissions for a class of users:

u=

g=

o=

ug=

A=

u=,g=


Modify one or some bit permissions for a class of users

u+

U-


chmod [OPTION] ...--reference=rfile FILE ...

Refer to the permissions of rfile file, change file to the same rfile;

(chown): Modify the owner of the file

chown [OPTION] ... [OWNER] [: [GROUP]] FILE ...


Usage:

OWNER

Owner:group

: GROUP


Note: The colon in the command is available. Replace;


-R: Recursive


chown [OPTION] ...--reference=rfile FILE ...

(CHGRP): Modify the genus Group of the file

CHGRP [OPTION] ... GROUP FILE ...

chgrp [OPTION] ...--reference=rfile FILE ...


Umask: Mask code when a file or directory is created

File:666-umask

Note: If there is an X permission in the result of a user with a class that has the permissions reduced, its permissions +1

Dir:777-umask


umask: View

umask #: Setting


Linux basic 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.