Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Vi,find,bash, disk Management, chmod

2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

Assignment (activity) content:

1. Summarize the usage of vim, a text editing tool.

Vim: full screen editor, model editor

Vim mode:

Edit mode (command mode)

Input mode

Last row mode

Mode conversion:

Editor-à enter:

I: switch to input mode before the character in which the current cursor is located

A: after the character where the current cursor is located, switch to input mode

O: under the current cursor, create a new line and switch to input mode

I: convert to input mode at the beginning of the line where the current cursor is located

A: at the end of the line where the current cursor is located, convert to input mode

O: above the line of the current cursor, create a new line and change to input mode:

Open a file

# vi / tmp/grub2.cfg

Vi + #: open the file and navigate to line

Vi +: open the file and navigate to the last line

Vi + / PSTTERN: open the file and navigate to the beginning of the line that was first matched by PATTERN

In edit mode by default

Close the file

Close the file in the last line mode

: Q do not save exit

Wq save exit

: q! Force exit without saving

W save

: w! Forced preservation

: wq-- à: X

2 exit in edit mode

Zz: save and exit

The last line mode of vim

(1) address, demarcation

: start_pos,end_pos

#: line

#, #

#, + #

.: current line

$: last line

%: full text, equivalent to 1 $

The row to which / pat1/: is matched by this pattern for the first time

#, / pat1/

/ pat1/,/pat2/

You can then follow the editor's command:

D, y

W, r

(2) find

/ PATTERN: to the tail

? PATTERN: to the first part

N: same direction as the command

N: opposite to the command

(3) find and replace

S: in the last line mode, complete the find and replace operation within the range of the address delimited

S / what to find / what to replace with / modifier

What to find: available mode

To be replaced by: you cannot use a pattern, but you can use a backward reference symbol to reference what is matched by the grouping parentheses in the previous pattern

1, 2,.

&: reference the whole content matched by "what you are looking for"

Modifier:

I: ignore case

G: global replacement

/: used for delimiters, so if this symbol appears in what you want to find or replace with, to escape it with\, use the format:\ /

The delimiter can be replaced with other characters, such as @, #, etc.

1. How to use the summary file search command find

Find command: real-time search; search speed is slightly slower; precise search

Find [OPTION]... [search path] [search condition] [processing action]

Find path: default to current path

Search criteria: the specified search criteria can be carried out according to file name, size, main group, type, etc. The default is to find all files under the specified path.

Processing action: what to do with files that meet the criteria; the default is output to the screen

Search criteria:

Look up by file name:

-name "file name": glob is supported

*, []

-iname "file name": it is case-insensitive and glob is supported.

-regex "PATTERN": matches the entire file path string with PATTERN, not just the file name

Look up according to the owner and group:

-user USERNAME: find files whose owner is the specified user

-group GROUPNAME:

-uid UserID: find the file specified by the owner of the uid

-gid GroupID:

-nouser: find files without owners

-nogroup: find files that do not belong to a group

Look up by file type:

-typeTYPE

F: ordinary files

D: directory

L: symbolic link

B: block equipment

C: character device

P: named pipe

S: socket

Combination of search criteria:

And conditions:-a

Or condition:-o

Non-conditional:-not!

! Amuro! B =! (a-a B)

! Amura! B =! (Ao B)

Look up according to the file size:

-size [+ | -] # UNIT

Unit: K, M, G

# UNIT: (#-1 UNIT #]

+ # UNIT: (#, + oo)

-# UNIT: [0memorie muri 1]

According to the timestamp:

In terms of "days"

-atime [+ | -] #

#: [#, # + 1)

+ #: [# + 1Poweroo]

-#: [0BZ #)

-mtime

-ctime

In "minutes"

-amin

-mmin

-cmin

Based on permissions:

-perm [/ | -] MODE

MODE: exact permission matching

/ MODE: any permission of any kind of object (umai gjino) can satisfy the condition; implied or conditional

/ 400

-MODE: every permission specified for each type of object must exist at the same time to meet the condition; implied and conditional

Processing actions:

-print: default processing action

-ls: similar to doing "ls-l" operation on every file found

-delete: delete the found file

