8.30 Vim Editor file Find file System jobs (practice)

Source: Internet
Author: User
Tags define local readable disk usage line editor

Vim Editor:

Full-screen editor: VIM

Vi:visual interface

Sed: line Editor

VI, VI improved

Vim:

Pattern:

Edit mode: Command mode

Input mode:

Last-line mode:

Edit mode--Input mode:

I:insert,

A:append,

O:new Line,

I: The beginning of the line

A: End of line

O: Above New CCB

Input mode--edit mode:

Esc

Edit mode--and last-line mode:

:

Last-line mode--edit mode

Esc

1, summarize the text editing tool vim use method;

Open VIM:

# VIM

# Vim/path/to/somefile

+#: #为行号;

+/pattern

Turn off VIM:

: Q

: q!

: Wq

: X

ZZ: Save exit

Cursor Jump:

Jump between characters:

H:

L

J:

K:

#COMMAND:

Jump between words:

W: The first word of the word

E: The ending of the current or subsequent word;

B: The first word of the current or previous word;

#COMMAND:

In-line jump:

^: jumps to the first non-whitespace character at the beginning of a line;

0: Jump to the beginning of the line;

$: Jump to end of line;

Move between rows:

#G:

1G, GG

G

Move between sentences:

)

(

Move between paragraphs:

}

