Dahne-linux Foundation-day04

Source: Internet
Author: User

To view the contents of a text file:

Cat: Suitable for viewing files with less content.

Less: Suitable for viewing files with more content. When the file content is more, from the first line display, press SPACEBAR to page, press Q to exit.

To view the contents of a file:

Head-n viewing the first n rows of a file

Tail-n to view the end n rows of a file

View time:

Date

Calculator

Bc

Pipe: The output of the preceding command is processed by the following command as a parameter of the following command.

head-12/etc/passwd/| TAIL-5 displays 8-12 lines of/etc/passwd/text content

Cat-n/etc/passwd | head-12 | TAIL-5//Displays 8-12 lines of/etc/passwd/text content and displays line numbers
8 Halt:x:7:0:halt:/sbin:/sbin/halt
9 Mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
Ten Operator:x:11:0:operator:/root:/sbin/nologin
Games:x:12:100:games:/usr/games:/sbin/nologin
Ftp:x:14:50:ftp User:/var/ftp:/sbin/nologin


[Email protected] ~]# echo | BC//will be referred to BC (Calculator) processing.
2


grep: View the contents of a text file, displaying the line containing the specified string

Format: grep option ' Match string ' text file

[[email protected] ~]# grep ' root ' /etc/passwd shows the rows containing root in etc/passwd/
Root:x:0:0:root:/root:/bin/bash
Operator:x:11:0:operator:/root:/sbin/nologin


-I: Indicates ignoring case
[[email protected] ~]# grep-i ' Root ' /etc/passwd

Displays the line containing the root in the etc/passwd/(not matched if not with-i)
Root:x:0:0:root:/root:/bin/bash
Operator:x:11:0:operator:/root:/sbin/nologin

-V is reversed and does not contain


^word begins with a word string

word$ ending with a word string

[[email protected] ~]# grep ' ^root '/etc/passwd displays the lines in/etc/passwd/text that start with root

[[email protected] ~]# grep ' bash$ '/etc/passwd shows the lines in/etc/passwd/text ending in bash

[[email protected] ~]# grep ' ^$ '/etc/default/useradd//show Blank lines in/etc/default/useradd (but we generally don't use them because there's no real sense in displaying empty lines in the text)

[[email protected] ~]# grep-v ' ^$ '/etc/default/useradd//We use-V to reverse, to display the valid content in/etc/default/useradd/.


Find Files by criteria

Recursively query the corresponding file according to the preset conditions

Find directory Condition 1

Common conditions indicate:

-type type (f for File, L for shortcut, D for directory)

-name "Document Name"

-size + File size (k M G)

-user User Name

find/boot/-type L//Find a shortcut under/boot

find/boot/-type f//Find files under/boot

find/boot/-type d//Find directory under/boot

find/etc/-name ' *tab ' Find files with the File name tab ending in/etc

find/opt/-name ' *a* '-type D find a file in the file name under/opt/ and file type must be a directory

find/opt/-name ' *a* '- o -type d//Find files with a or file type directory in the file name under/opt/

-exec operation using the Find command

find/boot/-size +10m-exec cp-r {}/opt/\; Copy files larger than 10M in/boot/to/opt


User and group management :

User account:

1: Can log into the operating system

2: Access control can be made (different user rights are different)

Group accounts: Easy to manage user accounts (permissions)

Unique identifier of user account and group account: UID GID

The administrator's UID is: 0

Group accounts: Basic group additional groups (public group subordinate groups)

-U User ID

-D User Home directory

-S landing shell

-G Basic Group

-G Additional Group

Useradd-u 1110-d/opt/-s/shell/nologin Karsa
[[email protected] ~]# grep ' Karsa '/etc/passwd
Karsa:x:1110:1110::/opt/:/shell/nologin//username Karsa; password placeholder x; user ID; group ID; user description information; home directory; interpreter;

User password information stored in/etc/shadow

Using the passwd command

-PASSWD User Name

[[email protected] ~]# echo 123 |passwd--stdin karsa change user karsa password to 123
Change the password for the user Karsa.
PASSWD: All the authentication tokens have been successfully updated.

To switch users temporarily:

Su-user name


Modify User Properties

-usermod option User Name

Usermod-u 1200-d/root/-s/shell/nologin Harry

[[email protected] ~]# grep ' Harry '/etc/passwd
Harry:x:1200:3469::/root/:/shell/nologin viewing post-modification information


Delete User

Using the Userdel command

Usderdel-r User name and delete home directory (we generally do not add-R, because the home directory is stored in the user's basic information.) )


Add Group

Group basic information stored in/etc/group

Groupadd Tena Add Tena Group

Using the GPASSWD command

-A user name Group name increase user to specified group

-d User Name Group name remove users from the specified group

-M ' User name, username ' Group name add multiple


Delete a group

Use Groupdel Group name


Archiving and compression

1 Space saving

2 Easy management of fragmented documents

Tar Integrated Backup tool

-C Create an archive

-z-j-j calls the. gz. bz2. xz Format tool for processing

-f Specifies the name and path of the archive file

-X Release Archive

-T displays a list of files in the archive file

-P Keep an absolute path to the archive file

-C Specify release location

tar-zcpf/opt/file.tar.gz/boot//etc/passwd compresses/boot//etc/passwd to/opt/file.tar.gz

Tar-xf/opt/file.tar.gz-c/mnt/release/opt/file.tar.gz to/mnt/


NTP Network Time Protocol


vim/etc/chrony.conf Modify the time server

Server classroom.example.com Iburst modified to classroom (because the classroom in the teaching environment provides NTP services, so we just need to do it on the client)

Systemctl Restart chronyd Restart Service

Systemctl Enable Chronyd random start


Verify

[[email protected] ~]# date-s ' 2012-1-1 12:12:12 ' modification time
Sunday, January 01, 2012 12:12:12 CST
[[email protected] ~]# systemctl restart chronyd Restart Service


Dahne-linux Foundation-day04

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.