Directory
- 1. Change the basic properties of a file
- 2. linux File and directory management
- 3. Linux User and User group management
- 4. Disk Management
- 5. Linux Vi/vim
- 6. Linux View firewall status and turn off command
1. Change the basic properties of a file
Linux system is a typical multi-user system, different users in different positions, with different permissions. In order to protect the security of the system, the Linux system has different requirements for different users to access the same file (including directory files).
(1) Linux file owner and owner group
Command:$ ls -l
(2) changing file properties
1. CHGRP: Change file group
Grammar:chgrp [-R] 属组名 文件名
-R = Recursive change of file group
2, Chown: Change the file owner can also change the file group
Grammar:chown [-R] 属主名 文件名
chown [-R] 属主名:属组名 文件名
3, chmod: Change the file 9 properties
There are two ways to set up Linux file attributes, one is a number and one is a symbol.
Linux files have the basic permissions of nine, respectively, owner/group/others three identities each have their own Read/write/execute permissions.
There are two ways to set up Linux file attributes, one is a number and one is a symbol.
Linux files have the basic permissions of nine, respectively, owner/group/others three identities each have their own Read/write/execute permissions.
r:4(读权限) w:2(写权限) x:1(执行权限)
Basically nine permissions are (1) User (2) group (3) others three identities! Then we can represent three kinds of identities by u, G, O!
In addition, a represents all and all identity! Then the permission to read and write can be written as R, W, x! That is, you can see it in the following way:
chmod u
G
O
A + (join)
-(remove)
= (set) r
W
x file or directory
To modify the Test1 Permissions command:
$ chmod u=rwx,g=rx,o=r test1 // 修改 test1 权限
2. linux File and directory management
We know that the directory structure of Linux is tree-like structure, the top-level directory is the root directory/.
Other catalogs can be mounted to add them to the tree, and they can be removed by lifting the mount.
Before starting this tutorial we need to know what absolute and relative paths are.
- Absolute path:
The path is written by the root directory/write, for example:/usr/share/doc this directory.
Relative path:
The way the path is written, not by/writing, for example, by/usr/share/doc to the bottom of/usr/share/man, can be written as: CD. /man This is how the relative path is written!
2.1 Common commands for working with directories
- LS: List directory
- CD: Switch directories
- PWD: Displays the current directory
- mkdir: Create a new directory
- RmDir: Delete an empty directory
- CP: Copying Files or directories
RM: Remove files or directories
2.2 Linux File Content view
Use the following command to view the contents of a file in a Linux system:
- Cat starts displaying file contents from the first line
- The TAC begins with the last line, and you can see that the TAC is backwards written by cat!
- NL display, the output line number!
- More page-by-page display file contents
- Less is similar to more, but better than more, he can page forward!
- Head's just a few lines.
- Tail only look at the tail a few lines
3. Linux User and User group management
Linux system is a multi-user multi-tasking time-sharing system, any user who wants to use system resources must first request an account from the system administrator and then enter the system as this account.
On the one hand, the user's account can help the system administrator to track the users who use the system and control their access to system resources, and on the other hand can help users organize files and provide security protection for users.
Each user account has a unique user name and a separate password.
When a user types the correct user name and password at logon, they are able to enter the system and their home directory.
To achieve the management of user accounts, the main tasks to be completed are as follows:
- Add, delete and modify user accounts.
- Management of user passwords.
Management of user groups.
3.1 Linux System user account management 1, add a new user account, use the Useradd command
Grammar:useradd 选项 用户名
Parameter options:
- -C Comment Specifies an annotative description.
- The-D directory specifies the home directory, and if this directory does not exist, the-m option can be used to create the master directory.
- The-G user group specifies the user group to which the user belongs.
- -G user Group, user group specifies the additional group to which the user belongs.
- -S Shell file specifies the user's login shell.
-u user number specifies the user's user number, and if you have the-o option, you can reuse the other user's identification number.
2, delete the account, with Userdel command
Grammar:userdel 选项 用户名
Common options: -r
The role is to delete the user's home directory.
3, modify the account
Modify user account is based on the actual situation to change the user's relevant attributes, such as user number, home directory, user group, login shell and so on.
Grammar:usermod 选项 用户名
Common options include-C,-D,-M,-G,-G,-S,-u, and-O, etc., which have the same meaning as the options in the Useradd command, specifying a new resource value for the user.
4, the User password management
An important part of user management is the management of user passwords. The user account has just been created without a password, but is locked by the system, cannot be used, it must be given a password before it can be used, even if a blank password is specified.
Grammar:passwd 选项 用户名
Parameter options:
- -L locks the password, which disables the account.
- -u password to unlock.
- -D make the account no password.
- -F forces the user to modify the password the next time they log on.
3.2 Management of Linux system user groups
Each user has a user group, and the system can centrally manage all users in a single user group. Different Linux systems provide a different set of user groups, as users under Linux belong to a user group with the same name, which is created at the same time as the user is created.
The management of user groups involves adding, deleting, and modifying user groups. The addition, deletion, and modification of a group is actually an update to the/etc/group file.
1. Add a new user group using the Groupadd command.
groupadd 选项 用户组
Parameter options:
- -G GID Specifies the group identification number (GID) of the new user group.
- -O is commonly used with the-G option, which means that the GID of the new user group can be the same as the GID of the user group already in the system.
Instance:$ groupadd -g 101 group2
2. If you want to delete an existing user group, use the Groupdel command.
Grammar:groupdel group1
3. Modify the properties of the user group using the groupmod command.
Grammar:groupmod 选项 用户组
Parameter options:
- -G GID Specifies a new group identification number for the user group.
- The-O is used in conjunction with the-G option, and the user group's new GID can be the same as the GID of the user group already in the system.
- -N New user Group change user group name to new name
4. If a user belongs to more than one user group at the same time, the user can switch between groups of users in order to have permissions from other user groups.
After logging in, the user can switch to another user group using the command Newgrp, which is the target user group. For example:
$ newgrp root
This command switches the current user to the root user group, provided that the root user group is really the user's primary or additional group. Similar to the management of user accounts, the management of user groups can also be done through integrated system management tools.
3.3 System files related to user accounts
There are many ways to accomplish user-managed work, but each of these methods actually modifies the system files concerned.
Information related to users and user groups is stored in some system files, including/etc/passwd,/etc/shadow,/etc/group, etc.
The contents of these files are described below.
1,,, etc/passwd files are the most important document that the user manages the work to involve.
Each user in the Linux system has a corresponding record line in the/etc/passwd file, which records some of the basic properties of the user.
# cat /etc/passwdroot:x:0:0:Superuser:/:daemon:x:1:1:System daemons:/etc:bin:x:2:2:Owner of system commands:/bin:sys:x:3:3:Owner of system files:/usr/sys:adm:x:4:4:System accounting:/usr/adm:uucp:x:5:5:UUCP administrator:/usr/lib/uucp:auth:x:7:21:Authentication administrator:/tcb/files/auth:cron:x:9:16:Cron daemon:/usr/spool/cron:listen:x:37:4:Network daemon:/usr/net/nls:lp:x:71:18:Printer administrator:/usr/spool/lp:sam:x:200:50:Sam san:/usr/sam:/bin/sh
As we can see from the above example, one row of records in/etc/passwd corresponds to a user, and each row of records is separated by a colon (:) into 7 fields, with the following format and meaning:
用户名:口令:用户标识号:组标识号:注释性描述:主目录:登录Shell
(1) The user name is a string representing the user's account number;
(2) password, some systems, stored in the encrypted user password Word;
(3) The user identification number is an integer, the system internal users use it to identify users;
(4) The Group Identification Number field records the user group required by the user;
(5) The explanatory Description field records Some personal circumstances of the user;
(6) "Master Directory", which is the user's starting working directory;
(7) After the user login, to start a process, responsible for the user's actions to the kernel, the process is the user log on the system after the command interpreter, or a specific program, the shell;
(8) The system has a class of users called Pseudo-users (pseudo users)
3.4 Adding bulk users
Adding and removing users to every Linux system administrator is a breeze, the tricky thing is that if you want to add dozens of, hundreds or even thousands of users, we are not likely to use Useradd to add one by one, it is necessary to find a simple way to create a large number of users. The Linux system provides the tools to create a large number of users, allowing you to create a large number of users immediately, as follows:
(1) Edit a text user file first
Each column according to the format of the/etc/passwd password file, note that each user's user name, UID, host directory can not be the same, where the password bar can be left blank or enter the X number. An example file user.txt the contents as follows:
user001::600:100:user:/home/user001:/bin/bashuser002::601:100:user:/home/user002:/bin/bashuser003::602:100:user:/home/user003:/bin/bashuser004::603:100:user:/home/user004:/bin/bashuser005::604:100:user:/home/user005:/bin/bashuser006::605:100:user:/home/user006:/bin/bash
(2) Execute the command/usr/sbin/newusers as root, import the data from the user file user.txt that you just created, create the user:
# newusers < user.txt然后可以执行命令 vipw 或 vi /etc/passwd 检查 /etc/passwd 文件是否已经出现这些用户的数据,并且用户的宿主目录是否已经创建。
(3) Execute command/usr/sbin/pwunconv.
Decode the shadow password generated by/etc/shadow, then write back to/etc/passwd and delete the shadow password bar of the/etc/shadow. This is to facilitate the next step of the password conversion work, that is, the first cancellation shadow password function.
# pwunconv
(4) Edit the password control file for each user.
Sample file Passwd.txt content is as follows:
user001:密码user002:密码user003:密码user004:密码user005:密码user006:密码
(5) Execute command/usr/sbin/chpasswd as root.
To create a user password, CHPASSWD writes the password encoded by the/USR/BIN/PASSWD command to the/etc/passwd password bar.
chpasswd < passwd.txt
(6) After you have determined that the password has been encoded into the/etc/passwd password bar.
Executes the command/USR/SBIN/PWCONV encodes the password to shadow password and writes the result to/etc/shadow.
$ pwconv
This completes the creation of a large number of users, after which you can check whether the permissions settings for these user host directories are correct, and log on to verify that the user's password is correct.
4. Disk Management
Linux Disk Management is directly related to the performance of the whole system.
Linux Disk Management commonly uses three commands for DF, Du, and Fdisk.
- DF: List The overall disk usage of the file system
- du: Check disk space usage
- fdisk: For disk partitioning
(1) DF
DF Command parameter function: Check the disk space consumption of the file system. You can use this command to get information about how much space the hard disk is taking up, and how much space is left.
Syntax: DF [ahikhtm] [directory or file name]
Option parameter:
- -A: Lists all file systems, including system-specific/proc and other file systems;
- -K: with Kbytes capacity Displays each file system;
- -M: Displays the file systems in MBytes capacity;
- -H: GBytes, MBytes, Kbytes, etc., which are easier to read;
- -H: m=1000k Take the place of the m=1024k;
- -T: Displays the file system type, along with the partition's filesystem name (for example, ext3), and
- -i: No hard disk capacity, and the number of Inode Display
Instance: Lists all special file formats and names in the system
[[email protected] ~]# df -aTFilesystem Type 1K-blocks Used Available Use% Mounted on/dev/hdc2 ext3 9920624 3823112 5585444 41% /proc proc 0 0 0 - /procsysfs sysfs 0 0 0 - /sysdevpts devpts 0 0 0 - /dev/pts/dev/hdc3 ext3 4956316 141376 4559108 4% /home/dev/hdc1 ext3 101086 11126 84741 12% /boottmpfs tmpfs 371332 0 371332 0% /dev/shmnone binfmt_misc 0 0 0 - /proc/sys/fs/binfmt_miscsunrpc rpc_pipefs 0 0 0 - /var/lib/nfs/rpc_pipefs
(2) du
The Linux du command also looks at the use of space, but unlike the DF command, the Linux du command is a view of the space used by the file and directory disks, or some difference from the DF command, which describes the Linux du command.
Grammar:du [-ahskm] 文件或目录名称
Parameter options:
- -A: Lists all files and directory capacity, because the default is only the number of files under the directory.
- -H: Displayed in a more readable capacity format (g/m);
- -S: Lists the total, not the capacity of each directory;
- -S: does not include totals under subdirectories, and is somewhat different from-S.
- -K: List capacity display in Kbytes;
- -M: List capacity display with MBytes;
(3) Fdisk
FDISK is a disk partition table manipulation tool for Linux.
Grammar:fdisk [0l] 装置名称
Parameter-L: Outputs all the partition contents of the device after the output. If there is only fdisk-l, the system will list the partitions of the device that can be searched in the whole system.
(4) disk formatting
After the disk is split, it is natural to format the file system, the format of the command is very simple, using the MKFS (make filesystem) command.
Grammar:mkfs [-t 文件系统格式] 装置文件名
Options and Parameters:
- -T: can take file system format, such as Ext3, ext2, VFAT, etc. (System support will be effective)
(5) Disk inspection
The fsck (file system check) is used to check and maintain inconsistent file systems.
If the system is out of power or a disk problem occurs, the fsck command can be used to check the file system.
Grammar:fsck [-t 文件系统] [-ACay] 装置名称
Options and Parameters:
- -T: Given the type of the file system, this parameter is not required if there is already a definition in/etc/fstab or if the kernel itself is supported
- -S: Execute the fsck command one by one to check
- -A: Check all listed partitions (partition) in/etc/fstab
- -C: Show complete Check progress
- -D: Print out debug results for e2fsck
- -P: Simultaneously with the-a condition, multiple fsck checks are performed together
- -R: Omit/No check when there is a-a condition at the same time
- -V: Verbose display mode
- -A: Automatically fix if check is wrong
- -R: If the check is wrong, the user answers whether the repair
- The-y: option specifies to detect that each file is automatically entered Yes, and can perform a full check fix when unsure of those that are not normal
# fsck -y
.
(6) disk mount and unload
Linux disk mounts using the Mount command, uninstall using the Umount command. V
Disk mount Syntax:
mount [-t 文件系统] [-L Label名] [-o 额外选项]
Example: In the default way, the/dev/hdc6 you just created is mounted on/MNT/HDC6!
[[email protected] ~]# mkdir /mnt/hdc6[[email protected] ~]# mount /dev/hdc6 /mnt/hdc6[[email protected] ~]# dfFilesystem 1K-blocks Used Available Use% Mounted on.....中间省略...../dev/hdc6 1976312 42072 1833836 3% /mnt/hdc6
Disk Offload command Umount syntax:
umount [-fn] 装置文件名或挂载点
Option parameters:
- -F: Forced removal! can be used in situations such as a network file system (NFS) that cannot be read;
- -N: Dismount without upgrading/etc/mtab.
Example: Uninstalling/DEV/HDC6
5. Linux Vi/vim
Vim is a text editor developed from VI. Code completion, compilation and error jumps and other convenient programming features are particularly rich, in the programmer is widely used.
To put it simply, VI is an old-fashioned word processor, but the function is already complete, but there is still room for improvement. Vim can be said to be a very useful tool for program developers.
Even Vim's official website (http://www.vim.org) itself says VIM is a program development tool rather than word processing software.
Vim keyboard diagram:
Basically, Vi/vim is divided into three modes, namely command mode, input mode and bottom command mode (last line mode). The three modes of action are:
- ESC: Switch to command mode
- I: Switch to input mode/edit mode
- :: Switch to baseline command mode
q 退出程序 w 保存文件 qi 强制退出
The relationship between the three modes is:
6. Linux View firewall status and turn off command
6.1 Service Mode
(1) View firewall status:
service iptables status
(2) Turn on the firewall:
service iptables start
(3) Turn off the firewall:
service iptables stop
6.2 iptables Way
(1) View firewall status:
/etc/init.d/iptables status
(2) Temporarily turn off the firewall:
/etc/init.d/iptables stop
(3) Restart Iptables:
/etc/init.d/iptables restart
Common basic commands for Linux