{

Edit command:

Character editing:

X: Delete the character at the cursor location

#x:

Xp:

R: replaces the character at which the cursor is located;

Delete command:

D:

d^

d$

D0

DW, DE, DB

Dd:

#COMMAND

Note: The deleted content will be saved to the buffer by the Vim editor;

Paste: P (paste, put)

If this copied or deleted content is not a full line

P: Paste at the back of the current cursor;

P: Paste at the front of the current cursor;

If the copied content is a full row (more than one line)

P: Paste below the line where the current cursor is located;

P: Above line;

Copy command: Y, yank

Y

y$, y^, y0

Ye, yw, yb

YY: Copying rows

#COMMAND

Changing the command: C, change

C $, c^, C0

CB, CE, CW

Cc:

#COMMAND

To undo a previous edit operation:

U:undo

Undo the previous edit operation;

#u

Ctrl+r:

Redo the previous undo operation

.: Repeats the previous edit operation

Turn screen operation:

Ctrl+f: one screen backward;

Ctrl+b: one screen ahead;

Ctrl+d: Back half screen

Ctrl+u: Forward half screen

Vim built-in tutorials:

Vimtutor

Vim's last-line mode

(1) Address, delimitation

: Start_pos,end_pos

#: Line #;

#,#

#,+#

.: When moving forward

$: Last line

%: Full text, equivalent to 1,$

/PAT1/: The first time the line is matched to this pattern;

#,/pat1/

/pat1/,/pat2/

After you can follow the edit command:

D, y

W, R

(2) Find

/pattern: to the tail

? PATTERN: To the header

N: Same direction as command

N: Opposite direction of command

(3) Find and replace

S: In the last line mode, the search and replace operation is done within the bounds of the address;

s/what to look for/replace with content/modifiers

What to look for: Available modes

What to replace: You cannot use a pattern, but you can use a back reference symbol to refer to what the grouping brackets in the preceding pattern match to;

\1, \2, ...

&: Refers to the entire content of the "What to find" matches;

Modifier:

I: Ignore case

G: Global Substitution

/: Used for delimiters, so, to find the content or replace with the content that appears in this symbol, to use \ to escape it, use format: \/

The delimiter can be replaced with other characters: @, #等, for example;

Multi-file Mode:

Vim FILE1 FILE2 ...

: Next

: First

:p Rev

: Last

: Wqall

: Q!all

Multi-File Window segmentation:

Vim-o|-o FILE1 FILE2 ...

Ctrl+w, ARROW

Single File Window segmentation:

Ctrl+w, S:split, horizontal split

Ctrl+w, v:vertical, vertical split

Some of the working features of the custom vim:

(1) Line number

Display: Set Nu

Disabled: Set Nonu

(2) Bracket matching

Display: Set SM

Disabled: Set NOSM

(3) Auto indent:

Set AI

Set Noai

(4) Highlight Search

Set Hlsearch

Set Nohlsearch

(5) Syntax coloring

Syntax on

Syntax off

(6) Ignore character case

Set IC

Set Noic

: Help for assistance

: Help SUBJECT

The permanent effect of the feature setting is as follows:

Global configuration file:/ETC/VIMRC

User profile: ~/.VIMRC

2, summarize the document Search command find use method;

Linux File Lookup:

Locate: Non-real-time lookup, according to the database (fast); Fuzzy search;

Find: Real-time search, exact match, slow speed;

Find [Find location] [find standard] [processing action]

Find Location: Default view current directory;

Lookup criteria: The default is to find all files under the specified directory;

Processing action: Display to standard output;

Find criteria:

-name "file name": Find the file exactly based on the file name.

Support Glob, *, [],?

-iname "file name": Find by file name, character case insensitive; name Ignore case

-user USERNAME: According to the owner of the search;

-group GRPNAME: Search according to genus Group;

-uid uid; #按照Uid to find

-gid GID; #按照gid来查找

-nouser: Find files that are not owned by the master;

-nogroup: Find files without a group;

Combination Lookup criteria:

-A: With

-O: Or

-not,!: Non-

3, summarize the content of bash environment variable;

Bash Environment configuration:

configuration file, the scope of effective, there are two categories:

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 the interactive logon shell

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

~/.bash_profile

Function:

(1) Define environment variables, such as path, PS1

(2) run a command or script

BASHRC class: Provides configuration for non-interactive logon 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 variables: scoped only to a snippet of code in the current shell process (usually a function context)

Position variable: $ $, $

Special variables: $?

How variables are defined:

Bash built-in variables: can be called directly, built in a number of environment variables, such as Path

Custom variables:

Variable assignment: variable name = value

Bash Weak type:

When a variable stores data, it is written by default, and any variable can be directly referenced without being declared;

120:24bits

120:8bits

To define a local variable:

Name=value

View: Set

Define Environment variables:

Export Name=value

Declare-x Name=value

View: env, printenv, export

Undo Variable:

unset name

Reference variable:

${name}, $name

Reference symbols in bash:

': Strong reference, variable substitution does not occur

"": Weak reference

": Command Reference

Shell Logon Type:

Interactive login:

Login directly through the terminal;

User Switching implemented by su-l username command;

Non-interactive logon:

A command-line window opens under the graphical interface;

Execute the script;

Su Username;

Configuration file Action Order:

Interactive login:

/etc/profile--/etc/profile.d/*.sh--and ~/.bash_profile--~/.BASHRC--/ETC/BASHRC

Non-interactive logon:

~/.BASHRC--/ETC/BASHRC-/etc/profile.d/*.sh

How does the new configuration of the Edit profile definition take effect?

(1) Re-login;

(2) Let the current shell process to re-read the specified configuration file;

Source/path/to/somefile

. /path/to/somefile

Note: Side effects

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

Special permissions on the Linux file system

Permission model:

U, G, O

R, W, X

Security context for the process:

Prerequisite: The process is owned by the owner (the process is running as the user's identity);

(1) Whether the user can start an executable program file as a process, depending on whether the user has Execute permission on the program file;

(2) After the program is started as a process, the owner of the process is the current user, the initiator of the process, the group to which the process belongs, and the base group for the initiator;

(3) The access rights of the process, depending on the owner's access rights:

(a) The owner of the process and the owner of the document, the application document is the master authority;

(b) The owner of the process, belonging to the group of documents, the application file is a group of permissions;

(c) Apply other rights;

SUID:

(1) Any executable program file can be started as a process: depending on whether the initiator has EXECUTE permission on the program file;

(2) After initiating as a process, its owner is not the initiator, and the program file is the owner of its own, the mechanism is suid;

Permission settings:

chmod u+s FILE ...

chmod u-s FILE ...

Attention:

S: The owner of the original X permission;

S: The original owner has no x permission;

SGID:

By default, when a user creates a file, it belongs to the base group that the user is a member of;

Once a directory has been set with Sgid permissions, the user who has write permission to this directory has the same group as the directory, not the user's base group, to which the files created in this directory belong.

Permission settings:

chmod g+s FILE ...

chmod g-s FILE ...

Sticky:

For a multi-person writable directory, this permission is used to restrict each file that can only delete itself;

Permission settings

chmod o+t FILE ...

chmod o-t FILE ...

SUID, SGID, STICKY

000

001

010

11P

100

101

110

111

chmod 4777 FILE

chmod 3755 DIR

5, summarize the Linux Disk Management, file system related knowledge points and the use of related commands;

Linux System Management

Disk and file system management;

RAID, LVM; Btrfs

Package management: RPM, yum (DNF)

network management of Linux;

Process and Job Management: Htop, glances, tsar;

Sed and awk;

Linux system boot-up process;

Kernel basic knowledge, kernel custom compile;

System installation: Kickstart, PXE

Linux Disk Management

Hard disk:

Mechanical hard-disk

Ssds

Mechanical type:

Track

Sector:512bytes

Cylinder: The basic unit of the partition;

Mbr:master Boot Record

512bytes

446:bootloader

64:filesystem Allocation table

16: Identify a partition

2:55aa

Disk interface type:

IDE (ATA): 133MB/S,/DEV/HD

scsi:640mb/s

sata:6gbps

sas:6gbps

usb:480mb/s

Identify the hard drive device:/DEV/SD

Mark a different hard drive device:/dev/sd[a-z]

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

1-4: Primary or extended partition identification

5 +: Logical partition identification

Device Files: Special files

Device number:

Major, minor

Major: Device type

Minor: Different devices under the same type

"Block": block, Random device

"Character": Character, linear device

Gpt

Partitioning: Separates the storage space into multiple small spaces, each of which can use the file system independently;

Partitioning tools:

Fdisk, parted, Sfdisk

Use of the Fdisk tool:

Support for up to 15 partitions on one hard drive;

Partition Management sub-command:

P: Display

N: Create

D: Delete

T: Modify the partition ID

L: List all support 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 identified 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 m:n DEVICE

M

M:

: N

KPARTX command:

Kpartx-af DEVICE

Linux File System Management

File system:

Vfs:virtual File System

Linux:ext2, Ext3, Ext4, ReiserFS, XFS, Btrfs, swap

Disc: iso9660

Windows:fat32 (VFAT), NTFS

Unix:ffs, UFS, JFS, JFS2

Network File System: NFS, CIFS

Cluster file system: OCFS2, GFS2

Distributed File systems: Ceph,

Moosefs, MogileFS, HDFs, GFS, Glusterfs

(1) journaled file system

Non-journaled file system: ext2

journaled File System: ext3

(2) Swap: Swap partition

To create a file system:

Perform formatting on a partition (advanced formatting)

To use a file system, two conditions are met:

Kernel: Support for this file system

User space: There are file System management tools

Create tool: Mkfs (make filesystem)

MKFS-T type DEVICE

Mkfs.type DEVICE

Special management tools for the EXT series file system:

mke2fs-t {EXT2|EXT3|EXT4} DEVICE

-B block:1024, 2048, 4096

-L ' LABEL ': Set volume label

Blkid command:

Blkid DEVICE

LABEL, UUID, TYPE

Linux File System Management:

MKFS, mkfs-t type = Mkfs.type

Ext:mke2fs

To create a file system:

MKE2FS [OPTION] ... DEVICE

-T {EXT2|EXT3|EXT4}

-B {1024|2048|4096}

-L ' LABEL '

-j:mke2fs-t ext3

-I. #:

-N #:

-M #: Reserved disk space occupies a large percentage of space for post-management use;

-O feature[,...]

-O ^feature: Turn off this attribute

Has_journal

File System Properties View and adjustment tools:

E2label

E2lable DEVICE [LABEL]

Tune2fs

Displays the properties of the Ext series file system, or adjusts its properties;

-L: Displays information in the Super block, and displays information about the properties and layout of the entire file;

-L ' LABEL ': Modify the volume label;

-M #: Adjust the percentage of administrative space reserved to administrators;

-J:EXT2-Ext3

-O: File System Properties start or close

-O: File system default mount option enabled or closed

DUMPE2FS:

-H: Displays only the Super block information;

File System Detection:

Fsck:filesystem Check

FSCK-T type

Fsck.type

-A: Auto fix error

-r: Interactive fix error

-F: Force detection

E2fsck:ext Series file system-specific detection and repair tools;

-Y: Auto Answer "yes"

-f:force

File system mount and use:

Kernel--ROOTFS (partition)

ROOTFS Partition:

Bin, Sbin, etc, Lib, lib64, Dev, tmp, proc, SYS

/sbin/init

The additional file system is associated with an existing directory of the root file system, which makes this directory the behavior of accessing the portal as other file systems, called Mount;

The process of releasing this association: uninstall;

Mount points: mount point, device mounted to directory;

Note: After the mount point is mounted, its internal files are temporarily hidden, and an empty directory is used as the mount point;

Mount Method:

Mount: Displays all devices that are already mounted on the current system by reading the/etc/mtab file;

MOUNT-A: Mounts all file systems in the/etc/fstab file that support automatic mounting;

mount [Options] [-o options] DEVICE mount_point

[Options]: Command options

[-O options]: Mount options

Device: Devices to be mounted

(1) Device file:/dev/sda5

(2) Volume Label:-L ' LABEL '

(3) uuid:-u ' UUID '

(4) pseudo file system name

Mount_point: Mount point

Common options:

-T type: File system type

-r: Mount this file system as "read-only" mode

-W: Mount this file system in read-write mode

-N: Each file system will automatically update the/etc/mtab file when it is mounted,-n is used to prohibit this function;

At this point, if you want to view all the file systems that are mounted: cat/proc/mounts

-A: Automatically mount all devices that support automatic mounting;

-B: Bind the directory to another directory;

-O mount option:

Async: Async Mode

Sync: Synchronous mode

Atime/noatime: Whether to update the access timestamp;

Diratime/nodiratime: Whether to update the access timestamp of the directory;

Auto/noauto: Whether this device is allowed to be automatically mounted;

Exec/noexec: Whether the application is allowed to execute on this file system;

Dev/nodev: Whether to support the use of device files on this device;

Suid/nosuid:

Remount: Re-mount

Ro

rw

User/nouser: Is it permissible to mount the device normally;

ACL: whether to support the use of FACL on this device;

DEFAULTS:RW, suid, Dev, exec, auto, Nouser, and Async

Umount: Uninstall command

# Umount DEVICE

# Umount Mount_point

To view the process that is accessing the specified mount point:

# fuser-v Mount_point

Terminates all processes that are accessing the specified mount point:

# fuser-km Mount_point

Swap partition:

Free command:

View the usage status of memory and swap

-M: in megabytes

-G: in gigabytes

Mkswap: Creating Swap partitions

mkswap [option] DEVICE

-L ' LABEL '

Swapon: Enable swap partition

swapon [option] [DEVICE]

-A: Activate all swap partitions

-P Priority: set its precedence;

Swapoff: Disable swap partition

swapoff [option] [DEVICE]

A view of space occupancy information such as file systems:

Df:disk Free

-h:human-readable

Number of-i:inode

-P: Output in POSIX-compatible format

Du:disk usage

-h:human-readable

-s:summary

File system-related Mount profile:/etc/fstab

Each row defines a file system;

Device to mount or pseudo file system mount point file System type Mount options dump frequency self-test order

Devices to mount:

Device files, label=, uuid=, pseudo file system names

Mount Options:

Defaults

Dump frequency:

0: No dumps

1: Daily dumps

2: Dump every other day

Self-Test order:

0: No self-test

1: First self-test, usually only/only 1

2:

...

Linked files on the file system:

Hard Links:

Two paths pointing to the same inode

cannot be performed on the directory;

cannot be done across partitions

Multiple different paths pointing to the same inode; Creating a hard link to a file increases the reference count of the inode; deleting a hard link deletes only one of its access paths, and only the last path is deleted;

Symbolic Links:

The data of the linked file points to another file path;

Can be done to the directory;

can span partitions;

Point to another file path, not an inode;

Creating a symbolic link to a file does not increase its reference count, and deleting the original file will not make the symbolic link file.

ln [-S] SRC DEST

-s:symbolic Link

-v:verbose

6, copy the/etc/grub.cfg configuration file to the/tmp directory, use the Find replacement command to delete the/tmp/grub.cfg file at the beginning of the blank character;

%s/^[[:space:]]\+//g

7. Copy the/etc/rc.d/init.d/functions file to the/tmp directory, and add a # to the beginning of the line beginning with a blank character for each line of/tmp/functions with the find replacement command; The original whitespace character is reserved;

%s/^[[:space:]]/#&/g

8, replace the/etc/sysconfig/init in/tmp/functions file is/var/log;

%s/\etc\sysconfig\init//var/log/g

9. Delete the beginning of the line in the/tmp/functions file so #, and # followed by at least one blank character #;

%s/^#[[:space:]]\{1,\}+//g

10, find the/var directory is the owner of the root, and belong to the group mail all files;

Find/var–user Root–a Group Mail-ls

11. Find all files that are not root, bin or hadoop under the/usr directory;

Find/usr-not-user root-o-user bin-o-user Hadoop

12. Find all files whose contents have been modified and are not root or Hadoop for the last week in/etc directory;

Find/etc-mtime-7-a-not-user root-a-not-user Hadoop

13. Find all files on the current system that are not owned by the master or group, and have been visited in the last week;

Find/-not-nouser-o-nogroup-a-atime 7

14. Find all files that are larger than 20k and type ordinary files in/etc directory;

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

15, look for all the users in/etc directory do not have permission to write files;

Find/etc-not-perm +222

16. Find at least one class of users who do not have permission to execute files in/etc directory;

find/etc-not-perm-111

17, find/etc/init.d directory, all users have execute permission, and other users have write permission files;

[Email protected] tmp]# find/etc/init.d-perm-111-a-perm-002

/etc/init.d

18, so that ordinary users can use/tmp/cat to view/etc/shadow files;

[Email protected] tmp]# cp/bin/cat/tmp

[Email protected] tmp]# Ll/tmp/cat

-rwxr-xr-x. 1 root root 48568 September 8 12:23/tmp/cat

[Email protected] tmp]# chmod u+s/tmp/cat

[Email protected] tmp]# Ll/tmp/cat

-rwsr-xr-x. 1 root root 48568 September 8 12:23/tmp/cat

[Email protected] tmp]#/tmp/cat/etc/shadow

Root:$6$7eb90rabjrkkbyur$4hceo5yt9xsustbkwvki7yvqbr3akvl5pvtq8zqdtljbjj3twpqo0dt3oq2driawckvxzcob7bkpid0achhus /:16666:0:99999:7:::

Bin:*:15980:0:99999:7:::

Daemon:*:15980:0:99999:7:::

Adm:*:15980:0:99999:7:::

Lp:*:15980:0:99999:7:::

Sync:*:15980:0:99999:7:::

Shutdown:*:15980:0:99999:7:::

Halt:*:15980:0:99999:7:::

Mail:*:15980:0:99999:7:::

Uucp:*:15980:0:99999:7:::

Operator:*:15980:0:99999:7:::

Games:*:15980:0:99999:7:::

Gopher:*:15980:0:99999:7:::

Ftp:*:15980:0:99999:7:::

Nobody:*:15980:0:99999:7:::

dbus:!! : 16666::::::

usbmuxd:!! : 16666::::::

vcsa:!! : 16666::::::

Rpc:!! : 16666:0:99999:7:::

rtkit:!! : 16666::::::

avahi-autoipd:!! : 16666::::::

abrt:!! : 16666::::::

rpcuser:!! : 16666::::::

nfsnobody:!! : 16666::::::

haldaemon:!! : 16666::::::

Gdm:!! : 16666::::::

Ntp:!! : 16666::::::

Apache:!! : 16666::::::

saslauth:!! : 16666::::::

postfix:!! : 16666::::::

pulse:!! : 16666::::::

Sshd:!! : 16666::::::

tcpdump:!! : 16666::::::

wwg8708:$6$80kzeybuntljh3kw$clysqn/gq6dea0qvvp1ex7/ Pzbqd2m2yn70363sh6bfn97ffhq9rth9tcczbt5jlhvwap9lod14jmzjrm53tv1:16666:0:99999:7:::

wufeng_gg:!! : 16673:0:99999:7:::

oracle:!! : 16677:0:99999:7:::

test:!! : 16679:0:90:7:::

Bash:!! : 16684:0:99999:7:::

testbash:!! : 16684:0:99999:7:::

busher:!! : 16684:0:99999:7:::

nologin:!! : 16684:0:99999:7:::

Centos:!! : 16684:0:99999:7:::

user1:!! : 16684:0:99999:7:::

Hadoop:!! : 16685:0:99999:7:::

19, create the directory/test/data, let a group of ordinary users have write permission to it, and all the files created by the group of directories belong to the group, in addition, each user can only delete their own files;

[Email protected] tmp]# Mkdir-pv/test/data

mkdir: The directory "/test" has been created

mkdir: The directory "/test/data" has been created

[Email protected] tmp]# chmod g+ws/test/data

[Email protected] tmp]# Ll/test/data

Total dosage 0

[Email protected] tmp]# ll-d/test/data

Drwxrwsr-x. 2 root root 4096 September 8 13:33/test/data

8.30 Vim Editor file Find file System jobs (practice)

Related Article

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.