mirror of
https://github.com/Idnan/bash-guide.git
synced 2018-11-09 02:29:39 +01:00
1. Basic Operations
This commit is contained in:
parent
659b9b2d51
commit
f0f8a31565
78
README.md
78
README.md
@ -2,32 +2,32 @@
|
|||||||
<img src="https://cloud.githubusercontent.com/assets/2059754/24601246/753a7f36-1858-11e7-9d6b-7a0e64fb27f7.png" alt="bash logo"/>
|
<img src="https://cloud.githubusercontent.com/assets/2059754/24601246/753a7f36-1858-11e7-9d6b-7a0e64fb27f7.png" alt="bash logo"/>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
## Table of Contents
|
## Содержание
|
||||||
1. [Basic Operations](#1-basic-operations)
|
1. [Основные операции](#1-basic-operations)
|
||||||
1.1. [File Operations](#11-file-operations)
|
1.1. [Файловые операции](#11-file-operations)
|
||||||
1.2. [Text Operations](#12-text-operations)
|
1.2. [Текстовые операции](#12-text-operations)
|
||||||
1.3. [Directory Operations](#13-directory-operations)
|
1.3. [Операции с каталогами](#13-directory-operations)
|
||||||
1.4. [SSH, System Info & Network Operations](#14-ssh-system-info--network-operations)
|
1.4. [SSH, системная информация и сетевые операции](#14-ssh-system-info--network-operations)
|
||||||
1.5. [Process Monitoring Operations](#15-process-monitoring-operations)
|
1.5. [Операции по мониторингу процессов](#15-process-monitoring-operations)
|
||||||
2. [Basic Shell Programming](#2-basic-shell-programming)
|
2. [Основы программирования в командной строке](#2-basic-shell-programming)
|
||||||
2.1. [Variables](#21-variables)
|
2.1. [Переменные](#21-variables)
|
||||||
2.2. [Array](#22-array)
|
2.2. [Массивы](#22-array)
|
||||||
2.3. [String Substitution](#23-string-substitution)
|
2.3. [Замена строк](#23-string-substitution)
|
||||||
2.4. [Functions](#24-functions)
|
2.4. [Функции](#24-functions)
|
||||||
2.5. [Conditionals](#25-conditionals)
|
2.5. [Условные выражения](#25-conditionals)
|
||||||
2.6. [Loops](#26-loops)
|
2.6. [Циклы](#26-loops)
|
||||||
3. [Tricks](#3-tricks)
|
3. [Трюки](#3-tricks)
|
||||||
4. [Debugging](#4-debugging)
|
4. [Отладка (Debug)](#4-debugging)
|
||||||
|
|
||||||
|
|
||||||
# 1. Basic Operations
|
# 1. Основные операции
|
||||||
|
|
||||||
### a. `export`
|
### a. `export`
|
||||||
Displays all environment variables. If you want to get details of a specific variable, use `echo $VARIABLE_NAME`.
|
Отображает все переменные среды. Если вы хотите получить подробную информацию о конкретной переменной, используйте `echo $VARIABLE_NAME`.
|
||||||
```bash
|
```bash
|
||||||
export
|
export
|
||||||
```
|
```
|
||||||
Example:
|
Пример:
|
||||||
```bash
|
```bash
|
||||||
$ export
|
$ export
|
||||||
AWS_HOME=/Users/adnanadnan/.aws
|
AWS_HOME=/Users/adnanadnan/.aws
|
||||||
@ -40,40 +40,40 @@ $ echo $AWS_HOME
|
|||||||
```
|
```
|
||||||
|
|
||||||
### b. `whatis`
|
### b. `whatis`
|
||||||
whatis shows description for user commands, system calls, library functions, and others in manual pages
|
whatis показывает описание для пользовательских команд, системных вызовов, библиотечных функций и другое на страницах руководства.
|
||||||
```bash
|
```bash
|
||||||
whatis something
|
whatis something
|
||||||
```
|
```
|
||||||
Example:
|
Пример:
|
||||||
```bash
|
```bash
|
||||||
$ whatis bash
|
$ whatis bash
|
||||||
bash (1) - GNU Bourne-Again SHell
|
bash (1) - GNU Bourne-Again SHell
|
||||||
```
|
```
|
||||||
|
|
||||||
### c. `whereis`
|
### c. `whereis`
|
||||||
whereis searches for executables, source files, and manual pages using a database built by system automatically.
|
whereis ищет исполняемые файлы, исходные файлы и страницы руководства, используя базу данных, созданную системой автоматически.
|
||||||
```bash
|
```bash
|
||||||
whereis name
|
whereis name
|
||||||
```
|
```
|
||||||
Example:
|
Пример:
|
||||||
```bash
|
```bash
|
||||||
$ whereis php
|
$ whereis php
|
||||||
/usr/bin/php
|
/usr/bin/php
|
||||||
```
|
```
|
||||||
|
|
||||||
### d. `which`
|
### d. `which`
|
||||||
which searches for executables in the directories specified by the environment variable PATH. This command will print the full path of the executable(s).
|
which ищет исполняемые файлы в каталогах, заданных переменной среды PATH. Эта команда будет печатать полный путь к исполняемому файлу.
|
||||||
```bash
|
```bash
|
||||||
which program_name
|
which program_name
|
||||||
```
|
```
|
||||||
Example:
|
Пример:
|
||||||
```bash
|
```bash
|
||||||
$ which php
|
$ which php
|
||||||
/c/xampp/php/php
|
/c/xampp/php/php
|
||||||
```
|
```
|
||||||
|
|
||||||
### e. clear
|
### e. clear
|
||||||
Clears content on window.
|
Очищает содержимое окна.
|
||||||
|
|
||||||
## 1.1. File Operations
|
## 1.1. File Operations
|
||||||
<table>
|
<table>
|
||||||
@ -146,7 +146,7 @@ Determine file type.
|
|||||||
```bash
|
```bash
|
||||||
file filename
|
file filename
|
||||||
```
|
```
|
||||||
Example:
|
Пример:
|
||||||
```bash
|
```bash
|
||||||
$ file index.html
|
$ file index.html
|
||||||
index.html: HTML document, ASCII text
|
index.html: HTML document, ASCII text
|
||||||
@ -156,7 +156,7 @@ Find files in directory
|
|||||||
```bash
|
```bash
|
||||||
find directory options pattern
|
find directory options pattern
|
||||||
```
|
```
|
||||||
Example:
|
Пример:
|
||||||
```bash
|
```bash
|
||||||
$ find . -name README.md
|
$ find . -name README.md
|
||||||
$ find /home/user1 -name '*.png'
|
$ find /home/user1 -name '*.png'
|
||||||
@ -191,7 +191,7 @@ Check out the printer queue.
|
|||||||
```bash
|
```bash
|
||||||
lpq
|
lpq
|
||||||
```
|
```
|
||||||
Example:
|
Пример:
|
||||||
```bash
|
```bash
|
||||||
$ lpq
|
$ lpq
|
||||||
Rank Owner Job File(s) Total Size
|
Rank Owner Job File(s) Total Size
|
||||||
@ -216,7 +216,7 @@ Lists your files. `ls` has many options: `-l` lists files in 'long format', whic
|
|||||||
```bash
|
```bash
|
||||||
ls option
|
ls option
|
||||||
```
|
```
|
||||||
Example:
|
Пример:
|
||||||
<pre>
|
<pre>
|
||||||
$ ls -la
|
$ ls -la
|
||||||
rwxr-xr-x 33 adnan staff 1122 Mar 27 18:44 .
|
rwxr-xr-x 33 adnan staff 1122 Mar 27 18:44 .
|
||||||
@ -266,7 +266,7 @@ Updates access and modification time stamps of your file. If it doesn't exists,
|
|||||||
```bash
|
```bash
|
||||||
touch filename
|
touch filename
|
||||||
```
|
```
|
||||||
Example:
|
Пример:
|
||||||
```bash
|
```bash
|
||||||
$ touch trick.md
|
$ touch trick.md
|
||||||
```
|
```
|
||||||
@ -440,7 +440,7 @@ foo (Lorem|dolor)
|
|||||||
### f. `fmt`
|
### f. `fmt`
|
||||||
Simple optimal text formatter
|
Simple optimal text formatter
|
||||||
|
|
||||||
*example: example.txt (1 line)*
|
*Пример: example.txt (1 line)*
|
||||||
```bash
|
```bash
|
||||||
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
|
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
|
||||||
```
|
```
|
||||||
@ -476,14 +476,14 @@ Looks for text inside files. You can use grep to search for lines of text that m
|
|||||||
```bash
|
```bash
|
||||||
grep pattern filename
|
grep pattern filename
|
||||||
```
|
```
|
||||||
Example:
|
Пример:
|
||||||
```bash
|
```bash
|
||||||
$ grep admin /etc/passwd
|
$ grep admin /etc/passwd
|
||||||
_kadmin_admin:*:218:-2:Kerberos Admin Service:/var/empty:/usr/bin/false
|
_kadmin_admin:*:218:-2:Kerberos Admin Service:/var/empty:/usr/bin/false
|
||||||
_kadmin_changepw:*:219:-2:Kerberos Change Password Service:/var/empty:/usr/bin/false
|
_kadmin_changepw:*:219:-2:Kerberos Change Password Service:/var/empty:/usr/bin/false
|
||||||
_krb_kadmin:*:231:-2:Open Directory Kerberos Admin Service:/var/empty:/usr/bin/false
|
_krb_kadmin:*:231:-2:Open Directory Kerberos Admin Service:/var/empty:/usr/bin/false
|
||||||
```
|
```
|
||||||
You can also force grep to ignore word case by using `-i` option. `-r` can be used to search all files under the specified directory, for example:
|
You can also force grep to ignore word case by using `-i` option. `-r` can be used to search all files under the specified directory, for Пример:
|
||||||
```bash
|
```bash
|
||||||
$ grep -r admin /etc/
|
$ grep -r admin /etc/
|
||||||
```
|
```
|
||||||
@ -677,7 +677,7 @@ Tells you how many lines, words and characters there are in a file.
|
|||||||
```bash
|
```bash
|
||||||
wc filename
|
wc filename
|
||||||
```
|
```
|
||||||
Example:
|
Пример:
|
||||||
```bash
|
```bash
|
||||||
$ wc demo.txt
|
$ wc demo.txt
|
||||||
7459 15915 398400 demo.txt
|
7459 15915 398400 demo.txt
|
||||||
@ -778,7 +778,7 @@ Options:
|
|||||||
- `-h` (human readable) Displays output it in kilobytes (K), megabytes (M) and gigabytes (G).
|
- `-h` (human readable) Displays output it in kilobytes (K), megabytes (M) and gigabytes (G).
|
||||||
- `-s` (supress or summarize) Outputs total disk space of a directory and supresses reports for subdirectories.
|
- `-s` (supress or summarize) Outputs total disk space of a directory and supresses reports for subdirectories.
|
||||||
|
|
||||||
Example:
|
Пример:
|
||||||
```bash
|
```bash
|
||||||
du -sh pictures
|
du -sh pictures
|
||||||
1.4M pictures
|
1.4M pictures
|
||||||
@ -941,14 +941,14 @@ The first line that you will write in bash script files is called `shebang`. Thi
|
|||||||
|
|
||||||
Creating variables in bash is similar to other languages. There are no data types. A variable in bash can contain a number, a character, a string of characters, etc. You have no need to declare a variable, just assigning a value to its reference will create it.
|
Creating variables in bash is similar to other languages. There are no data types. A variable in bash can contain a number, a character, a string of characters, etc. You have no need to declare a variable, just assigning a value to its reference will create it.
|
||||||
|
|
||||||
Example:
|
Пример:
|
||||||
```bash
|
```bash
|
||||||
str="hello world"
|
str="hello world"
|
||||||
```
|
```
|
||||||
|
|
||||||
The above line creates a variable `str` and assigns "hello world" to it. The value of variable is retrieved by putting the `$` in the beginning of variable name.
|
The above line creates a variable `str` and assigns "hello world" to it. The value of variable is retrieved by putting the `$` in the beginning of variable name.
|
||||||
|
|
||||||
Example:
|
Пример:
|
||||||
```bash
|
```bash
|
||||||
echo $str # hello world
|
echo $str # hello world
|
||||||
```
|
```
|
||||||
@ -1007,7 +1007,7 @@ function name() {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
Example:
|
Пример:
|
||||||
```bash
|
```bash
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
function hello {
|
function hello {
|
||||||
|
Loading…
Reference in New Issue
Block a user