-fls/path/to/somefile: the detailed path information of the found file is saved to the specified file

-okCOMMAND {}\

Prior confirmation by the user is required before executing the specified command on each file

-execCOMMAND {}\

No user confirmation is required

2. Summarize the relevant contents of bash environment variables.

Configuration file, effective scope division, there are two types:

Global configuration:

/ etc/profile,/etc/profile.d/*.sh

/ etc/bashrc

Personal configuration:

~ / .bash_profile

~ / .bashrc

By function, there are two categories:

Profile class: provides configuration for interactive login shell

/ etc/profile,/etc/profile.d/*.sh

~ / .bash_profile

Function:

(1) define environment variables, such as PATH and PS1

(2) run a command or script

Bashrc class: provides configuration for non-interactive login shell

/ etc/bashrc

~ / .bashrc

Function:

(1) define command aliases

(2) define local variables

Variables: memory space, variable name

Type:

Environment variables: scope current shell process and its child processes

Local variable: scope current shell process

Local variable: the scope is only a code snippet in the current shell process (usually in the context of a function)

Location variable: $1, $2

Special variable: $?

How variables are defined:

Bash built-in variables: can be called directly, built-in many environment variables, such as PATH, etc.

Custom variables:

Variable assignment: variable name = value

Bash weak type:

When a variable stores data, it is in character form by default; any variable can be referenced directly without declaration

120:24bits

120:8bits

Define local variables:

Name=value

Viewing: set

Define environment variables:

Exportname=value

Declare-xname=value

View: env, printenv, export

Undo the variable:

Unset name

Reference variable:

${name}, $name

Reference symbols in bash:

'': strong reference, variable substitution will not occur

"": weak reference

``: command reference

3. Summarize the knowledge points of special permissions (SUID, SGID, Sticky) on the Linux file system.

SUID:

(1) whether any executable program file can be started as a process depends on whether the initiator has the right to execute the program file.

(2) after starting as a process, its owner is not the initiator, but the owner of the program file itself; this mechanism is called SUID

Permission settings:

Chmodu+s FILE...

Chmodu-s FILE...

Note:

S: the owner originally had x permission

S: the owner originally did not have x permission

SGID:

By default, when a user creates a file, it belongs to the basic group to which the user belongs

Once a directory is set with SGID permission, the files created by users who have write access to this directory belong to a group that belongs to the directory, not the user's basic group.

Permission settings:

Chmodg+s FILE...

Chmodg-s FILE...

Sticky:

For a directory that can be written by multiple people, this permission is used to restrict each file that can only be deleted by itself

Permission setting

Chmodo+t FILE...

Chmodo-t FILE...

Permission model:

U, g, o

R, w, x

Security context of the process:

Premise: the process has an owner (as which user the process runs); the file has an owner and a group

(1) whether a user can start an executable program file as a process depends on whether the user has the right to execute the program file.

(2) after the program is started as a process, the owner of the process is the current user, that is, the initiator of the process; the group to which the process belongs is the basic group of the initiator

(3) the access rights enjoyed by a process depend on the access rights of its owner:

(a) if the owner of the process is the same as the document owner, the document owner authority shall be applied

(B) if the owner of the process belongs to the group of the document, the file group permission shall be applied

(C) apply other permissions

5. Summarize the knowledge points related to Linux disk management and file system and the usage of related commands.

Partition: separate storage space into multiple small spaces, each of which can use the file system independently

Zoning tools:

Fdisk,parted, sfdisk

Use of the fdisk tool:

Supports up to 15 partitions on one hard disk

Partition Management subcommand:

P: display

N: creatin

D: deletin

T: modify partition ID

L: list all supported ID types

W: save exit

Q: discard changes and exit

M: get help

After the creation is complete, check to see if the kernel has recognized the new partition:

# cat/proc/partitions

There are three commands that allow the kernel to reread the disk partition table:

CentOS5: partprobe [DEVICE]

CentOS6,7:

Partx

Kpartx

Partx command:

PartxDEVICE

Partx-a DEVICE

Partx-a-n MVO N DEVICE

M

M:

: N

Kpartx command:

Kpartx-af DEVICE

Linux file system management:

Mkfs, mkfs-ttype = mkfs.type

Ext:mke2fs

Create a file system:

Mke2fs[OPTION]... DEVICE

-t {ext2 | ext3 | ext4}

-b {1024 | 2048 | 4096}

-Lhasa Labelle'

-j:mke2fs-t ext3

-I #:

-N #:

-m #: what percentage of disk space is reserved for later management use

-OFEATURE [,...]

-O ^ feature: turn this feature off

Has_journal

File system Properties View and Adjustment tool:

E2label

E2lableDEVICE [LABEL]

Tune2fs

Display or adjust the properties of the ext series file system

-l: display the information in the super block; display the attributes, layout and other related information of the whole file

-modified labeling: modify the volume label

-m #: adjust the percentage of management space reserved for administrators

-j: ext2-- > ext3

-O: startup or shutdown of file system properties

-o: enable or disable the default mount option for the file system

Dumpe2fs:

-h: only super block information is displayed

File system detection:

Fsck:Filesystem check

Fsck-ttype

Fsck.type

-a: automatically fix errors

-r: interactively fix errors

-f: force detection

Special detection and repair tools for e2fsck:ext series file system

-y: automatic answer is "yes"

-f:force

6. Copy the / etc/grub.cfg configuration file to the / tmp directory and delete the white space character at the beginning of the line in the / tmp/grub.cfg file with the find replace command

[root@localhost~] # cp-p / etc/grub2.cfg / tmp/ [root@localhost~] # ls / tmp/grub2.cfg [root@localhost~] # vi / tmp/grub2.cfg:%s/ ^\ s command mode in the lower left corner

7. Copy the / etc/rc.d/init.d/functions file to the / tmp directory and add a # to the beginning of each line that begins with a white space character with the find and replace command / tmp/functions; the original white space character is retained

[root@localhost~] # cp / etc/rc.d/init.d/functions / tmp/ [root@localhost~] # vi / tmp/functions

:% s / ^\ s _ g or:% s / ^ [[: space:]] / # & / g in the command mode in the lower left corner.

8. Replace / etc/sysconfig/init in / tmp/functions file with / var/log

[root@localhost~] # vi / tmp/functions:%s/\ / etc\ / sysconfig\ / init/\ var\ / log/g

9. Delete the line # from the / tmp/functions file that starts with # and is followed by at least one white space character

[root@localhost~] # vi / tmp/functions:%s/ ^ #\ (\ s\ +\) /\ 1Unigram

10. Find all files in the / var directory whose owner is root and whose group is mail

[root@localhost~] # find / var-user root-group mail-ls134295027 0 drwxrwxr-x 2 root mail 6 Jun 10 2014 / var/spool/mail [root@localhost~] #

11. Find all files in the / usr directory that do not belong to root, bin or hadoop

[root@localhost~] # find / usr!-user root!-user bin!-user hadoop-lsfind: 'hadoop'is not the name of a known user [root@localhost~] # useradd hadoop [root@localhost~] # find / usr!-user root!-user bin!-user hadoop-ls- you may have to wait a few seconds here Don't think it's stuck here-200304 0 drwx- 2 polkitd root 6 Jun 10 2014 / usr/share/polkit-1/rules.d

12. Find all files in the / etc directory whose contents have been modified in the last week and whose owner is not root or hadoop

[root@localhost~] # find / etc-mtime-7!-user hadoop-ls67108993 12 drwxr-xr-x 74 root root 8192 Sep 2 08:23 / etc431625 4-rw-r--r-- 1 root root 14 Sep 2 04:36 / etc/tuned/active_profile67985872 4-rw-r--r-- 1 root root 470 Sep 2 08:23 / etc/group67985873 4- 1 root root 371Sep 2 08:23 / etc/gshadow67985868 4-rw-r--r-- 1 root root 995 Sep 2 08:23 / etc/passwd67985871 4-1 root root 643 Sep 2 08:23 / etc/shadow67109049 4 drwxr-xr-x 6 root root 4096 Sep 2 04:36 / etc/sysconfig134732599 4 drwxr-xr-x 2 root root 4096 Sep 2 04:36 / etc/sysconfig/network-scripts135058400 4-rw-r--r-- 1 root root 352 Aug 28 05:38/etc/sysconfig/network-scripts/ifcfg-eno1677773667427376 4-rw-r--r-- 1 root root 952 Sep 2 08:18 / etc/passwd-67109038 4-1 root root 614 Sep 2 08:18 / etc/shadow-67311285 4-rw-r--r-- 1 root root 455 Sep 2 08:18 / etc/group-67109030 4-1 root root 360 Sep 2 08:18 / etc/gshadow- [root@localhost~] #

[root@localhost~] # find / etc-mtime-7!-user hadoop!-user root-ls [root@localhost~] #-there is nothing here except root But you can modify the owner [root@localhost~] # cp-p / etc/group- / etc/group1 [root@localhost~] # find / etc-mtime-7!-user hadoop!-user root-ls [root@localhost~] # chown bin: / etc/group1 [root@localhost~] # find / etc-mtime-7!-user hadoop!-user root-ls67985874 4-rw-r--r-- 1 bin bin 455 Sep 2 08:18 / etc/group1 [root@localhost~] #

13. Find all files that have no owners or groups on the current system and have been accessed in the last week

[root@localhost] # find /-nouser-mtime-7

14. Find all files in the / etc directory that are greater than 20k and whose type is ordinary.

[root@localhost ~] # find / etc- type f-size + 20k-ls [root@localhost ~] # find / etc-size + 20k-type f-ls

15. Find files in the / etc directory that all users do not have write permission to

[root@localhost ~] # find / etc! = perm+222-ls [root@localhost ~] # find / etc-not-perm+222

16. Find at least one class of files in the / etc directory that users do not have the right to execute.

[root@localhost~] # find / etc!-perm-111lll-ls [root@localhost~] # find / etc-not-perm-22222-ls

17. Find files under the / etc/init.d directory where all users have execute permissions and other users have write permissions

[root@localhost~] # find / etc/init.d-perm-113-ls67208865 0 lrwxrwxrwx 1 root root 11 Aug 21 04:01/etc/init.d-> rc.d/init.d

18. Enable ordinary users to view / etc/shadow files using / tmp/cat

[root@localhost~] # which cat/usr/bin/cat [root@localhost~] # cp / bin/cat / tmp [root@localhost~] # ls-l / tmp/total 76-rwxr-xr-x. 1root root 54048 Sep 2 09:01 cat-rw-r--r--. 1root root 13430 Sep 2 07:45 functions-rw-r--r--. 1root root 3976 Aug 21 04:12 grub2.cfg [root@localhost~] # chmod Utility / tmp/cat [root@localhost~] # ls-l / tmp/total 76-rwsr-xr-x. 1root root 54048 Sep 2 09:01 cat-rw-r--r--. 1root root 13430 Sep 2 07:45 functions-rw-r--r--. 1root root 3976 Aug 21 04:12 grub2.cfg [root@localhost~] # chmod Umurs / tmp/cat [root@localhost~] # ls-l / tmp/total 76-rwxr-xr-x. 1root root 54048 Sep 2 09:01 cat-rw-r--r--. 1root root 13430 Sep 2 07:45 functions-rw-r--r--. 1root root 3976 Aug 21 04:12 grub2.cfg [root@localhost~] # chmod 4755 / tmp/cat [root@localhost~] # ls-l / tmp/total 76-rwsr-xr-x. 1root root 54048 Sep 2 09:01 cat-rw-r--r--. 1root root 13430 Sep 2 07:45 functions-rw-r--r--. 1root root 3976 Aug 21 04:12 grub2.cfg [root@localhost~] #

Create a directory / test/data, which allows ordinary users in a group to write to it, and all files created belong to the group to which the directory belongs; in addition, each user can only delete their own files

[root@localhost~] # mkdir-p / test/data [root@localhost~] # groupadd only [root@localhost~] # chown: only / test/data/ [root@localhost~] # ls-l / test/total 0drwxr-xr-x. 2root only 6 Sep 2 09:14 data [root@localhost~] # chmod otakt / test/data/ [root@localhost~] # ls-l / test/total 0drwxr-xr-t. 2root only 6 Sep 2 09:14 data [root@localhost~] # useradd-G only user1

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report