What & How & Why

差别

这里会显示出您选择的修订版和当前版本之间的差别。

到此差别页面的链接

两侧同时换到之前的修订记录前一修订版
后一修订版
前一修订版
linux:bash [2021/12/29 16:40] – [REDIRECTION] codingharelinux:bash [2024/01/14 13:57] (当前版本) – [Bash & Shell] codinghare
行 1: 行 1:
 ======Bash & Shell====== ======Bash & Shell======
-常用的 bash 命令+//常用的 bash 命令//
 ---- ----
-====命令==== 
-==ls== 
-  * ''ls'':查看当前目录下的所有文件 
-  * ''ls -a'':查看当前目录下所有文件,包括隐藏的目录和文件 
-  * ''ls -l'' :以完整信息的模式查看 
-  * ''ls -t'' :按上次修改的时间排序 
  
-drwxr-xr-x 5  cc  eng  4096 Jun 24 16:51  action +====Navigation==== 
-Access rights. These indicate the read, write, and execute permissions on the file or directory allowed to the owner, the group, and all users. You can read more about file permissions. +<code bash> 
-Number of hard links. This number counts the number of child directories and files. This number includes the parent directory link (..) and current directory link (.). +##ls 
-The username of the file’s owner. Here the username is cc. +# 查看当前目录下所有的文件夹和文件 
-The name of the group that owns the file. Here the group name is eng. +ls 
-The size of the file in bytes. +# 查看所有文件夹和文件,包括隐藏 
-The date & time that the file was last modified. +ls -a 
-The name of the file or directory+# 查看详细信息 
 +ls -l 
 +# 查看文件,按上次修改时间排列 
 +ls -t
  
 +##pwd
 +# 打印当前目录的路径
 +pwd
  
 +##cd
 +# 切换到指定文件夹
 +cd <folder name>
 +cd <path>
 +# 返回上级目录
 +cd ..
  
 +##mkdir
 +#创建文件夹
 +mkdir <folder name>
  
 +##touch
 +#创建文件
 +touch <file name>
 +</code>
 +=== ls -l 的详细信息解释===
 +''ls -l'' 之后会出现如下的详细信息:
 +<code bash>
 +drwxr-xr-x 5  cc  eng  4096 Jun 24 16:51  action
 +</code>
 +具体的解释见下图:
 +{{ :linux:ls_l_detail.svg?500 |}}
 +==access right==
 +背景知识:Linux 中:
 +  * premission group 分为三类:// owner, group, all users//
 +  * premission type 也分为三类://read, write, excute//
 +//access right// 是详细信息中的 10 位字母,结构如下:
 +  * 头一位字母是 special permission flag
 +  * 2-4 位代表了 owner 的权限
 +  * 5-7 代表了 group 的权限
 +  * 8-10 代表了 all user 的权限
 +权限中,read 权限标记为 ''r'', write 为 ''w'', excute 为 ''x''。因此,上面例子中的 2-4 为字母为 ''rwx'',意思是 owner 拥有读,写,执行文件的权限。
 +====Viewing and Changing File System====
 +===Manipulation===
  
-  * ''pwd'':显示当前目录路径 
-  * ''cd + folder_name'' :打开当前目录下的文件夹 
-  * ''cd ..'':返回上一级文件夹 
-  * ''mkdir + dir_name'':新建目录 
-  * ''touch + file_name'':新建文件 
   * ''cat + file_name'':读取文件中的内容   * ''cat + file_name'':读取文件中的内容
   * ''cp + file_name + path'':拷贝文件到目标位置   * ''cp + file_name + path'':拷贝文件到目标位置
行 48: 行 75:
   * ''grep'' global regular expression print, 按 pattern 搜索。默认区分大小写, ''-i'' 取消区分大小写, ''-R'' 搜索所有匹配的关键字文件,''-Rl'' 搜索匹配的文件名   * ''grep'' global regular expression print, 按 pattern 搜索。默认区分大小写, ''-i'' 取消区分大小写, ''-R'' 搜索所有匹配的关键字文件,''-Rl'' 搜索匹配的文件名
   * ''sed'' 查找并且替换:s/snow/rain/g s 代表 substitution 替换, 查找的关键词是 snow, 替换的关键词是 rain, g 代表 global,意思是替换所有。如果只需要在终端打印的时候替换,使用 ''-i''   * ''sed'' 查找并且替换:s/snow/rain/g s 代表 substitution 替换, 查找的关键词是 snow, 替换的关键词是 rain, g 代表 global,意思是替换所有。如果只需要在终端打印的时候替换,使用 ''-i''
-===Environment====+===Environment=== 
 +Nano 的操作 
 +==Bash profile== 
 +  * ''~'' 代表 Home 目录 
 +  * ''.'' 代表影藏文件 
 +  * 重要的文件 ~/.bash_profile ''nano ~/.bash_profile'' 修改该文件, 在里面写 ''echo'' 会在 terminal 打开的时候打印 
 +  * 激活 profile ''source ~/.bash_profile'' 立刻激活,不用关闭终端 
 +  * 类型 ''alias'' : 可以配置快捷键 
 +    * ''alias pd = "pwd" '' pd 会具有 pwd 的功能 
 +==Environment Variables==