1. Basic command

The basic format of a command

1. command prompt

[root@localhost ~]#
	[]:这是提示符的分隔符号,没有特殊含义。
	root:显示的是当前的登录用户,现在使用的是 root 用户登录。
	@:分隔符号,没有特殊含义。
	localhost:当前系统的简写主机名(完整主机名是 localhost.localdomain)。
	~:代表用户当前所在的目录,此例中用户当前所在的目录是家目录。
	#:命令提示符。超级用户是#,普通用户是$

2. The basic format of the command

[root@localhost ~]# 命令 [选项] [参数]
ls 是最常见的目录操作命令,主要作用是显示目录下的内容。
  命令名称:ls。
 英文原意:list。
 所在路径:/bin/ls。
 执行权限:所有用户。
 功能描述:显示目录下的内容。 
 [root@localhost ~]#ls [选项] [文件名或目录名] 
-a:	显示所有文件
--color=when: 支持颜色输出,when 的值默认是 always(总显示颜色),也可以是
never(从不显示颜色)和 auto(自动)
-d:	显示目录信息,而不是目录下的文件
-h:	人性化显示,按照我们习惯的单位显示文件大小
-i:	显示文件的 i 节点号
-l:	长格式显示
举几个例子:
[root@localhost ~]# ls -l
总用量 44
-rw-------. 1 root root 1207 1 月    14 18:18 anaconda-ks.cfg
#权限	引用计数 所有者 所属组 大小 文件修改时间	文件名
我们已经知道“-l”选项用于显示文件的详细信息,那么“-l”选项显示的这 7 列分别是什么含义?
  第一列:权限。
  第二列:引用计数。文件的引用计数代表该文件的硬链接个数,而目录的引用计数代表该目录 有多少个一级子目录。
  第三列:所有者,也就是这个文件属于哪个用户。默认所有者是文件的建立用户
  第四列:所属组。默认所属组是文件建立用户的有效组,一般情况下就是建立用户的所在组。
  第五列:大小。默认单位是字节。
  第六列:文件修改时间。文件状态修改时间或文件数据修改时间都会更改这个时间,注意这个 时间不是文件的创建时间。
  	第七列:文件名。

Two directory operations command

cd command

cd 是切换所在目录的命令,这个命令的基本信息如下。
  命令名称:cd。
  英文原意:change directory。
  所在路径:Shell 内置命令。
  执行权限:所有用户。 功能描述:切换所在目录

pwd command

pwd 命令是查询所在目录的命令,基本信息如下:
  命令名称:pwd
  英文原意:print name of current/working directory
  所在路径:/bin/pwd
  执行权限:所有用户。
  功能描述:查询所在的工作目录。

mkdir command

mkdir 是创建目录的命令,其基本信息如下。
  命令名称:mkdir。
  英文原意:make directories。
  所在路径:/bin/mkdir。
  执行权限:所有用户。
  功能描述:创建空目录。
命令格式
[root@localhost ~]# mkdir [选项] 目录名   -p:递归建立所需目录

Three file manipulation commands

touch command

创建空文件或修改文件时间,这个命令的基本信息如下。
  命令名称:touch。
  英文原意:change file timestamps。
  所在路径:/bin/touch。
  执行权限:所有用户。
  功能描述:修改文件的时间戳。

stat command

stat 是查看文件详细信息的命令,而且可以看到文件的这三个时间,其基本信息如下。
  命令名称:stat。
  英文原意:display file or file system status。
  所在路径:/usr/bin/stat。
  执行权限:所有用户。
功能描述:显示文件或文件系统的详细信息。
[root@localhost ~]# stat anaconda-ks.cfg
文件:"anaconda-ks.cfg"
大小:1453	块:8	IO 块:4096	普通文件 设备:803h/2051dInode:33574991		硬链接:1
权限:(0600/-rw-------) Uid:(	0/	root)	Gid:(	0/	root)
环境:system_u:object_r:admin_home_t:s0
最近访问:2018-11-06 23:22:23.409038121 +0800
最近更改:2018-10-24 00:53:08.760018638 +0800	#数据修改时间
最近改动:2018-10-24 00:53:08.760018638 +0800	#状态修改时间
创建时间:-

