Study Notes day4

rm: delete
-f: Force deleted without asking confirmation (regardless of the specified deleted file exists or not will execute)
-r: delete the directory (without the r parameter can only delete a folder)
-v: Print Delete to delete the same time information

history: history of commands
-c: Empty Command History

cp: copy
-r: copies directory

mv: move and rename
* When the target directory exists, will the source directory into the target directory, when the target directory does not exist, change the source directory named directory directory name

  • The role of the environment variable
    viewing environment variable
    Here Insert Picture Description
    * When the directory are environmental variables, execute the command in the directory without using the absolute path
    such as ls command:
    Here Insert Picture Description
    test:
    Here Insert Picture Description
    The ls copy to the / tmp directory named testls, use the / tmp / testls still can realize the function of the ls command, but does not use an absolute path to direct input testls, prompted not found, then you need to add an environment variable
  • Add environment variables
    Here Insert Picture Description
    : the / tmp directory to the environment variable and test testls command again
    Here Insert Picture Description
    * reuse testls command after adding the / tmp directory to environment variable can no longer use an absolute path

But the only variable in the current terminal to take effect, you need to modify the configuration file it in a multi-terminal effect:
1. Modify the configuration file / etc / profie
Here Insert Picture Description
2. Add Content: PATH = $ PATH: / tmp /
Here Insert Picture Description
3. After saving open the other end of the link to take effect, if not come into force source / etc / profile command

  • Cancellation environment variables
    1. 如需取消/tmp目录的环境变量,重新定义一次不包含该目录的变量即可
      Here Insert Picture Description
      2.修改 /etc/profile文件,注释掉PATH=$PATH:/tmp/即可
      Here Insert Picture Description
      *需要注意添加变量和重新定义变量的区别

*在linux中查看文档内容可以根据实际情况使用不同的命令

cat命令:
cat /路径/文件名
-A :显示所有字符(例如在每行末尾的$结束符)
-n :在每行前面显示行号
tac:倒序查看文档

more命令:
more /路径/文件名
*more不会像cat一次把文档内容显示完,而是分页显示
回车:显示下一行
空格:显示下一页
B:显示上一页
退出:按q或者看完
上下左右方向键不能翻页

less命令:
less /路径/文件名
与more同样是分页显示,但可以使用方向键
空格:显示下一页
B:显示上一页
Q:退出
/:正序搜索
?:倒序搜索
n 向下查找搜索出的关键词,N向上查找搜索出的关键词
g 跳到首行 G跳到末尾最后一行
*less包含more所有功能,推荐记忆和使用less

head/tail命令:
head:查看文件的前10行
tail:查看文件的后10行
-n:指定要查看行的数量
tail -f /路径/文件名 实时显示文件正在新增的内容(通常用于看日志)

通过ll命令即可查看当前目录下的目录和文件的权限信息,每行开始的第一位为文件类型,文件类型后面的rwx内容即是权限
Here Insert Picture Description
r:可读 w:可写 x:可执行,用数字表示r为4,w为2,x为1
例:rwxrwxrwx=777 rwxr-xr-x=755 rw-r--r--=644
权限一共有9个字符,每三个字符分为一段,第一段代表文件所有者的权限,第二段代表所属组的权限,第三段代表其他用户的权限

  • chmod命令:
    *变更文件或目录的权限
    Here Insert Picture Description
    将test.txt文件权限由644变更为666:
    Here Insert Picture Description
    -R参数:将目录以及目录内的子目录和文件一起变更权限
    Here Insert Picture Description
    将test/目录权限由755变更为700后,test/目录内的子目录和文件权限没有变化
    Here Insert Picture Description
    加-R 参数,批量更改目录以及子目录和文件的权限

如果不想通过数字来变更权限,也可以通过r、w、x字母来变更*
将test.txt文件的权限由600变更为644
Here Insert Picture Description
*u=user,g=group,o=other
也可以单独指定user、group、other加上r、w、x权限
Here Insert Picture Description
a表示all,user+group+other*

  • chown命令:
    *变更文件或目录的所属用户或所属组

Here Insert Picture Description
chown username filename belongs to the user to modify the file or directory
belongs to the group chgrp groupname filename modify a file or directory
chown username: groupname filename modify one owner and group

-R parameter: Batch change the owner or group of users all subdirectories and files in the directory
Here Insert Picture Description

  • umask: the default permissions for files and directories decided
    to see umask
    Here Insert Picture Description
    * Ignore the first 0, where umask equal to 022
    when umask = 022, the folder and file permissions are created as follows:
    * The first 0 represents the file permissions correspond to the first paragraph the relationship between (the owner), the second represents the corresponding relationship between the file permissions of the second paragraph (owned group), relationships (other users) the third represents the file permissions corresponding to the third paragraph of
    Here Insert Picture Description
    folders: 755 file: 644 umask : 022
    correspondence is as follows:
    Here Insert Picture Description
    modified umask = 003, when the mask 003 = time with the following results:
    Here Insert Picture Description

Guess you like

Origin blog.51cto.com/14520558/2433775