1. Permissions 1.1 View Permissions
You can see the details of a file by using the Ls-l command
Here is a message explaining the role of each position character
-rwxr--r--. 1 root root 32 June 10:15 choose.sh
(1) 0-9-bit description:
- No. 0 bit determine file type (-: Normal file, D: directory, L: Soft link, C: Character device, such as keyboard, mouse, B: Block file, hard disk)
- 第1-3位 determines the owner (the owner of the file) has permission to the file--user
- 第4-6位 determines the permissions of the owning group (the same user group) that owns the file-group
- 第7-9位 determine the permissions that other users have on the file--other
(2) 1
If it is a file, the number of hard links, or if it is a directory, indicates the number of subdirectories
(3) root root
File owner, the group to which the file belongs User Group
(4) 32
File size, if the directory is 4096
(5) June 18 10:15
Last modification time
(6) choose.sh
File or directory Name
1.2 rwx Permissions 1.2.1 rwx permissions detailed 1.2.2.1 rwx action to file
- [R] stands for readable (read): can read , view.
- [W] for Writable (write): can be modified , but does not mean that the file can be deleted, deleting a file if you have write permission to the directory where the file is located in order to delete the file.
- [x] Represents an executable (execute): can be executed.
1.2.1.2 rwx effects to the directory
- [R] stands for readable (read): can read,ls view directory contents.
- [W] stands for writable (write): can be modified , directory creation + DELETE + Rename directory.
- [x] stands for executable (execute): The directory can be entered.
1.2.2 Modify Permissions--chmod1.2.2.1 Change permissions by +,-,=
Read Execute permissions to the owner of the ABC file , read execute permission to the group, and execute permissions to other groups
[[email protected] myDir] # chmod U=RWX,G=RX,O=RX ABC [[email protected] myDir] # ls-l Total dosage 4-rwxr-xr-x. 1 root root 8 June 15:44 ABC
Remove the execute permission for the owner of the ABC file and increase the permissions for the group write
[[email protected] myDir] # chmod u-x,g+w ABC [[email protected] myDir] # ls-l Total dosage 4-rw-rwxr-x. 1 root root 8 June 15:44 ABC
Add Read permissions to all users of the ABC file
[[email protected] myDir] # chmod a+r ABC [[email protected] myDir] # ls-l Total dosage 4-rw-rwxr-x. 1 root root 8 June 15:44 ABC
1.2.2 Changing permissions by number
Rule: r=4 w=2 x=1
Read Execute (r+w+x=4+2+1=7) permissions to the owner of the ABC file, read execute (r+w=4+1=5) permissions to the group, and the other group reads execution (r+w=4+1=5) permissions
[[email protected] myDir] # chmod 755 ABC [[email protected] myDir] # ls-l Total dosage 4-rwxr-xr-x. 1 root root 8 June 15:44 ABC
1.3 Modifying the file owner--chown
Modify file ABC owner to Zang
[[email protected] myDir] # chown Zang ABC [[email protected] myDir] # ls-l Total dosage 4-rwxr-xr-x. 1 Zang Root 8 June 15:44 ABC
Change the owner of all files and directories in the/home/testshell directory to Zang
[[email protected] home] # chown-r Zang testshell/ [[email protected] home] # CD testshell/ [[email protected] Testshell] # ls-l Total dosage 16-rwxr--r--. 1 zang Root 32 June 10:15 choose.sh-rw-r--r--. 1 zang root 299 June 10:20 menuchoosedrwx R-xr-x. 2 Zang root 4096 June 15:44 myDir-rwxr--r--. 1 zang Root 37 June 15:42 myshell.sh-R W-r--r--. 1 Zang root 0 June 23:15 test.sh
1.4 Modifying a user's group--chgrp
Modify file ABC User Group is Zang
[[email protected] myDir] # chgrp zang/home/testshell/mydir/abc [[email protected] myDir] # ls-l Total dosage 4-rwxr-xr-x. 1 Zang Zang 8 June 15:44 ABC
Modify all of the files and directories in the/home/testshell directory to Zang
[[email protected] home] # chgrp-r Zang testshell/ [[email protected] home] # CD testshell/ [[email protected] Testshell] # ls-l Total dosage 16-rwxr--r--. 1 zang Zang 32 June 10:15 choose.sh-rw-r--r--. 1 zang zang 299 June 10:20 menuchoosedrwx R-xr-x. 2 zang zang 4096 June 15:44 MyDir
2. Task Scheduling
Task scheduling: Refers to a particular command or program that the system executes at a certain time.
Task Scheduling Classification:
- System work: Some important work is performed on a recurring cycle. such as virus scanning, etc.
- Individual users work: Individual users may want to perform certain programs, such as a backup of a MySQL database
With the crontab to set the scheduled tasks, simple tasks can be added directly in the crontab, complex tasks need to write scripts, through the crontab to call the script timed.
2.1 Task Scheduler command--CRONTAB [options]2.1.1 crontab Common options
Crontab common options are as follows:
- -E: Editing crontab timed tasks
- -L: Query crontab task
- -R: Delete all crontab tasks for the current user
2.1.2 Task Scheduling Setup Step 1) Edit Task Scheduling task
[[email protected] taskdir] # crontab-e
Enter will jump out of the Edit VI interface where you can edit a simple dispatch task
*/1 * * * * ls-l/etc >>/home/taskdir/lslog.txt
2) Save exit automatically execute schedule
[[email protected] taskdir] # crontab-e for Root- using a empty onecrontab:installing new Crontab[[email protected] Taskdir]# da TeJune 24, 2018 Sunday 18:32:50 cst[[email protected] Taskdir]# lslslog.txt[[email Protected] Taskdir]#total 2480drwxr-xr-x. 3 root root 4096 abrtdrwxr-xr-x. 4 root root 4096 ACPI
···
The use of the other two options
[[email protected] taskdir] # crontab-l*/1 * * * * ls-l/etc >>/home/taskdir/lslog.txt[[email protected] Taskdir]# c4> crontab-r[[email protected] taskdir]# crontab-l for Root
2.2 Task-defined parameters
*/1 * * * * ls-l/etc >>/home/taskdir/lslog.txt
Description of the five placeholders
Description of placeholder Parameters
Perform a task case at a specific time
2.3 Task Scheduler Call script
2.3.1 Every 1 minutes, append the current date and calendar to the/home/taskdir/datelog.txt file
[[email protected] taskdir]#ls[[email protected] taskdir]#pwd/home/Taskdir[[email protected] Taskdir]#Vim datetask.sh[[email protected] taskdir]#Cat datetask.shDate >>/home/taskdir/datelog.txtcal>>/home/taskdir/Datelog.txt[[email protected] Taskdir]#chmod 744 datetask.sh[[email protected] taskdir]#crontab-eNo crontab forRoot-using an empty onecrontab:installing new Crontab[[email protected] Taskdir]#crontab-l*/1 * * * */home/taskdir/Datetask.sh[[email protected] Taskdir]#DateJune 24, 2018 Sunday 19:04:37Cst[[email protected] Taskdir]#ls-lTotal dosage 8-rw-r--r--. 1 root root 177 June 24 19:04Datelog.txt-rwxr--r--. 1 root root 67 June 24 19:03Datetask.sh[[email protected] Taskdir]#Cat Datelog.txtSun June 19:04:01 CST 2018June2018Su Mo Tu We Th Fr Sa1 2 3 4 5 6 7 8 910 11 12 13 14 15 1617 18 19 20 21 22 23
2.3.2 MySQL database TestDB, back up to file Mydb.bak daily 2:00
[[email protected] taskdir] # Vim backup_mysql.sh [[email protected] taskdir] # /usr/local/mysql/bin/mysqldump -uroot-p123 testdb >/tmp/mydb.bak[[email protected] taskdir] #[[email protected] taskdir]# crontab-ecrontab:installing New crontab [[email protected] taskdir] # crontab-l*/1 * * * */home/taskdir/2 * * * /home/taskdir/backup_mysql.sh
3. Disk partition 3.1 partition type
The MBR (Master Boot Record) and GPT (GUID Partition Table) are two different ways to store partition information on disk. These partition information contains information about where the partition started, so that the operating system knows which sector belongs to which partition and which partition is bootable. When you create a partition on a disk, you must make a selection between MBR and GPT.
Two partitioning methods differentiate the MBR partition:
- Supports a maximum of four primary partitions
- System can only be installed on primary partition
- Extended partition to occupy one primary partition
- MBR supports only 2TB, but has the best compatibility
GPT partitions:
- Supports an unlimited number of primary partitions (but the operating system may be limited, such as up to nine partitions under windows)
- Large capacity of 18EB (1eb=1024 pb,1pb=1024 TB ) maximum support
- Windows7 support GTP after
With stronger robustness and greater compatibility, the GPT partitioning approach is gradually replacing MBR partitioning.
3.2 Drive Description
Linux hard disks are divided into IDE hard disks and SCSI hard drives, which are basically SCSI drives.
- For IDE hard drives, the drive identifier is "hdx~", where "HD" indicates the type of device on which the partition is located, which refers to the IDE hard disk. "X" is the disk number (A is the base disk, B is the base slave, C is the secondary primary, D is the secondary slave), "~" represents the partition, the first four partitions are represented by the numbers 1 to 4, they are the primary partition or the extended partition, and the logical partition starts at 5. Example, Hda3 is represented as the third primary or extended partition on the first IDE hard disk, and HDB2 is represented as the second primary or extended partition on the second IDE hard disk.
- The SCSI hard disk is identified as "sdx~", the SCSI hard disk is "SD" to indicate the type of device the partition is located in, the rest is the same as the IDE hard disk representation.
3.3 Linux Partitioning principle
Linux, no matter how many partitions, to which directory to use, it boils down to only one root directory, a separate and unique file structure, Linux each partition is used to form a part of the entire file system.
Linux uses a processing method called "Loading", which contains a full set of files and directories in the entire file system, and links a partition to a directory. At this point a partition to be loaded will make its storage space available in one directory.
3.4 Common partition Commands--lsblk view system partitions--lsblk
3.5 Mounting--mount
The actual work, when the hard disk capacity is not enough, can be mounted to achieve additional hard drives, thereby increasing the system capacity. The following is a demonstration by adding a piece of 2GB of disk space to this machine.
Operation Steps:
(1) in the "Virtual Machine" menu, select "Settings", then the device list to add the hard disk, and then all the way "next", in the middle only select the size of the disk where the need to modify, until completed.
It needs to be restarted to be recognized after it is added.
The disk is not partitioned and is not formatted at this time.
(2) Partitioning
Fdisk/dev/sdb
(3) Formatting
Mkfs-t EXT4/DEV/SDB1
Generates a UUID that represents a partition after formatting
(4) Mounting
Mount/dev/sdb/opt
Note: Files in the/OPT directory will be temporarily deleted after mounting, so choose to create a new folder to mount
(5) The above method is only temporary mount, the next boot will not be automatically mounted, to permanently mount the/etc/fstab file can be edited
Vim/etc/fstab
Add the following line
/DEV/SDB1 /opt/newdisk ext4 defaults 0 0
Immediate effect
Mount-a # Hang up all the file systems defined in/etc/fstab
You can see the disk mounted after rebooting
3.6 Uninstalling--umount
Unmount a partition mount
Umount/opt/newdisk # unmount the partition, after unloading, can actually be mounted, and the data will be in the
Delete Partition Fdisk/dev/sdb, follow the instructions
fdisk/dev/sdb m d
3.7 Disk condition Query--DF & du3.7.1 system Overall disk usage df-h
3.7.2 queries the disk usage of the specified directory Du-h
Grammar:
du [Options] [file]
List only the more common options:
- -A: Displays the size of individual files in the directory.
- -C: Displays the sum of all directories or files in addition to the size of individual directories or files.
- -H: Improve the readability of the information in k,m,g units.
- -S: Displays totals only.
- --max-depth=< directory layer: After the specified number of layers, the directory is ignored.
Such as: Query the/OPT directory disk usage, depth of 1
Common instructions for querying disk conditions in 3.7.3 work
(1) Count the number of files in the /home folder
" ^- " | Wc-l
(2) Count the number of directories under the /home folder
" ^d " | Wc-l
(3) Count the number of files in the/home folder, including subfolders
" ^- " | Wc-l
(4) The number of directories under the statistics folder, including sub-folders
" ^d " | Wc-l
(5) Displaying the directory structure in a tree-like form
Yum Install tree # If the hint tree is not installed, execute the command install Tree# to display the directory structure
Note: Blog focus on real, space reasons, not deep digging command, if the understanding of the command has doubts, can go to the Linux command Daquan query.
(i) Linux implementation--permissions, task scheduling, disk partitioning