---
title: "【batshell】Shell进阶"
author: "Perrin Yong"
author_profile: https://www.pystone.net/profile/
published_by: "Perrin Yong"
canonical: https://www.pystone.net/notes/shell-advanced-techniques/
type: note
content_role: unspecified
visibility: public
id_stability: rename-stable
source_path: "10-计算机、信息技术与工程/03-软件工程与质量保障/CI-CD与质量保障/CI-CD工具链/【batshell】Shell进阶.md"
content_hash: 9ee6adb07fff5f09a7c6c786ed24507e088e4bbb8f89db4e9bd36ad7872d88af
knowledge_version: 224c990773de.5fa8af6e39fa
site_commit: 224c990773de166d23a886306577dd90379529ce
notes_commit: 5fa8af6e39fa3891d1b9b4832bfa6c4e0ecaaf0a
---
# 【batshell】Shell进阶

> 创建时间：2021/7/21 15:42

* permission
    * chmod
  * text processing
    * grep
    * awk
    * sed
      * Substitution command
    * xargs
  * 输出重定向
  * test命令
  * Ref

## permission

### chmod

```csharp
string a = &quot;test&quot;;
string tmp = &quot;est&quot;;
string b = &quot;t&quot; + tmp;
Console.WriteLine(string .ReferenceEquals(str1, str2));

```

make it executable

Permission:

  * read (r) = 4
  * write (w) = 2
  * execute (x) = 1

Each permission may be on or off for each of three categories of users: the file or directory **owner** ; other people in the same **group** as the owner; and all **others**.

  * u stands for user.
  * g stands for group.
  * o stands for others.
  * a stands for all.

`chmod u+x filename` \- grant the execution permission to the owner of the file
`chmod +x filename` = `chmod a+x filename`

`chmod 777` = `chmod a=rwx`

## text processing

### grep

grep is a command-line utility for searching plain-text data sets for lines that match a **regular expression**.

```csharp
string a = &quot;test&quot;;
string tmp = &quot;est&quot;;
string b = &quot;t&quot; + tmp;
Console.WriteLine(string .ReferenceEquals(str1, str2));

```

The caret ^ and the dollar sign $ are meta-characters that respectively match the empty string at the beginning and end of a line.

### awk

https://en.wikipedia.org/wiki/AWK
AWK (awk) is a domain-specific language designed for text processing and typically used as a data extraction and reporting tool.

### sed

https://www.geeksforgeeks.org/sed-command-in-linux-unix-with-examples/
https://en.wikipedia.org/wiki/Sed

sed ("stream editor") is a Unix utility that parses and transforms text, using a simple, compact programming language.

#### Substitution command

sed OPTIONS... [SCRIPT] [INPUTFILE...]

```csharp
string a = &quot;test&quot;;
string tmp = &quot;est&quot;;
string b = &quot;t&quot; + tmp;
Console.WriteLine(string .ReferenceEquals(str1, str2));

```

### xargs

https://en.wikipedia.org/wiki/Xargs

xargs (short for "eXtended ARGuments" ) is a command on Unix and most Unix-like operating systems used to build and execute commands from standard input.

Some commands such as grep and awk can take input either as command-line arguments or from the standard input. However, others such as cp and echo can only take input as arguments, which is why xargs is necessary.

## 输出重定向

0：标准输入；1：标准输出；2：标准错误

2>&1表明将文件描述2（标准错误输出）的内容重定向到文件描述符1（标准输出），为什么1前面需要&？当没有&时，1会被认为是一个普通的文件，有&表示重定向的目标不是一个文件，而是一个文件描述符。

```csharp
string a = &quot;test&quot;;
string tmp = &quot;est&quot;;
string b = &quot;t&quot; + tmp;
Console.WriteLine(string .ReferenceEquals(str1, str2));

```

http://xstarcd.github.io/wiki/shell/exec_redirect.html

```csharp
string a = &quot;test&quot;;
string tmp = &quot;est&quot;;
string b = &quot;t&quot; + tmp;
Console.WriteLine(string .ReferenceEquals(str1, str2));

```

## test命令

https://www.runoob.com/linux/linux-shell-test.html

## Ref

https://zhuanlan.zhihu.com/p/47765176
https://en.wikipedia.org/wiki/AWK


> 创建时间：2021/9/24 18:20

* 进程查找与杀死
    * tasklist
    * taskkill
    * 完整代码
  * 相关知识点
  * 查询程序及命令行参数
  * Ref

## 进程查找与杀死

### tasklist

  * **Image name** is the name of the executable, e.g. explorer.exe or myapp.exe

```csharp
string a = &quot;test&quot;;
string tmp = &quot;est&quot;;
string b = &quot;t&quot; + tmp;
Console.WriteLine(string .ReferenceEquals(str1, str2));

```
```csharp
string a = &quot;test&quot;;
string tmp = &quot;est&quot;;
string b = &quot;t&quot; + tmp;
Console.WriteLine(string .ReferenceEquals(str1, str2));

```
```csharp
string a = &quot;test&quot;;
string tmp = &quot;est&quot;;
string b = &quot;t&quot; + tmp;
Console.WriteLine(string .ReferenceEquals(str1, str2));

```

### taskkill

```csharp
string a = &quot;test&quot;;
string tmp = &quot;est&quot;;
string b = &quot;t&quot; + tmp;
Console.WriteLine(string .ReferenceEquals(str1, str2));

```
```csharp
string a = &quot;test&quot;;
string tmp = &quot;est&quot;;
string b = &quot;t&quot; + tmp;
Console.WriteLine(string .ReferenceEquals(str1, str2));

```

### 完整代码

```csharp
string a = &quot;test&quot;;
string tmp = &quot;est&quot;;
string b = &quot;t&quot; + tmp;
Console.WriteLine(string .ReferenceEquals(str1, str2));

```

## 相关知识点

1>nul 意思是不显示命令运行的正确提示
2>nul 是不显示错误提示
一起就是 正确错误的都不显示

> 是重定向符号
>  nul是空设备的意思
>  把提示输入到空设备就不显示了

## 查询程序及命令行参数

```csharp
string a = &quot;test&quot;;
string tmp = &quot;est&quot;;
string b = &quot;t&quot; + tmp;
Console.WriteLine(string .ReferenceEquals(str1, str2));

```
```csharp
string a = &quot;test&quot;;
string tmp = &quot;est&quot;;
string b = &quot;t&quot; + tmp;
Console.WriteLine(string .ReferenceEquals(str1, str2));

```

## Ref

https://blog.csdn.net/c1520006273/article/details/50539092