The cat command

cat 命令用来查看文件内容。这个命令的基本信息如下。
  命令名称:cat。
  英文原意:concatenate files and print on the standard output。
  所在路径:/bin/cat。
  执行权限:所有用户。 功能描述:合并文件并打印输出到标准输出
命令格式
[root@localhost ~]# cat [选项] 文件名 选项:
-A: 相当于-vET 选项的整合,用于列出所有隐藏符号
-E: 列出每行结尾的回车符$
-n: 显示行号
-T: 把 Tab 键用^I 显示出来
-v: 列出特殊字符

more command

more 是分屏显示文件的命令,其基本信息如下。
  命令名称:more。
  英文原意:file perusal filter for crt viewin。
  所在路径:/bin/more。
  执行权限:所有用户。
  功能描述:分屏显示文件内容。

more 命令比较简单,一般不用什么选项,命令会打开一个交互界面,可以识别一些交互命令。常 用的交互命令如下。
  空格键:向下翻页。
  b:向上翻页。
  回车键:向下滚动一行。
  /字符串:搜索指定的字符串。
  q:退出。

less command

less 命令和 more 命令类似,只是 more 是分屏显示命令,而 less 是分行显示命令,其基本信息如 下。
  命令名称:less。
  英文原意:opposite of more。
  所在路径:/usr/bin/less。
  功能描述:分行显示文件内容
/字符串:向下搜索“字符串”的功能
?字符串:向上搜索“字符串”的功能
n:重复前一个搜索(与 / 或 ? 有关)
N:反向重复前一个搜索(与 / 或 ? 有关)
b  向后翻一页
d  向后翻半页
[pagedown]: 向下翻动一页
[pageup]:   向上翻动一页

head command

head 是用来显示文件开头的命令,其基本信息如下。
  命令名称:head。
  英文原意:output the first part of files。
  所在路径:/usr/bin/head。
  执行权限:所有用户。
  功能描述:显示文件开头的内容。
1.命令格式
[root@localhost ~]# head [选项] 文件名 选项:
-n 行数:	从文件头开始,显示指定行数
-v:	显示文件名

tail command

既然有显示文件开头的命令,就会有显示文件结尾的命令。tail 命令的基本信息如下。
  命令名称:tail。
  英文原意:output the last part of files。
  所在路径:/usr/bin/tail。
  执行权限:所有用户。
  功能描述:显示文件结尾的内容。
命令格式
[root@localhost ~]# tail [选项] 文件名 选项:
-n 行数:	从文件结尾开始,显示指定行数
-f:	监听文件的新增内容

8. ln command

Let's look at the basic information ln command.
 command name: ln.
 English original intent: make links between file.
 the path: / bin / ln.
 execute permissions: All users.
 Description: establish links between files.

Ln command basic format is as follows:

[root @ localhost ~] # ln [ options] source file destination
options:
-s: softlinks file. If you do not add "-s" option, then establish a hard link files
-f: Force. If the target file already exists, delete the file and then establish the link target file
if you create a hard link:
[root @ localhost ~] # Touch cangls
[root @ localhost ~] # LN / root / cangls / tmp /
establish a hard link file # target file did not write a file name, and formerly known as consistent
# is / root / cangls and / tmp / cangls is hard linked files
If you create a soft link:
[root @ localhost ~] # Touch Bols
[root @ localhost ~] # LN - S / root / Bols / tmp /
# softlinks file

8.2 hard links and soft features connected

Hard link feature:
 source files and hard links and file have the same Inode Block
 modify any file, another has changed
 delete any file, another can use
 hard links not clearly marked, it is difficult to confirm a hard link file locations is not recommended
 hard links can not link directories
 hard links can not be partitioned across
