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

Vim find bash file system

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

Share

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

One vim

Vi visual interface full screen text editor

Line text editor sed

Full screen: vi/vim nano

Vim = vi improved

Mode:

Edit mode, command mode

Input mode

Last row mode

Edit mode-- "input mode"

I insert, insert in place

An append, then insert

O insert a new line

I line beginning insert

Insert at the end of line A

O insert a new row above the current row

Input mode-"Editing mode"

Press the ESC key

Edit mode-"Last line mode"

Press: wq to save exit

Last line mode-- "Editing mode"

Press the ESC key twice in a row

Vim open file if there is direct editing, if it does not exist, the file will be created, and the path must be normal

Vim + n file open the file and go to line n

+ / PATTERN

: q

: q!

Wq forces you to write to the file and exit. Force writing even if the file has not been modified, and update the modification time of the file.

: X writes to the file and exits. Write only when the file is modified, and update the file modification time, otherwise the file modification time will not be updated.

Press ZZ in edit mode to save

Cursor jump

Jump between characters

H j k l

Left, bottom, top, right.

Each jump character can be preceded by a number to indicate that multiple characters jump

Jump 3 characters to the left in 3h

Jump between words

W the initial symbol of the next word is treated as a separate word, _ is not regarded as a separate word

E the suffix of the current or latter word

B the prefix of the current or previous word

If you add a number in front of you, you can jump into multiple words.

Inline jump

^ jumps to the first non-white space character at the beginning of the line

0 jump to the beginning of the line

$Jump to row hair

Interline movement

# G Jump to #

1G gg jumps to the first line

G jumps to the last line

Inter-sentence movement

) skip to the next sentence separated by various symbols

(skip to the previous sentence

Move between paragraphs

} skip to the next paragraph separated by a full line of white space

