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

Summary (vim find bash Foundation Special permission limit disk Management Foundation)

2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

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

Vim is a visual editor

There are three modes: edit mode, insert mode, and last line mode; (the default is in edit mode when opening a file using vim)

Conversion between modes:

Edit mode à insert mode

I insert at the cursor

An enter the insert at the last bit of the cursor

I enter insert mode at the beginning of the line where the cursor is located

An enters insert mode at the end of the line where the cursor is located

O below the line of the cursor, start a new line and enter insert mode

O above the line of the cursor, start a new line and enter insert mode

Insert mode à editing mode

Just press ESC.

Edit mode à last line mode

: colon

Last line mode à editing mode

One or two consecutive ESC keystrokes

Exit the operation of vim

ZZ in edit mode can perform save exit (not commonly used)

: Q you can use Q to exit directly when the text content has not changed.

: q! Forcibly exit, discard edited content

Wq saves and exits normally

: wq! Forced save and exit (generally, only root can be used, root can ignore the file read-only status)

W save, but do not exit

: w! Force save but do not exit

Cursor movement

Hjkl in edit mode

H move to the left is equivalent to the arrow key to the left

L move to the right is equivalent to the arrow key to the right

J move down (Ma Lao says j is Japanese indecent) is equivalent to the arrow key down arrow

K moving up is equivalent to pointing keys up and down.

You can also # {h | j | k | l} (# represents a number)

For example, 5h means to move 5 characters to the left, and 5l means to move 5 characters to the right, 5J down 5 times, 5k up 5 characters.

The movement between words

In edit mode

W skip to the beginning of the next word

E skip to the end of the next word

B to the beginning of the previous word

# {w | e | b} is also supported

Move # positions at a time, such as:

3w equals pressing w three times to jump to the beginning of the third word to the right at the cursor

3e jump to the end of the word from the cursor or three words to the right

3b skip to the beginning of the first three words

A fast jump between the beginning and the end of a line

In edit mode

0 number zero, jump to the absolute beginning of the line, in the actual experiment is to jump to the relative head of the line rather than the absolute beginning of the line.

^ off the character, jump to the beginning of the line, or if the beginning of the line is a blank character, jump to the first letter of the line

$Jump to the end of the line

Jump between sentences (not commonly used)

In edit mode

(the next sentence

(previous sentence)

Jump between paragraphs (not commonly used)

In edit mode

} the next paragraph