a soft link characteristic:
 soft links and source files have different Inode and Block
 two files to modify any of the other changed
 delete soft links the source files are not affected; delete the source file, soft links can not be used
 soft links no actual data, save only Inode source file, no matter what the source file, soft links the same size
privileges  soft link is the greatest privilege lrwxrwxrwx,. but the absence of actual data, you need to reference the source file permissions to access the final
 soft link to link directory
 soft link across partitions
 soft links obvious characteristics, it is recommended to use flexible connections

Directories and files can command four operations

1. rm command

rm is a powerful command to delete, not only can delete files, you can also delete the directory. Basic information of this command is as follows.
 command names: rm.
 English original intent: remove files or directories.
 the path: / bin / rm.
 execute permissions: All users.
 Function Description: Delete a file or directory.
Command Format
[root @ localhost ~] # rm [ options] files or directories options:
-f: force the deletion (Force)
-i: interactive deleted, before deleting the user will be asked
-r: recursive delete, you can delete the directory (recursive)

2. cp command

cp is a command for copying, the following basic information:
 command name: cp.
 English original intent: copy files and directories.
 the path: / bin / cp.
 execute permissions: All users.
 Description: copying files and directories.
Command Format
[root @ localhost ~] # cp [ options] source file destination options:
-a: -dpr equivalent set of options, these options we introduced one by one
-d: If the source file is a soft link (hard link does not work), then copy the target file is also soft link
-i: ask, if the target file already exists, you are asked whether to overwrite
-p: after you copy the target file to retain the source file's attributes (including the owner, the owning group, permissions and time)
-r: recursive copy, for copying directory

3. mv command

mv is the command to cut, as the basic information.
 command names: mv.
 English original intent: move (rename) files.
 the path: / bin / mv.
 execute permissions: All users.
 Description: move or rename files.
Command Format
[root @ localhost ~] # mv [ options] source file destination options:
-f: mandatory coverage, if the target file already exists, it is not asked directly mandatory coverage
-i: interactive mobile, if the target file already exists, the user is asked whether coverage (the default option)
-v: show Details

FIVE BASIC Rights Management

1. Introduction rights

[the root @ localhost ~] # the install.log LS -l
-rw-R & lt-r--. the root the root 24772 1 1 18:17 the install.log dated 14
 bit represents the file type. Linux, unlike Windows uses the extension indicates the file type, but the use of No. 1 permission bits of the file type. Although the type of Linux file unlike Windows, so much, but also a lot of classification, the details you can use "info ls" command. Super brother here talk about some of the common file types.

  • "-": ordinary files.
  • "B": block device file. This is a special device files, storage devices are of this file, such as the partition file / dev / sda1
    is this document.
  • "C": character device file. This is also the special device files, input devices are generally such documents, such as a mouse, keyboard, and so on.
  • "D": the catalog file. Linux, everything is a file, it is also one kind of directory files.
  • "L": soft-linked files.
  • "P": the pipe character file. This is a very special device files rare.
  • "S": socket file. This is a special device files, access some services to support Socket, it will produce such a document.

 2 to 4 represents the owner of the file permissions.

  • r: represents the read, read permission.
  • w: representatives write, write permissions.
  • x: represents the execute, execute permission is. If there is a letter, on behalf of the authority have corresponding; if it is "-" represents no corresponding rights.
     Bit 5 to 7 represents the file permissions of the owning group, also has "rwx" permissions.
     8 to 10 permissions on behalf of other people, also has "rwx" permissions.

2. Basic authority to order

First, look at the command modify the permissions of chmod, basic information is as follows.
 command names: chmod.
 English original intent: change file mode bits.
 the path: / bin / chmod.
 execute permissions: All users.
 Functional Description: Modify the file mode.

2.1. Command Format

[root @ localhost ~] # chmod [ options] mode permissions file name options:
-R: recursively set permissions, that is, to all files in subdirectories set permissions

2.2. Permissions mode