{skip to the previous paragraph and be separated by a full line of white space

Editing command

Character editing

X Delete the character where the cursor is located

# x # characters after the cursor is deleted

Xp corrects the outer character of the cursor with the following character

R replace the character where it is located

# r

Delete command

D delete, can be used with the cursor jump

D $removes the character whose cursor is positioned to the end of the line

D ^ Delete the character whose cursor is positioned at the beginning of the line

D0 removes the character where the cursor is positioned to the beginning of the line

Dw deletes all characters before the cursor before the next word (also removes the symbol before the next word)

De deletes all characters from the cursor to the end of the word (does not delete the symbol before the next word)

Db deletes all characters from the cursor to the prefix, and if it is already at the prefix, delete the whole word before the cursor

Dd deletes the entire line where the cursor is located

# dd Delete the line on which the cursor is located and the # line after it

All deletions are saved to the buffer by the VIM editor

Paste command

If the previous copy or deletion is not a complete line

P paste to the back of the cursor

P paste to the front of the cursor

If the previous copy or deletion is a full line or multiple lines

P paste below the line where the cursor is located

P paste above the line where the cursor is located

Copy command

Y compound currency

Y$ copy the character whose cursor is positioned to the end of the line

Y ^ copy the character whose cursor is positioned to the beginning of the line

Y0 copies the character whose cursor position is at the beginning of the line

'=

Yw copies all the characters before the next word with the cursor

Ye copies all the characters from the cursor to the suffix

Yb copies all the characters from the cursor to the prefix, and if it is already at the prefix, copy the whole word before the cursor

Yy copies the entire row

# y copy # lines

Change the command

C delete-- > cut-> enter insert mode

C $c ^ c0

Ce cw cb

Cc

# c

Revoke an order

U

# u

Undo

Ctrl+r

. Repeat the previous operation command

Flip screen operation

Ctrl+f turns back one screen.

Ctrl+b flips a screen forward

Ctrl+d backward half screen

Ctrl+u front half screen

Vimtutor vim built-in tutorial

Last row mode

Address, delimited can be followed by the editing command d y w r

: start,end

# Line #

: 5 the cursor jumps to line 5

100 cursor jumps to line 100

100d delete line 100th

#, # Line # to Line

#, + #

Delete 3 lines after the 100th line of 100th line of the 100th line of 100th

. Current line

$Last line

:. $- 1D

% 1 dint $full text

: / part1/ rows that are matched by this pattern for the first time

: / umask/

: #, / umask/

: / part1/,/part2/

Search function

/ PATTERN looks from the cursor to the tail

? PATTERN looks from the cursor to the header

N find the next one in the same direction as the command

N finds the next one in the opposite direction of the command

Find and replace

S completes the find and replace operation within the address delimited range in the last line mode

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

What to find: available mode

Replacement of flesh content: patterns cannot be used, but subsequent reference symbols can be used

& reference the entire content that matches what you are looking for

Modifier

I ignore case

G global replacement

/: used for delimiters, to escape symbols using\

: 3100s/pid/processid/g

:% s@/etc/fstab@/tmp/fstab@/g

:. + 20s/ ^ # / / g

Multi-file mode

Vim file1 file2

Next switches to the next file

First switches to the first file

Last switches to the last file

Prev switches to the previous file

Wqall saves all files

: qroomall does not save all files and exits

Multi-file window segmentation

Vim-o file1 file2 split horizon

-O vertical segmentation

Ctrl+w+ Arrow

Single file window segmentation

Ctrl+w+s split horizon toggles windows in ctrl+w+ direction

Ctrl+w+v vertical division toggles the window in the direction of ctrl+w+

Custom vim

Display line number: set nu

Do not display line number: set nonu

Parentheses match set sm

Set no sm

Auto indent set ai

Set noai

Highlight search set hlsearch

Set nohlserch

Syntax coloring syntax on

Syntax off

Ignore character case set ic

Set noic

: help

Vim Chinese Handbook

Global configuration file for vim / etc/vimrc vim

Personal profile of / ~ / .vimrc vim

Two file search

Locate file search, according to the index search, new files may not be found, fast search speed, fuzzy search

The index is built automatically (periodic tasks) when the system is idle, and the database is updated manually (updatedb)

Find file search, real-time search, slow search speed, accurate search

Find [- H] [- L] [- P] [- D debugopts] [- Olevel] [path...] [expression]

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

The find path defaults to the current path

Search criteria specify search criteria. All files under the specified path can be specified by default according to file name, size, owner, type, etc.

What the processing action does to the qualified file, which is output to the screen by default.

Search condition

Search based on the file name

-glob is supported for name filename

*? []

-iname filenames are case-insensitive and glob is supported.

-regex "PATTERN" matches the entire file path string with PATTERN. Not male is the file name.

Find / tme-user centos find / tmp-user centos-ls find / tmp-group centos-ls

Search according to the owner and group.

-user username

-group groupname

-uid useruid

-gid usergid

-nouser has no documents from the owner.

-nogroup has no files belonging to the group

Root file type lookup

-type TYPE

F ordinary file

D directory file

L symbolic connection file

B block equipment

C character device file

P command pipeline

S socket file

Find / tmp-type s-ls

Combined search condition

Non-conditional-notBary!

And condition-a

Or condition-o

Find-type f-a-nouser-ls find / tmp\ (- nouser-o-user marion\)-ls find / etc!-name "* .conf"

! a-o! B =! (a-a-B)

! a-a! B =! (a-o B)

Find / etc-not-name "a.conf"-a-not-type f-ls find / etc-not\ (- name "a.conf"-o-not-type f)-ls

Find based on file size

-size [+ | -] # UNIT

Unit k M G

# UNIT (+-1)

+ UNIT (#, + OO)

-UNIT [0cr]

Find / etc-size-3k

Find it in time

In days

-atime [+ | -] n accessed 24 hours ago

-mtime [+ | -] n modified 24 hours ago

-ctime [+ | -] n changed 24 hours ago

Find / etc-mtime-3-ls

In minutes

-amin [+ | -] n accessed n minutes ago

-mmim [+ | -] n modified n minutes ago

-cmin [+ | -] n changed n minutes ago

According to the authority

-perm [/ | -] MODE

MODE exact permission matching

/ MODE any one of the permissions of any type of object (umai gjino) can be met, implied or conditional, and any of the three types of conditions can be met

-MODE every permission specified by each type of object (uquoise gjino) must be generous or qualified, implied and conditional at the same time.

Find. /-perm / 22-ls find. /-perm-22-ls

Processing action

-print: display to the screen by default

-ls

-delete

-fls / path/to/somefile

-ok COMMAND {}\; ask the user to confirm before executing each file

-exec COMANND {}\; the execution of the file does not require user confirmation

Find. /-perm-exec ls-lh {}\; find. /-perm-003-exec chmod Omurw {}\; find. /-not-perm / 111-ls find. /-not-perm / 111-exec mv {}. Old\

3. Configuration of bash environment

Man bash

Configuration file

Global configuration file / etc/profile / etc/profile.d/*.sh

/ etc/bashrc

Personal profile ~ / .bash_profile

~ / .bashrc

Profile class

Function defines environment variable

A command or script that runs

Bashrc class

Function custom command alias

Define local variables

Pstreesetenvprintenvexport

Unset variable name cancel variable

$variable name reference variable

'' mandatory, variable substitution will not occur

"" weak reference

``command reference

Ls-l `which cat`

Shell login type

Interactive login

Login through the terminal

User handoff through su-l command

Non-interactive login

Command line window opened under the graphic interface

Execute script

The priority after the order of action of the configuration file is higher than the previous priority.

Interactive login:

/ etc/profile-- > / etc/profile.d/*.sh-- > ~ / .bash_profile-- > ~ / .bashrc-> / etc/bashrc

Non-interactive login

~ / .bashrc-- > / etc/bashrc-- > / etc/profile.d/*.sh

The edited profile defines the effective method

Log in again

Let the current shell process reread the specified configuration file

Source / path/to/somefile

. / path/to/somefile

Note: side effects: each read will append the contents of the configuration to the environment, resulting in duplicate configuration

Special permissions on the Linux file system

The security context of the process

The process has a group (as which user the process runs)

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

(2) after the program starts as a process, the owner of the process is the current user, and the group to which the process belongs is the basic group of the initiator.

(3) the access rights of a process depend on the access rights of its owner.

The owner of the process is the same as the owner of the file, and the file belongs to the master permission

The owner of the process belongs to the file's subordinate group, and the file belongs to the group permission.

In other cases, apply other permissions

Whether the SUID user starts an executable file as a process depends on whether the user has the right to execute the program file.

When any user executes the program as a process, the program is the owner initiator of the program

Chmod Utility / tmp/cat

Be careful

S owner originally did not have x permission

S owner used to have x permission

SGID by default, a user creates a file whose group is the basic group to which this user belongs

Once the SGID permission is set in a directory, the group of files created by the user with write permission in this directory is the group of the directory, not the basic group of the user who created it.

Chmod gears / tmp/test/

Be careful

S group originally did not have x permission.

S group used to have x permission

Sticky is used for multiple writable directories. This permission is used to restrict that each user can only delete permissions whose ownership is their own.

Chmod file chmod Odyst / tmp/test

SUID SGID STICKY

0 0 0

Chmod 4777 file

5. Linux disk management and file system

Identify the hard drive / dev/sd#

Mark different hard disk devices / dev/sd [a -]

Mark different partitions on the same device / dev/sd [a Murz] [1 -]

1-4: primary or extended partition identification

5neighbors: logical partition identification

Device files special files

Device number

Major,minor

Major device Typ

Different devices under the same type of minor

The block device is identified as b random access device

Character device marked as c linear device

GPT

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

Zoning tool

Fdisk parted sfdisk

Fdisk 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:

CentOS 5: partprobe [DEVICE]

CentOS 6,7: partx kpartx

Partx command:

Partx DEVICE

Partx-a DEVICE

Partx-a-n MRU N DEVICE

M

M:

: N

Kpartx command:

Kpartx-af DEVICE

Partx-a-n 4:5 / dev/sda kpartx-af / dev/sda

File system management

File system VFS Virtual File System

Linux: ext2 ext3 ext4 btrfs swap

Unix: xfs ffs ufs jfs jfs2

CD: ISO9660

Win: fat32/vfat ntfs

Network file system: net nfs cifs

Cluster file system: ocfs2 gfs2

Distributed file system: ceph moosefs mogilefs hdfs gfs glusterfs

Log file system ext3

Non-journaling file system ext2

Swap partition swap

Create a file system

Perform formatting on partitions (advanced formatting)

To use a file system, two conditions are met:

This file system is supported in the kernel

There are file system management tools in user space

Creation tool: mkfs (make filesystem) mkfs-t type DEVICE

Mkfs.ext4

Fsck

Fsck.ext4

Special management tool for ext series file system: mke2fs-t ext2 | ext3 | ext4 DEVICE

Blkid / dev/sda5 displays the details of the file system

Practice

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

Cp / etc/grub2.cfg / tmp/ vim / tmp/grub2.cfg:% s @ ^ [[: space:]] @ @ g: 1 space / ^ [[: space:]] / g:% 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

Cp / etc/rc.d/init.d/functions / tmp/ vim / tmp/functions:% s @ ^ [[: space:]] @ # & @ g

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

Vim / 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

Vim / tmp/functions:% s @ ^ #\ ([[: space:]]\ +\) @\ 1roomg

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

Find / var-user root-a-group mail-ls

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

Find / usr-not\ (- user root-o-user wang-o user hadoop\)-ls

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

Find / etc-mtime-7-a-not\ (- user root-o-user hadoop\)-ls

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

Find / etc-atime-7-a-not\ (- nouser-o-nogroup\)-ls

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

Find / etc-size + 20k-a-type f-ls

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

Find / etc-not-perm / 222-ls

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

Find / etc-not-perm-111111-ls

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

Find / etc/init.d-perm / 111a-perm / 002-ls

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

Cp / bin/cat / tmp chmod Utility / tmp/cat su-hadoop / test/cat shadow

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

Mkdir-p / test/data chmod glossy wrxs test/data or chmod 3777 data

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