{previous paragraph

Interline movement

In edit mode

# G jumps to a specified line, such as 8G, which is the beginning of the eighth line

G jumps to the end of the article

Gg jumps to the first line of the article

In the last line mode, the jump can be completed by directly specifying the number.

3 means to skip to the third line

Editing operation

In edit mode

X Delete the character where the cursor is located

# x delete # characters at a time (to the right)

Dd deletes an entire line

# dd delete together with this line and down a total of # lines

D can be deleted by combining word jump, line beginning and line end jump, such as:

Dw deletes the character between the cursor and the beginning of the next word

De deletes the character between the cursor and the end of the next word, which is basically the deletion of the next word

Db deletes the character between where the cursor is located and the beginning of the previous word

D ^ Delete the character from where the cursor is to the beginning of the line

D $removes the character between the cursor and the end of the line

D0 deletes the character between where the cursor is located and the beginning of the line (absolute beginning of the line)

# d {w | e | b} delete more than one at a time

P paste (put, paste) to paste the last deleted content

P lowercase, after pasting the cursor

P uppercase, before pasting cursor

Paste at the line level, paste a new line down the line where the p (lowercase) cursor is located, and a new line up where the P (uppercase) cursor is located

Copy operation, using the same method as d

Yy copies a whole line

# yy downwards, together with this line, a total of # lines to copy

Like d, it can be copied by combining the jump actions of the word, the beginning of the line and the end of the line.

Dw copies the character from the cursor to the beginning of the next word

De copies the character from the cursor to the end of the next word

Db copies the character from where the cursor is located to the beginning of the previous word

Y ^ copy the character from where the cursor is to the beginning of the line

Y$ copy the character between the cursor and the end of the line

# y {w | e | b} copy more than one at a time

C change, replace operation

Cc deletes the entire row and enters the insert operation

# cc together with this line down a total of # lines delete and enter the insert operation

C ^ Delete the content between the cursor and the beginning of the line and enter the insert operation

C $deletes the content between the cursor and the end of the line and enters the insert operation, which has the same effect as C (uppercase)

Cw deletes the character from the cursor to the beginning of the next word and enters the insert operation

Ce deletes the character from the cursor to the suffix of the next word and enters the insert operation

Cb deletes the character from the cursor to the beginning of the previous word and enters the insert operation

# c {w | e | b} replace multiple at a time

R replace the single character where the cursor is located, only once at a time

Undo action

U undo undo modification

# u undo # changes (only 50 changes are saved by default)

Ctrl+r restores undo content

. Repeat the last action

Flip screen operation in edit mode

Ctrl+f next screen

Previous screen of Ctrl+b

Ctrl+d downward half screen

Ctrl+u up half screen

Text search

/ PATTERN search down from the head

? PATTERN searches up from the tail

N next

N last

Text replacement operation (last line mode)

Address demarcation

: startline [, endline]

: # Line #

:. Current line

: $trailing

:% full text

: + # specify position down # lines

:-# specify position # line up

For example, 10 ~ 18 lines of content are deleted in 10 ~ (th) century 8d, and 10 ~ (th) lines to 2 ~ (th) lines are deleted in 10 ~ (th) ~ (th).

Text replacement command (last line mode)

Format s / what to find / what to replace / modifier

Where "/" is the delimiter and can be replaced with symbols not included in the find or replace, such as @, #, etc.

What to find supports regular expressions

Content to replace does not support regular expressions, but you can use backward references\ 1\ 2.

The modifier I means case is ignored, g is global global

PS: "what to replace" uses & refers to all the contents of "what to find"

Multi-file mode

Vim [option] file.

+ # Open the file and jump to line #, vim + 3 file, open file and navigate to line 3

: next next file

: last file in prev

The first file of first

The last file of last

Wall saves all

Qall exits all

: wqall save all exit

Multi-window mode

Vim-o file1 fiel2. Split horizontally to open multiple files

Vim-O file1 fiel2... Split vertically to open multiple files

Jump ctrl+w,arrow between windows (arrow keys)

A single file can also be split into windows.

Ctrl+w,s horizontal segmentation

Ctrl+w,v vertical segmentation

Show attribute definition (last line mode)

: set nu display line number: set nonu turns off display line number

: set hlsearch search highlight: set nohlsearch turns off search highlight

: set autoindent (: set ai) enables automatic indentation: set noautoindent (: set noai)

: set ignorecase (: set ic) ignores case: set noignorecase (: set noic)

: set showmatch (: set sm) turn on highlight parenthesis pairing: set noshowmatch (: set nosm)

Vim profile

Global profile / etc/vimrc

Personal profile ~ / .vimrc does not exist by default, just create and save it

2. How to use the summary file search command find.

The file lookup function can use locate and find

Locate looks for files according to the database, and the results of all searches will not be very complete. Execute updatedb to update the database if necessary.

Find usage

Find [option] [PATH] [condition] [processing Action]

Search criteria:

Look up by name

-name "file name" file name writing method supports globbing (wildcard)

-iname "file name" ignores file name case

Find it according to the owner and group.

-user unsername

-group groupname

-uid # search based on uid

-gid # search based on gid

-nouser looks for files without owners

-nogroup looks for files that do not belong to a group

Combination of conditions, and, OR, not

-a search bar 1-a search condition 2-a. -a can be omitted

-o search condition 1-o search condition 2-o.

-not use! Or.

Find by file type

-type

F ordinary file

D directory file

L link file

B block file

C character file

P pipe file

S socket

Find by file size

-size + |-commonly used units are K M G

-size # k finds files greater than #-1 and less than or equal to # k

-size + # k to find files greater than # k

-size-# k finds files less than or equal to #-1k

Find according to the timestamp

In days

-atime [+ | -] #

-ctime [+ | -] #

-mtime [+ | -] #

For example:

-4 means less than or equal to 4

4 means greater than 4 but less than 5 days

+ 4 means greater than or equal to 5 days

In minutes

-mmin

-cmin

-amin

Find based on permissions

-perm [+ | -] MODE

Indicates that MODE is not a +,-indicates an exact match

+ any kind of permissions, as long as the application account can include one of them.

-each type of user rights should include the permissions of the corresponding bits

Processing action

-print result output value screen, which is timely by default

-ls display details

-exec COMMAND {}\; directly executes no interactive reminder operation. {} represents the value searched by find,\; ends in a fixed syntax format.

-ok COMMAND {}\; has the same effect as-exec, but each step requires user confirmation and interactive reminders.

Note:

Find can find all qualified files at once and pass them to the following commands, but some commands do not support excessively long parameters, so you can use:

Find XXXX | xargs COMMAND

3. Summarize the relevant contents of bash environment variables.

The effective scope of bash configuration files can be divided into two categories:

Global class

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

/ etc/bashrc

Individual human beings

~ / .bash_profile

~ / .bashrc

Divided by function (profile class, bashrc class)

Profile class, which provides configuration for interactive login to shell

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

~ / .bash_profile

Functions: 1, define environment variables such as PATH PS1, 2, run command script

Bashrc class, which provides configuration for non-interactive login shell

/ etc/bashrc

~ / .bashrc

Functions: 1, define command aliases; 2, define local variables

Variable type

Environment variables act on the current shell process and child processes

Local variables act on the current shell process, and child processes do not take effect

The role of local variables is related to only a code fragment in the current shell process

Location variable $0 $1 $2.

Special variable $?

How variables are defined:

Bash embedded variables that can be called directly, with embedded variables such as PATH PS1, etc.

User-defined variable

Variable name = value variable storage format is in character form by default and can be used without declaration

Viewing: set

Pstree command, viewing the process tree

Define environment variables

Export variable name = value Local variable is declared as environment variable

Declare-x variable name = value is equivalent to export

Viewing: env printenv export

Undo variable

Unset variable name

Reference variable

${variable name}

The function of quotation marks in bash

"" double quotation marks, weak quote

'' single quotation mark, strong quote

``backquotes to refer to the result of its command execution

The difference between interactive and non-interactive login shell:

Interactive: user name and password need to be entered, such as terminal login; su-username user switching

Non-interactive: do not need to enter a user name and password, such as right-click to open the terminal in the graphical interface; su username switch (no -)

Order of action of configuration files

Interactive:

/ etc/profile à / etc/profile.d/*.sh à / etc/bashrc à / .bash_profile à / .bashrc

Non-interactive

~ /. Bashrc à / etc/bashrc à / etc/profile.d/*.sh

Effective method after editing configuration file:

You can log in to shell; source file or. / PATH/FILE to execute (note that repeated execution may result in repeated additions)

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

The security context of the process

The premise is that the process has an owner, and the document has an owner and a group.

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

2. after the program starts, the subordinate group of the program is the user, that is, the initiator of the program, and the subordinate group of the process is the basic group of the initiator.

3. The access rights of a process depend on the access permissions of its group.

If the owner of the process is the same as the owner of the file, the master permissions are applied

If the owner of the process is the same as the group of the file, the master permissions are applied

Otherwise, other permissions of the file are applied

Special authority

SUID

If the owner has execute permission, it is displayed as s, otherwise it is displayed as S

Function: for an executable file, when any user runs this program as a process, the owner of the process is not the initiator, but the executable file's own group.

Chmod Utility add UID permission

SGID

Function: when the subordinate group of a directory has write permission and SGID permission, then all the subordinate groups that belong to this directory, and create a new file or directory in this directory as a subordinate group, the subordinate group of the new file or directory is not the basic group to which the creator belongs, but the subordinate group of the directory.

Chmod gears DIRECTORY

Special permission bit sticky

Chmod ointt

No one can delete a file except root and the master user of the file.

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

Hard disk classification

Mechanical hard disk

SSD solid state disk

Mechanical type

Track track

Sector sector 512bytes

Cylinder cylinder, the basic unit of the zone

MBR master boot record

512bytes

The first 446 bytes of which: bootloader

64 filesystem allocation table (FAT)

Every 16 bytes represents a partition

Hard disk interface type

IDE

SCSI

SATA

SAS

USB

Set up a hard disk device: / dev/sd [a murz], mark the non-passing partition / dev/sd [a murz] [1 -] on the same device

1-4 Primary or extended partition identification

5 + logical partition identification

Device files are also known as special files

[root@localhost ~] # ll / dev/sda*brw-rw---- 1 root disk 8, 0 Aug 24 16:33 / dev/sdabrw-rw---- 1 root disk 8, 1 Aug 24 16:33 / dev/sda1brw-rw---- 1 root disk 8, 2 Aug 24 16:33 / dev/sda2brw-rw---- 1 root disk 8, 3 Aug 24 16:33 / dev/sda3brw-rw---- 1 root disk 8, 4 Aug 24 16:33 / dev/sda4brw-rw---- 1 root disk 8 5 Aug 24 16:33 / dev/sda5

Device number:

Primary device number major (8) secondary device number minor (0-5)

Major device Typ

Different devices under the same type of minor

Partition reason: divide the storage space into multiple small spaces, and each space can use the file system independently.

Zoning tool

Common: fdisk parted sfdisk

Fdisk command (it is said that up to 15 partitions can be managed on the same hard drive)

-l DEV lists disk information

Fdisk DEV partition management self-command

P display

N create

D Delete

T modify disk id

L list supported ID

W Save exit

Q discard changes and exit

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

Cat / proc/partions

Reread disk partition

Centos5: partprobe [DEVICE]

Centos6 、 7: partx kpartx

Partx

-an add

-n number

Partx-a-n / dev/sda6 add sda6 to the kernel

Partx-a-n 4:6 / dev/sda add 4-6 partitions at a time

Partx-a DEVICE, all added, but those that have been added will report an error

Kpartx-af DEVICE forces hard disk partitions to be added

Linux file system management

Linux file system: ext2 ext3 ext4 xfs btrfs swap

Optical disk file system: iso9660

Windows: fat32 ntfs

Network file system: nfs cifs

Log file system: (ext3 ext4xfs btrfs)

Swap swap partition (using hard disk space as memory) when memory is insufficient, store temporarily unused ones in swap, similar to virtual memory in windows

Create a file system

Perform formatting on partitions (advanced formatting)

Create tool mkfs

Inspection tool fsck (fsck.ext4 is used to detect ext4 series)

Mkfs-t TYPE DEVICE

Blkid DEVICE to view partition LABEL UUID, file system type and other information

Mkfs-t ext4 = mkfs.ext4

Special management tools for ext series file system

Mke2fs-t {ext2 | ext3 | ext4}

-b BLOCK 1024 2048 4096 bytes

-L LABEL set volume label

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

There is no grub.cfg in Centos6, use / etc/grub.conf to demonstrate

:% s / ^ [[: space:]] / /

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

:% s @ ^\ ([[: space:]]\) @ #\ 1@

Why not / split? Because\ (\) is used later, it doesn't seem to be clear enough at a glance, so use @ for segmentation

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

:% s#/etc/sysconfig/init#/var/log#

You can also use # to split if the content you find or replace does not contain this character

9. Delete all lines in the / tmp/functions file that begin with # and # is followed by at least one blank character

:% s @ ^ #\ ([[: space:]]\) @\ 1@

There can be regular expressions in what you want to find, but not in replacements, but you can use the latter item reference (\ 1)

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-ls525473 4 drwxrwxr-x 2 root mail 4096 Sep 2 10:12 / var/spool/mail

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

[root@localhost] # find / usr/-not\ (- user root-o-user bin-o-user hadoop\)-ls402139 12-rwsr-xr-x 1 abrt abrt 10296 Jul 25 00:08 / usr/libexec/abrt-action-install-debuginfo-to-abrt-cache

Note: the space after-not needs to be separated by a space.

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-not\ (- user root-o-user hadoop\)-ls1179660 4 drwxr-xr-x 2 779 hadoop 4096 Sep 2 13:38 / etc/mytest

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-o-nogroup\)-mtime-7-ls1179660 4 drwxr-xr-x 2 779 hadoop 4096 Sep 2 13:38 / etc/mytest526066 0-rw-rw---- 1 779 mail 0 Aug 31 18:26 / var/spool/mail/bash917513 0-- Whashashi Muyashi w-1,779 root 0 Aug 31 18:10 / tmp / b918351 4 drwx- 4 1001 1001 4096 Sep 2 13:43 / home/database917516 4 drwx- 4 779 779 4096 Sep 2 13:43 / home/bashfind: `/ proc/1090/task/1090/fd/5': No such file or directoryfind:` / proc/1090/task/1090/fdinfo/5': No such file or directoryfind: `/ proc/1090/fd/5': No such file or directoryfind: `/ proc/1090/fdinfo/5': No such file or directory

14. Find all files in the / etc directory that are larger than 20k and whose types are ordinary files

[root@localhost ~] # find / etc/-size + 20k-type f-exec ls-ldh {}\

If you find out too much, you won't post it.

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

[root@localhost] # find / etc/-not-perm + 222m-ls1179988 352r etc/pki/ca-trust/extracted/pem/objsign-ca-bundle.pem Aug-1 root root 359773 Aug 19 23:51 / etc/pki/ca-trust/extracted/openssl/ca-bundle.trust.crt1179991 208While Aug 19 23:51 / etc/pki/ca-trust/extracted/pem/objsign-ca-bundle.pem

All users do not have write permission = not any one user contains write permission

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/-not-perm-111l

At least one type of user does not have execute permission = not every type of user has execute permission

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

-111 is that each user contains execution permission, and other users need to have write permission. Just + 2 on the other user bit can =-113.

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

[root@localhost ~] # ll / etc/shadow- 1 root root 1206 Sep 2 13:42 / etc/shadow [root@localhost ~] # chmod USAs / tmp/cat [root@localhost ~] # ll / tmp/cat-rwsr-xr-x 1 root root 48568 Sep 6 11:14 / tmp/cat

Analysis: if an ordinary user executes cat, the process owner of this cat is the executor himself, but the executor does not belong to the owner or group of passwd, so according to the o permission bit of shadow, it is impossible to read. Add SUID permission to / tpm/cat, then the process owner of ordinary user executing cat is root. Although the owner of shadow does not have the authority, root has the supreme authority and can still read it.

[root@localhost ~] # su-hadoop [hadoop@localhost ~] $/ tmp/cat / etc/shadowroot:$6 $qHghFv2SnmPJgsKM$JbGecAAkkhJQsRO4eLGMScdCe3HCzZF2QXoHskXDMEM7FT3NxwiLzurqyYFiXrG5gQfv1rutpAeMuTcyUKwQm/:16666:0:99999:7:::bin:*:15980:0:99999:7:::daemon:*:15980:0:99999:7:::.

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

Let's analyze it first:

Let ordinary users in a group have write access to it, chmod g=rwx / test/data

And the subordinate group of all the files created is the group chmod gems / test/data to which the directory belongs.

Each user can only delete his or her own file, chmod / test/data.

Verify:

[root@localhost data] # ll-d / test/data/drwxrwsr-t 2 root hadoop 4096 Sep 6 12:00 / test/data/ [user1@localhost data] $touch aa [user1@localhost data] $lltotal 0Murray Ruki-1 user1 hadoop 0 Sep 6 12:01 aa-rw-rw-r-- 1 hadoop hadoop 0 Sep 6 12:02 bb

View / test/data permissions, SUID,sticky

[user1@localhost data] $whoamiuser1 [user1@localhost data] $lltotal 0 rm-1 user1 hadoop 0 Sep 6 12:01 aa-rw-rw-r-- 1 hadoop hadoop 0 Sep 6 12:02 bb [user1@localhost data] $rm-rf bbrm: cannot remove `bb': Operation not permitted

Deletion of another user's file was rejected

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