Chmod command format mode change is "[ugoa] [[± =] [perms]]", that is, "[user] [[impartment] [Permissions]]"

 user.

  • u: on behalf of the owner (user).
  • g: Representative belonging group (group).
  • o: on behalf of someone else (other).
  • a: representing the entire identity (all).

 giving way.

  • +: Add permissions.
  • -: minus permission.
  • =: Set permissions.

 rights.

  • r: Read permission (read).
  • w: write permissions (write).
  • x: execute permissions (execute).

2.3. Digital Rights
digital rights of way is given to the most simple, but not as good as before permission letters to remember, and intuitive. Let's look at the meaning of these figures rights.
 4: represents the "r" permissions.
 2: represents the "w" permissions.
 1: represents the "x" permission.

2.4. Common permissions
given way to a more simple digital rights, but require the user to become more familiar with a few of these numbers. In fact, not many common authority, as only a few.
 644: This is the basic file permissions, on behalf of the owner has read and write permissions, and belongs to the group and others have read-only access.
 755: This is the basic permission to execute files and directories, on behalf of the owner has read, write, and execute permissions, and belongs to the group
and others have read and execute permissions.
 777: This is the greatest privilege. In the actual production server, you should try to avoid giving such file or directory permissions, which can cause some security risks.

3. The role of basic rights

3.1. Permissions explained the meaning of

First of all, read, write, and execute permissions for the role of files and directories are different.
 role permissions to the file.

  • Read (r): the file has read (r) permission, representatives can read the data file. If the permissions correspond to the command, then once read (r) permission, you can perform cat, more, less, head, tail and other documents on file for file viewing command.

  • Write (w): file write (w) permission, representatives can modify the data file. If the permissions correspond to the command, then once the file has write (w) permission, you can execute the command vim, echo and other modified file data on the file. Note: There is write access to the file, not delete the file itself, can only modify the data file. If you want to delete a file, you need to have write access to the parent directory of the file.

  • Execute (x): have execute (x) permissions to the file, on behalf of the file have execute permissions, you can run. In Linux, as long as the file has execute (x) permission, this file is executed files. This file is in the end just can not be executed properly, not only need to execute (x) permission, but also the code in the file is not the correct language code. For files, execute

(X) is the highest authority permission.
Role  access to a directory.

  • Read (r): has read (r) permission on the directory, you can view the contents on behalf of the directory, which is to see which sub-files and subdirectories have directory. If the permissions correspond to the command, then once the directory has read (r) permission, you can execute the ls command in the directory, view the contents of a directory.
  • Write (w): directory write (r) permission, representatives can modify the data in the directory, which is in the directory can create, delete, copy, cut sub-file or subdirectory. If the permissions correspond to the command, then once the directory has write (w) permission, you can perform touch, rm, cp, mv command in the directory. For a directory, write (w) permission is the highest authority.
  • Execute (x): the directory is not running, then the directory has execute (x) permission, representatives can enter the directory. If the permissions correspond to the command, then once the directory has the execute (x) permission, you can execute the command cd to the directory, enter the directory.

3.1. Available directory permissions
available directory permissions fact, only the following.
 0: not confer any rights.
 5: directory browsing and basic access rights.
 7: full permission.

4. Owner and group command

4.1. chown command

chown command is owner and group of modified files and directories, the basic information is as follows.
 command name: chown.
 English original intent: change file owner and group.
 the path: / bin / chown.
 execute permissions: All users.
 Functional Description: Change owner and group of files and directories.
1) Command format
[root @ localhost ~] # chown [ options] Owner: owning group file or directory
options:
-R: recursively set permissions, that is, to all the files in a subdirectory set permissions for
ordinary users can not modify all the files who, even if he is the owner of the file does not work. Ordinary users can modify their own permissions owner of the file.

4.2. chgrp command

chgrp is to modify the command files and directories belonging group, the basic information is as follows.

 command name: chgrp.
 English original intent: change group ownership.
 the path: / bin / chgrp.
 execute permissions: All users.
 Functional Description: Modify your set of files and directories.

Guess you like

Origin blog.csdn.net/misxu890312/article/details/89196823