MaJ du 04-02-2021
This commit is contained in:
@@ -158,4 +158,84 @@ Occurence suivante:
|
||||
|
||||
CTRL + W puis Retour
|
||||
|
||||
CTRL + C pour sortir du mode recherche
|
||||
CTRL + C pour sortir du mode recherche
|
||||
|
||||
|
||||
|
||||
#### Créer un backup du fichier que l'on édite (-B, ):
|
||||
|
||||
```bash
|
||||
$ nano -B wordpress4.sql
|
||||
|
||||
-rw-r--r-- 1 bruno staff 600655 Dec 1 08:54 wordpress4.sql
|
||||
-rw-r--r-- 1 bruno staff 600648 Dec 31 2017 wordpress4.sql~
|
||||
```
|
||||
|
||||
|
||||
|
||||
#### No wrap (-w, --nowrap):
|
||||
|
||||
```bash
|
||||
$ nano -w wordpress4.sql
|
||||
```
|
||||
|
||||
|
||||
|
||||
#### Configuration:
|
||||
|
||||
Colorisation de la syntaxe: les fichiers de configurations sont là: `~/.nanosyntax` (homebrew) et `/usr/local/share/nano/` (macOS).
|
||||
|
||||
Ajouter un fichier de configuration:
|
||||
|
||||
```bash
|
||||
$ nano ~/.nanosyntax/yaml.nanorc
|
||||
```
|
||||
|
||||
et y copier:
|
||||
|
||||
```nanorc
|
||||
# Supports `YAML` files
|
||||
syntax "YAML" "\.ya?ml$"
|
||||
header "^(---|===)" "%YAML"
|
||||
|
||||
## Keys
|
||||
color magenta "^\s*[\$A-Za-z0-9_-]+\:"
|
||||
color brightmagenta "^\s*@[\$A-Za-z0-9_-]+\:"
|
||||
|
||||
## Values
|
||||
color white ":\s.+$"
|
||||
## Booleans
|
||||
icolor brightcyan " (y|yes|n|no|true|false|on|off)$"
|
||||
## Numbers
|
||||
color brightred " [[:digit:]]+(\.[[:digit:]]+)?"
|
||||
## Arrays
|
||||
color red "\[" "\]" ":\s+[|>]" "^\s*- "
|
||||
## Reserved
|
||||
color green "(^| )!!(binary|bool|float|int|map|null|omap|seq|set|str) "
|
||||
|
||||
## Comments
|
||||
color brightwhite "#.*$"
|
||||
|
||||
## Errors
|
||||
color ,red ":\w.+$"
|
||||
color ,red ":'.+$"
|
||||
color ,red ":".+$"
|
||||
color ,red "\s+$"
|
||||
|
||||
## Non closed quote
|
||||
color ,red "['\"][^['\"]]*$"
|
||||
|
||||
## Closed quotes
|
||||
color yellow "['\"].*['\"]"
|
||||
|
||||
## Equal sign
|
||||
color brightgreen ":( |$)"
|
||||
```
|
||||
|
||||
Ajouter ce fichier au fichier de configuration `.nanorc`
|
||||
|
||||
```
|
||||
## yml
|
||||
include "~/.nanosyntax/yml.nanorc"
|
||||
```
|
||||
|
||||
|
||||
83
docs/Linux/bat.md
Normal file
83
docs/Linux/bat.md
Normal file
@@ -0,0 +1,83 @@
|
||||
# bat
|
||||
|
||||
Remplaçant de cat
|
||||
|
||||
https://github.com/sharkdp/bat
|
||||
|
||||
|
||||
|
||||
Installation:
|
||||
|
||||
```bash
|
||||
$ brew install bat
|
||||
$ brew install fzf
|
||||
```
|
||||
|
||||
Créer le fichier de configuration:
|
||||
|
||||
```bash
|
||||
$ bat --generate-config-file
|
||||
```
|
||||
|
||||
Editer la configuration:
|
||||
|
||||
```bash
|
||||
$ nano /Users/bruno/.config/bat/config
|
||||
```
|
||||
|
||||
Prévisualiser les thèmes:
|
||||
|
||||
```bash
|
||||
$ bat --list-themes | fzf --preview="bat --theme={} --color=always /Users/bruno/Documents/Scripts/bash/zsh_tools.sh"
|
||||
```
|
||||
|
||||
Tail et bat:
|
||||
|
||||
```bash
|
||||
$ tail -f /usr/local/var/log/httpd/error_log | bat --paging=never -l log
|
||||
|
||||
STDIN
|
||||
1 [Fri Nov 27 16:15:38.788043 2020] [core:notice] [pid 10014] AH00094: Command line: '/usr/local/opt/httpd/bin/httpd -D FOREGROUND'
|
||||
2 [Fri Nov 27 16:22:54.224576 2020] [mpm_prefork:notice] [pid 10014] AH00173: SIGHUP received. Attempting to restart
|
||||
3 [Fri Nov 27 16:22:54.278764 2020] [mpm_prefork:notice] [pid 10014] AH00163: Apache/2.4.46 (Unix) OpenSSL/1.1.1h PHP/8.0.0 configured -- resuming normal operations
|
||||
4 [Fri Nov 27 16:22:54.278819 2020] [core:notice] [pid 10014] AH00094: Command line: '/usr/local/opt/httpd/bin/httpd -D FOREGROUND'
|
||||
```
|
||||
|
||||
Find et bat:
|
||||
|
||||
```bash
|
||||
$ find /usr -name error_log -exec bat {} +
|
||||
|
||||
-rw-r--r-- 1 root wheel 0 Oct 18 2019 rmtab
|
||||
File: /usr/local/var/log/httpd/error_log
|
||||
1 AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using SilverBook.local. Set the 'ServerName' directive globally to suppress this message
|
||||
2 [Tue Aug 06 11:06:14.901395 2019] [mpm_prefork:notice] [pid 51047] AH00163: Apache/2.4.39 (Unix) configured -- resuming normal operations
|
||||
3 [Tue Aug 06 11:06:14.904904 2019] [core:notice] [pid 51047] AH00094: Command line: '/usr/local/opt/httpd/bin/httpd -D FOREGROUND'
|
||||
|
||||
```
|
||||
|
||||
Man pages:
|
||||
|
||||
```bash
|
||||
$ export MANPAGER="sh -c 'col -bx | bat -l man -p'"
|
||||
man 2 select
|
||||
```
|
||||
|
||||
|
||||
|
||||
## bat-extras
|
||||
|
||||
https://github.com/eth-p/bat-extras/blob/master/README.md#installation
|
||||
|
||||
```bash
|
||||
$ brew install eth-p/software/bat-extras
|
||||
```
|
||||
|
||||
[batman](https://github.com/eth-p/bat-extras/blob/master/doc/batman.md)
|
||||
|
||||
[batgrep](https://github.com/eth-p/bat-extras/blob/master/doc/batgrep.md)
|
||||
|
||||
[batwatch](https://github.com/eth-p/bat-extras/blob/master/doc/batwatch.md)
|
||||
|
||||
[batdiff](https://github.com/eth-p/bat-extras/blob/master/doc/batdiff.md)
|
||||
|
||||
118
docs/Linux/compare.md
Normal file
118
docs/Linux/compare.md
Normal file
@@ -0,0 +1,118 @@
|
||||
# Comparer 2 fichiers:
|
||||
|
||||
|
||||
|
||||
### diff:
|
||||
|
||||
Voir les différences:
|
||||
|
||||
```bash
|
||||
$ diff php73.ini php74.ini
|
||||
|
||||
11a12
|
||||
> upload_max_filesize = 32M
|
||||
16c17
|
||||
< extension_dir = /usr/local/lib/php73/modules
|
||||
---
|
||||
> extension_dir = /usr/local/lib/php74/modules
|
||||
38c39
|
||||
< upload_max_filesize = 32M
|
||||
---
|
||||
```
|
||||
|
||||
|
||||
|
||||
Comparaison côte à côte:
|
||||
|
||||
```bash
|
||||
$ diff -y php73.ini php74.ini
|
||||
|
||||
[core] [core]
|
||||
sendmail_path = /usr/bin/ssmtp -t sendmail_path = /usr/bin/ssmtp -t
|
||||
ignore_repeated_source = 0 ignore_repeated_source = 0
|
||||
xmlrpc_error_number = 0 xmlrpc_error_number = 0
|
||||
memory_limit = 128M memory_limit = 128M
|
||||
output_buffering = 4096 output_buffering = 4096
|
||||
auto_globals_jit = 1 auto_globals_jit = 1
|
||||
include_path = .:/usr/share/pear include_path = .:/usr/share/pear
|
||||
log_errors = On log_errors = On
|
||||
allow_url_fopen = 1 allow_url_fopen = 1
|
||||
enable_dl = Off enable_dl = Off
|
||||
> upload_max_filesize = 32M
|
||||
enable_post_data_reading = 1 enable_post_data_reading = 1
|
||||
ignore_user_abort = 0 ignore_user_abort = 0
|
||||
display_startup_errors = 0 display_startup_errors = 0
|
||||
sys_temp_dir = /var/services/tmp sys_temp_dir = /var/services/tmp
|
||||
extension_dir = /usr/local/lib/php73/modules | extension_dir = /usr/local/lib/php74/modules
|
||||
```
|
||||
|
||||
|
||||
|
||||
Comparaison côte à côte (largeur limitée à 70 colonnes):
|
||||
|
||||
```bash
|
||||
$ diff -y -W 70 php73.ini php74.ini
|
||||
[core] [core]
|
||||
sendmail_path = /usr/bin/ssmtp sendmail_path = /usr/bin/ssmtp
|
||||
ignore_repeated_source = 0 ignore_repeated_source = 0
|
||||
xmlrpc_error_number = 0 xmlrpc_error_number = 0
|
||||
memory_limit = 128M memory_limit = 128M
|
||||
output_buffering = 4096 output_buffering = 4096
|
||||
auto_globals_jit = 1 auto_globals_jit = 1
|
||||
include_path = .:/usr/share/pe include_path = .:/usr/share/pe
|
||||
log_errors = On log_errors = On
|
||||
allow_url_fopen = 1 allow_url_fopen = 1
|
||||
enable_dl = Off enable_dl = Off
|
||||
> upload_max_filesize = 32M
|
||||
enable_post_data_reading = 1 enable_post_data_reading = 1
|
||||
```
|
||||
|
||||
|
||||
|
||||
Juste savoir si les 2 fichiers diffèrent:
|
||||
|
||||
```bash
|
||||
$ diff -q php73.ini php74.ini
|
||||
Files php73.ini and php74.ini differ
|
||||
```
|
||||
|
||||
|
||||
|
||||
On peut supprimer les lignes identiques (`--suppress-common-lines`):
|
||||
|
||||
```bash
|
||||
$ diff -y -W 70 --suppress-common-lines php73.ini php74.ini
|
||||
> upload_max_filesize = 32M
|
||||
extension_dir = /usr/local/lib | extension_dir = /usr/local/lib
|
||||
upload_max_filesize = 32M | unserialize_max_depth = 4096
|
||||
> zend.exception_ignore_args = 0
|
||||
> [gd]
|
||||
> gd.jpeg_ignore_warning = 1
|
||||
>
|
||||
[gd] | [session]
|
||||
gd.jpeg_ignore_warning = 1 | session.cookie_samesite =
|
||||
```
|
||||
|
||||
|
||||
|
||||
Colordiff peut comparer 2 dossiers:
|
||||
|
||||
```bash
|
||||
$ diff -rq photonix photoprism
|
||||
Only in photonix: .DS_Store
|
||||
Only in photonix: data
|
||||
Files photonix/docker-compose.yml and photoprism/docker-compose.yml differ
|
||||
```
|
||||
|
||||
|
||||
|
||||
### colordiff:
|
||||
|
||||
|
||||
|
||||
### diffmerge (GUI):
|
||||
|
||||
```bash
|
||||
❯ diffmerge config.json config.json.bak
|
||||
```
|
||||
|
||||
@@ -32,6 +32,12 @@ fi
|
||||
if [ "$choice" == "72" ]; then echo "sphp 72"; elif [ "$choice" == "73" ]; then echo "sphp 73"; fi
|
||||
```
|
||||
|
||||
### Ternaire
|
||||
|
||||
```bash
|
||||
[ "$nb" -gt 1 ] && echo -e "condition ok" || echo -e "condition nok"
|
||||
```
|
||||
|
||||
|
||||
|
||||
### if imbriqué
|
||||
@@ -86,6 +92,22 @@ fi
|
||||
|
||||
#### -fichier
|
||||
|
||||
Si le répertoire *<u>directory</u>* existe
|
||||
|
||||
```bash
|
||||
if [ -d directory ]; then
|
||||
|
||||
if [ -d ~/.kde ]; then
|
||||
```
|
||||
|
||||
Si le fichier *<u>regularfile</u> (ni un blockspecialfile, ni un characterspecialfile, ni un directory)* existe
|
||||
|
||||
```bash
|
||||
if [ -f regularfile ]; then
|
||||
|
||||
if [ -f ~/.bashrc ]; then
|
||||
```
|
||||
|
||||
Si le fichier *<u>existingfile</u>* existe
|
||||
|
||||
```bash
|
||||
@@ -112,22 +134,6 @@ if [ -c characterspecialfile ]; then
|
||||
if [ -c /dev/dsp ]; then
|
||||
```
|
||||
|
||||
Si le répertoire *<u>directory</u>* existe
|
||||
|
||||
```bash
|
||||
if [ -d directory ]; then
|
||||
|
||||
if [ -d ~/.kde ]; then
|
||||
```
|
||||
|
||||
Si le fichier *<u>regularfile</u> (ni un blockspecialfile, ni un characterspecialfile, ni un directory)* existe
|
||||
|
||||
```bash
|
||||
if [ -f regularfile ]; then
|
||||
|
||||
if [ -f ~/.bashrc ]; then
|
||||
```
|
||||
|
||||
Si le fichier *<u>sgidfile</u> (set-group-ID)* existe
|
||||
|
||||
```bash
|
||||
@@ -445,3 +451,24 @@ Si NUM 1 est <u>inférieur ou égal à</u> (( NUM1 <= NUM2 ))
|
||||
if (( NUM1 <= NUM2 )); then
|
||||
```
|
||||
|
||||
|
||||
|
||||
#### -test si la variable est un entier/decimal/chaine:
|
||||
|
||||
```bash
|
||||
#!/bin/bash
|
||||
read -p "Type a number or a string: " input
|
||||
if [[ $input =~ ^[+-]?[0-9]+$ ]]; then
|
||||
echo "Input is an integer."
|
||||
|
||||
elif [[ $input =~ ^[+-]?[0-9]+\.$ ]]; then
|
||||
echo "Input is a string."
|
||||
|
||||
elif [[ $input =~ ^[+-]?[0-9]+\.?[0-9]*$ ]]; then
|
||||
echo "Input is a float."
|
||||
|
||||
else
|
||||
echo "Input is a string."
|
||||
fi
|
||||
```
|
||||
|
||||
|
||||
50
docs/Linux/cron.md
Normal file
50
docs/Linux/cron.md
Normal file
@@ -0,0 +1,50 @@
|
||||
# cron
|
||||
|
||||
|
||||
|
||||
```bash
|
||||
* * * * * command(s)
|
||||
^ ^ ^ ^ ^
|
||||
| | | | | allowed values
|
||||
| | | | | -------
|
||||
| | | | ----- Day of week (0 - 7) (Sunday=0 or 7)
|
||||
| | | ------- Month (1 - 12)
|
||||
| | --------- Day of month (1 - 31)
|
||||
| ----------- Hour (0 - 23)
|
||||
------------- Minute (0 - 59)
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
| | | |
|
||||
| -------- | -------------------- | ----------------------------------------------- |
|
||||
| @yearly | 0 0 1 1 * | Tous les 1er janvier à midi |
|
||||
| @monthly | 0 0 1 * * | Tous les 1er du mois à minuit |
|
||||
| @weekly | 0 0 * * 0 | Tous les dimanches à minuit |
|
||||
| @daily | 0 0 * * * | Tous les jours à minuit |
|
||||
| @hourly | 0 * * * * | Toutes les heures |
|
||||
| @reboot | | Au démarrage de l'ordinateur |
|
||||
| | 0 15 * * 1-5 command | Tous les jours à 15h du lundi au vendredi |
|
||||
| | 00 08-16 * * * | Toutes les jours, toutes les heures de 8h à 16h |
|
||||
| | 0 7 1-7 * 1 | Le 1er lundi de chaque mois à 7h |
|
||||
| | 15 9 1,15 * * | Le 1er et le 15 du mois à 9h15 |
|
||||
| | */15 * * * * | Toutes les 15 mn |
|
||||
|
||||
|
||||
|
||||
#### La commande crontab:
|
||||
|
||||
- `crontab -e`: édite ou crée le fichier crontab.
|
||||
- `crontab -l`: affiche le fichier crontab.
|
||||
- `crontab -r`: supprime le fichier crontab (directement).
|
||||
- `crontab -i`: supprime le fichier crontab (prompt).
|
||||
- `crontab -u <user> `: édite le fichier crontab d'un autre utilisateur.
|
||||
|
||||
Le fichier crontab s'ouvre dans l'éditeur spécifié par la variable d'environnement EDITOR (ou VISUAL).
|
||||
|
||||
|
||||
|
||||
https://linuxize.com/post/scheduling-cron-jobs-with-crontab/
|
||||
|
||||
125
docs/Linux/fd.md
Normal file
125
docs/Linux/fd.md
Normal file
@@ -0,0 +1,125 @@
|
||||
# fd
|
||||
|
||||
(alternative à [find](find.md)) (macOS / Linux / Windows)
|
||||
|
||||
```bash
|
||||
$ brew install fd
|
||||
```
|
||||
|
||||
```
|
||||
choco install fd
|
||||
```
|
||||
|
||||
|
||||
|
||||
Recherche un fichier dans le répertoire courant (et sous-dossiers):
|
||||
|
||||
```bash
|
||||
~ master* ⇡
|
||||
❯ fd -H .zshrc
|
||||
.zshrc
|
||||
|
||||
~/.config master* ⇡
|
||||
❯ fd -HI pip.conf
|
||||
pip/pip.conf
|
||||
|
||||
```
|
||||
|
||||
Recherche dans un répertoire particulier:
|
||||
|
||||
```bash
|
||||
~ master* ⇡
|
||||
❯ fd -HI 'id_*' .ssh
|
||||
.ssh/id_ed25519
|
||||
.ssh/id_ed25519.pub
|
||||
.ssh/id_rsa
|
||||
.ssh/id_rsa.pub
|
||||
.ssh/id_rsa.zip
|
||||
```
|
||||
|
||||
Recherche par regex:
|
||||
|
||||
```bash
|
||||
~ master* ⇡ 4m 27s
|
||||
❯ fd -HI '^h.*.conf$' /etc
|
||||
/etc/apache2/extra/httpd-autoindex.conf
|
||||
/etc/apache2/extra/httpd-dav.conf
|
||||
/etc/apache2/extra/httpd-default.conf
|
||||
/etc/apache2/extra/httpd-info.conf
|
||||
/etc/apache2/extra/httpd-languages.conf
|
||||
/etc/apache2/extra/httpd-manual.conf
|
||||
/etc/apache2/extra/httpd-mpm.conf
|
||||
/etc/apache2/extra/httpd-multilang-errordoc.conf
|
||||
/etc/apache2/extra/httpd-ssl.conf
|
||||
/etc/apache2/extra/httpd-userdir.conf
|
||||
/etc/apache2/extra/httpd-vhosts.conf
|
||||
/etc/apache2/httpd.conf
|
||||
...
|
||||
```
|
||||
|
||||
https://docs.rs/regex/1.0.0/regex/#syntax
|
||||
|
||||
Fichiers se terminant par *'[0-9].jpg'*:
|
||||
|
||||
```bash
|
||||
$ fd -HI '.*[0-9]\.jpg$' ~
|
||||
|
||||
$ find ~ -iname '*[0-9].jpg'
|
||||
```
|
||||
|
||||
Sans arguments:
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Option:
|
||||
|
||||
- --hidden: cherche dans les dossiers cachés
|
||||
- --no-ignore:
|
||||
- -x / --exec:
|
||||
|
||||
|
||||
|
||||
```bash
|
||||
$ fd -h
|
||||
fd 8.1.1
|
||||
|
||||
USAGE:
|
||||
fd [FLAGS/OPTIONS] [<pattern>] [<path>...]
|
||||
|
||||
FLAGS:
|
||||
-H, --hidden Search hidden files and directories
|
||||
-I, --no-ignore Do not respect .(git|fd)ignore files
|
||||
-s, --case-sensitive Case-sensitive search (default: smart case)
|
||||
-i, --ignore-case Case-insensitive search (default: smart case)
|
||||
-g, --glob Glob-based search (default: regular expression)
|
||||
-a, --absolute-path Show absolute instead of relative paths
|
||||
-l, --list-details Use a long listing format with file metadata
|
||||
-L, --follow Follow symbolic links
|
||||
-p, --full-path Search full path (default: file-/dirname only)
|
||||
-0, --print0 Separate results by the null character
|
||||
-h, --help Prints help information
|
||||
-V, --version Prints version information
|
||||
|
||||
OPTIONS:
|
||||
-d, --max-depth <depth> Set maximum search depth (default: none)
|
||||
-t, --type <filetype>... Filter by type: file (f), directory (d), symlink (l),
|
||||
executable (x), empty (e), socket (s), pipe (p)
|
||||
-e, --extension <ext>... Filter by file extension
|
||||
-x, --exec <cmd> Execute a command for each search result
|
||||
-X, --exec-batch <cmd> Execute a command with all search results at once
|
||||
-E, --exclude <pattern>... Exclude entries that match the given glob pattern
|
||||
-c, --color <when> When to use colors: never, *auto*, always
|
||||
-S, --size <size>... Limit results based on the size of files.
|
||||
--changed-within <date|dur> Filter by file modification time (newer than)
|
||||
--changed-before <date|dur> Filter by file modification time (older than)
|
||||
-o, --owner <user:group> Filter by owning user and/or group
|
||||
|
||||
ARGS:
|
||||
<pattern> the search pattern - a regular expression unless '--glob' is used (optional)
|
||||
<path>... the root directory for the filesystem search (optional)
|
||||
|
||||
Note: `fd -h` prints a short and concise overview while `fd --help` gives all details.
|
||||
```
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
# find
|
||||
|
||||
(Voir aussi [fd](fd.md))
|
||||
|
||||
|
||||
|
||||
La commande **find** permet de retrouver des fichiers à partir de certains critères. Elle doit être utilisé avec l'option **-print**
|
||||
@@ -21,16 +23,64 @@ Les <u>critères de recherche</u> sont les suivants :
|
||||
|
||||
|
||||
|
||||
#### Nom:
|
||||
|
||||
Recherche par <u>nom de fichier</u>:
|
||||
|
||||
```bash
|
||||
find /usr -name toto -print
|
||||
$ find /usr -name toto -print
|
||||
|
||||
find /usr -name " *.c " -print
|
||||
$ find /usr -name " *.c " -print
|
||||
|
||||
# commence par un a ou A, suivi de quelque chose, et se termine par un chiffre compris entre 3 et 6
|
||||
|
||||
find . -name '[aA]*[3-6]' -print
|
||||
$ find . -name '[aA]*[3-6]' -print
|
||||
```
|
||||
|
||||
|
||||
|
||||
#### Taille:
|
||||
|
||||
Recherche suivant la <u>taille</u>:
|
||||
|
||||
```bash
|
||||
# fichiers dont la taille dépasse 30ko
|
||||
|
||||
$ find / -size +30k -print
|
||||
|
||||
# fichiers dont la taille est comprise entre 30 et 100ko
|
||||
|
||||
$ find / -size +30k -size -100k
|
||||
```
|
||||
|
||||
|
||||
|
||||
#### Opérateurs logiques:
|
||||
|
||||
Recherche en utilisant les <u>opérateurs logiques</u>:
|
||||
|
||||
```bash
|
||||
# les fichiers n'appartenant pas à l'utilisateur olivierles fichiers n'appartenant pas à l'utilisateur olivier
|
||||
|
||||
$ find . ! -user olivier -print
|
||||
|
||||
# Recherche les fichiers dont le nom est a.out ou les fichiers se terminant par *.c (une condition OU l'autre).
|
||||
|
||||
$ find . \ ( -name a.out -o -name " *.c " \ ) -print
|
||||
|
||||
# Recherche des fichiers dont le nom est core et d'une taille supérieure à 1Mo (une condition ET l'autre).
|
||||
|
||||
$ find . \ (-name core -a size +2000 \ ) -print
|
||||
```
|
||||
|
||||
|
||||
|
||||
#### Date:
|
||||
|
||||
Rechercher <u>le plus vieux</u> fichier:
|
||||
|
||||
```bash
|
||||
$ find / -type f -printf '%T+ %p\n' | sort | head -n 1
|
||||
```
|
||||
|
||||
Recherche suivant la <u>date de dernière modification</u>:
|
||||
@@ -38,53 +88,69 @@ Recherche suivant la <u>date de dernière modification</u>:
|
||||
```bash
|
||||
# modifiés il y a 30 jours
|
||||
|
||||
find / -mtime 30 -print
|
||||
$ find / -mtime 30 -print
|
||||
|
||||
# modifiés il y a 30 jours ou plus
|
||||
|
||||
find / -mtime +30 -print
|
||||
$ find / -mtime +30 -print
|
||||
|
||||
# modifiés il y a 30 jours ou moins
|
||||
|
||||
find / -mtime 30 -print
|
||||
$ find / -mtime 30 -print
|
||||
|
||||
# modifiés il y a plus de 50 jours et moins de 100
|
||||
|
||||
$ find / -mtime +50 –mtime -100
|
||||
|
||||
# modifiés dans la dernière heure
|
||||
|
||||
$ find / -mmin -60
|
||||
|
||||
# accédées dans la dernière heure
|
||||
|
||||
$ find / -amin -60
|
||||
```
|
||||
|
||||
```bash
|
||||
find . -mtime +0 # find files modified greater than 24 hours ago
|
||||
find . -mtime 0 # find files modified between now and 1 day ago (i.e., in the past 24 hours only)
|
||||
find . -mtime -1 # find files modified less than 1 day ago (SAME AS -mtime 0)
|
||||
find . -mtime 1 # find files modified between 24 and 48 hours ago
|
||||
find . -mtime +1 # find files modified more than 48 hours ago
|
||||
$ find . -mtime +0 # find files modified greater than 24 hours ago
|
||||
$ find . -mtime 0 # find files modified between now and 1 day ago (i.e., in the past 24 hours only)
|
||||
$ find . -mtime -1 # find files modified less than 1 day ago (SAME AS -mtime 0)
|
||||
$ find . -mtime 1 # find files modified between 24 and 48 hours ago
|
||||
$ find . -mtime +1 # find files modified more than 48 hours ago
|
||||
```
|
||||
|
||||
Rechercher <u>le plus vieux</u> fichier:
|
||||
|
||||
|
||||
#### Permissions:
|
||||
|
||||
Rechercher des <u>permissions</u>:
|
||||
|
||||
```bash
|
||||
find / -type f -printf '%T+ %p\n' | sort | head -n 1
|
||||
$ find /volume1/@appstore/PHP7.4/etc -perm 644
|
||||
/volume1/@appstore/PHP7.4/etc/php/conf.d/memcached.ini
|
||||
/volume1/@appstore/PHP7.4/etc/php/conf.d/redis.ini
|
||||
|
||||
$ ls -la
|
||||
-rw-r--r-- 1 root root 25 Sep 14 13:39 memcached.ini
|
||||
-rw-r--r-- 1 root root 21 Sep 14 13:39 redis.ini
|
||||
```
|
||||
|
||||
Recherche suivant la <u>taille</u>:
|
||||
<u>Inverser</u> la recherche (!):
|
||||
|
||||
```bash
|
||||
# fichiers dont la taille dépasse 30ko
|
||||
|
||||
find / -size +30k -print
|
||||
$ find /volume1/@appstore/PHP7.4/etc ! -perm 644
|
||||
/volume1/@appstore/PHP7.4/etc
|
||||
/volume1/@appstore/PHP7.4/etc/php
|
||||
/volume1/@appstore/PHP7.4/etc/php/conf.d
|
||||
```
|
||||
|
||||
Recherche en utilisant les <u>opérateurs logiques</u>:
|
||||
Rechercher les fichiers avec permission 777 et les modifiés en 644:
|
||||
|
||||
```bash
|
||||
# les fichiers n'appartenant pas à l'utilisateur olivierles fichiers n'appartenant pas à l'utilisateur olivier
|
||||
$ find / -type f -perm 0777 -print -exec chmod 644 {} \;
|
||||
|
||||
find . ! -user olivier -print
|
||||
|
||||
# Recherche les fichiers dont le nom est a.out ou les fichiers se terminant par *.c (une condition OU l'autre).
|
||||
|
||||
find . \ ( -name a.out -o -name " *.c " \ ) -print
|
||||
|
||||
# Recherche des fichiers dont le nom est core et d'une taille supérieure à 1Mo (une condition ET l'autre).
|
||||
|
||||
find . \ (-name core -a size +2000 \ ) -print
|
||||
# idem pour les dossiers
|
||||
$ find / -type d -perm 777 -print -exec chmod 755 {} \;
|
||||
```
|
||||
|
||||
Recherche <u>combinée</u>:
|
||||
@@ -92,53 +158,208 @@ Recherche <u>combinée</u>:
|
||||
```bash
|
||||
# les fichiers de l'utilisateur bruno dont les permissions sont 755
|
||||
|
||||
find / -type f -user bruno -perm 755 -print
|
||||
$ find / -type f -user bruno -perm 755 -print
|
||||
```
|
||||
|
||||
Rechercher les exécutables:
|
||||
|
||||
```bash
|
||||
$ find /var/services/homes/bruno -perm /a=x
|
||||
```
|
||||
|
||||
Rechercher les fichiers en lecture seule:
|
||||
|
||||
```bash
|
||||
$ find /var/services/homes/bruno -perm /u=r
|
||||
```
|
||||
|
||||
|
||||
|
||||
#### Regex:
|
||||
|
||||
Recherche avec <u>regex</u>:
|
||||
|
||||
```bash
|
||||
# les images avec extentions jpg|gif|png|jpeg dans le dossier Users
|
||||
# -E => macOS only ??
|
||||
|
||||
find -E /Users/bruno -regex ".*\.(jpg|gif|png|jpeg)"
|
||||
$ find -E /Users/bruno -regex ".*\.(jpg|gif|png|jpeg)"
|
||||
$ find -E $HOME/Music -regex ".*\.(mp3|flac)"
|
||||
|
||||
# non case-sensitive
|
||||
find -E /Users/bruno -iregex ".*\.(jpg|gif|png|jpeg)"
|
||||
$ find -E /Users/bruno -iregex ".*\.(jpg|gif|png|jpeg)"
|
||||
|
||||
# Linux / GNU find (macOS)
|
||||
$ find $HOME/Music -regex ".*\.\(mp3\|flac\)"
|
||||
$ gfind $HOME/Music -regex ".*\.\(mp3\|flac\)"
|
||||
```
|
||||
|
||||
|
||||
|
||||
Commandes en option:
|
||||
#### User / group:
|
||||
|
||||
```bash
|
||||
$ find /home -user bruno
|
||||
|
||||
$ find /home -group http
|
||||
```
|
||||
|
||||
|
||||
|
||||
#### Commandes en option:
|
||||
|
||||
```bash
|
||||
# Recherche les fichiers toto et les efface.
|
||||
|
||||
find . -name toto -exec rm {}\ ;
|
||||
$ find . -name toto -exec rm {}\ ;
|
||||
|
||||
# Pour avoir une demande de confirmation avant l'exécution de rm
|
||||
|
||||
find . -name toto -ok rm {}\ ;
|
||||
$ find . -name toto -ok rm {}\ ;
|
||||
```
|
||||
|
||||
Utilisation avec d'autres commandes:'
|
||||
|
||||
|
||||
#### Utilisation avec d'autres commandes:'
|
||||
|
||||
```bash
|
||||
# Recherche les fichiers normaux dans le répertoire courant, puis chercher le chaine toto dans ces fichiers.
|
||||
|
||||
find . -type f -print | xargs grep toto
|
||||
$ find . -type f -print | xargs grep toto
|
||||
|
||||
# Recherche les fichiers toto et les efface après confimation (-p).
|
||||
# idem -exec, " | xargs " ne crée qu'un seim processus.
|
||||
|
||||
find . -name toto | xargs -p rm
|
||||
$ find . -name toto | xargs -p rm
|
||||
```
|
||||
|
||||
|
||||
|
||||
Redirection des messages d'erreur:
|
||||
#### Effacer tous les fichiers d'un dossier sauf un:
|
||||
|
||||
```bash
|
||||
find / -name toto -print 2>/dev/null
|
||||
$ find . -type f ! -name 'fichier-a-garder.tar.gz' -delete
|
||||
```
|
||||
|
||||
|
||||
|
||||
#### Présentation de la sortie:
|
||||
|
||||
l'option -ls correspond à un 'ls -dils'
|
||||
|
||||
```bash
|
||||
$ find /var/services/homes/bruno -name "*php*.ini" -ls
|
||||
56408 72 -rwxrwxrwx 1 bruno users 72040 Nov 10 2017 /var/services/homes/bruno/Drive/Drive/Apache\ -\ PHP/Backup\ Silverbook/php.ini
|
||||
364193 8 -rw-r--r-- 1 root root 8169 Nov 13 10:53 /var/services/homes/bruno/php74.ini
|
||||
364195 8 -rw-r--r-- 1 root root 8145 Nov 13 10:55 /var/services/homes/bruno/php73.ini
|
||||
```
|
||||
|
||||
|
||||
|
||||
#### printf
|
||||
|
||||
affiche le *format* indiqué sur la sortie standard
|
||||
|
||||
```bash
|
||||
# taille en octet - nom
|
||||
$ find /var/services/homes/bruno -name "*php*.ini" -printf '%s %p\n'
|
||||
72040 /var/services/homes/bruno/Drive/Drive/Apache - PHP/Backup Silverbook/php.ini
|
||||
8169 /var/services/homes/bruno/php74.ini
|
||||
8145 /var/services/homes/bruno/php73.ini
|
||||
|
||||
# date - bits - user:group - taille en octet - nom
|
||||
$ find /var/services/homes/bruno -name "*php*.ini" -printf "%t %M %u:%g %s %p\n"
|
||||
Fri Nov 10 09:10:42.0000000000 2017 -rwxrwxrwx bruno:users 72040 9 /var/services/homes/bruno/Drive/Drive/Apache - PHP/Backup Silverbook/php.ini
|
||||
Fri Nov 13 10:53:58.5922529060 2020 -rw-r--r-- root:root 8169 10 /var/services/homes/bruno/php74.ini
|
||||
Fri Nov 13 10:55:50.7925348300 2020 -rw-r--r-- root:root 8145 10 /var/services/homes/bruno/php73.ini
|
||||
```
|
||||
|
||||
| | |
|
||||
| ---- | ------------------------------------------------------------ |
|
||||
| %u | Nom du propriétaire du fichier |
|
||||
| %g | Nom du groupe propriétaire du fichier |
|
||||
| %s | Taille du fichier en octets |
|
||||
| %k | Taille du fichier en ko |
|
||||
| %p | Nom du fichier |
|
||||
| | |
|
||||
| %t | Date de dernière modification du fichier |
|
||||
| %Tk | Date de dernière modification du fichier |
|
||||
| %m | Bits d'autorisation d'accès au fichier (en octal)(644/755) |
|
||||
| %M | Bits d'autorisation d'accès au fichier (symbole)(-rw-r--r--) |
|
||||
|
||||
|
||||
|
||||
#### fprintf *fichier* format
|
||||
|
||||
écrit le nom complet dans le *fichier*. Si *fichier* n'existe pas au démarrage de **find**, il est créé. S'il existe, il est écrasé.
|
||||
|
||||
|
||||
|
||||
#### Redirection des messages d'erreur:
|
||||
|
||||
```bash
|
||||
$ find /volume1/@appstore/ -name "*php*.ini"
|
||||
/volume1/@appstore/PHP7.0/usr/local/etc/php70/php.ini
|
||||
find: ‘/volume1/@appstore/DNSServer/named/etc/key’: Permission denied
|
||||
find: ‘/volume1/@appstore/DNSServer/named/usr/lib/ocf/lib’: Permission denied
|
||||
find: ‘/volume1/@appstore/DNSServer/named/usr/lib/ocf/resource.d’: Permission denied
|
||||
find: ‘/volume1/@appstore/DNSServer/named/usr/lib/heartbeat/plugins’: Permission denied
|
||||
/volume1/@appstore/PHP7.2/misc/php-fpm.ini
|
||||
/volume1/@appstore/PHP7.2/usr/local/etc/php72/cli/php.ini
|
||||
find: ‘/volume1/@appstore/Gitea/gitea/data’: Permission denied
|
||||
find: ‘/volume1/@appstore/Gitea/gitea/.ssh’: Permission denied
|
||||
/volume1/@appstore/PHP7.3/misc/php-fpm.ini
|
||||
/volume1/@appstore/PHP7.3/usr/local/etc/php73/cli/php.ini
|
||||
/volume1/@appstore/WebStation/misc/php56.ini
|
||||
/volume1/@appstore/WebStation/misc/php70.ini
|
||||
/volume1/@appstore/phpMyAdmin/php_conf/phpMyAdmin.ini
|
||||
/volume1/@appstore/PHP7.4/misc/php-fpm.ini
|
||||
/volume1/@appstore/PHP7.4/usr/local/etc/php74/cli/php.ini
|
||||
```
|
||||
Tous les messages d'erreurs sont redirigés avec `2>/dev/null` vers la poubelle.
|
||||
```bash
|
||||
$ find /volume1/@appstore/ -name "*php*.ini" 2>/dev/null
|
||||
/volume1/@appstore/PHP7.0/usr/local/etc/php70/php.ini
|
||||
/volume1/@appstore/PHP7.2/misc/php-fpm.ini
|
||||
/volume1/@appstore/PHP7.2/usr/local/etc/php72/cli/php.ini
|
||||
/volume1/@appstore/PHP7.3/misc/php-fpm.ini
|
||||
/volume1/@appstore/PHP7.3/usr/local/etc/php73/cli/php.ini
|
||||
/volume1/@appstore/WebStation/misc/php56.ini
|
||||
/volume1/@appstore/WebStation/misc/php70.ini
|
||||
/volume1/@appstore/phpMyAdmin/php_conf/phpMyAdmin.ini
|
||||
/volume1/@appstore/PHP7.4/misc/php-fpm.ini
|
||||
/volume1/@appstore/PHP7.4/usr/local/etc/php74/cli/php.ini
|
||||
```
|
||||
|
||||
C'est un peu plus propre.
|
||||
|
||||
Autre solution avec `grep -v "Permission denied"`, les autres messages d'erreurs restent affichés.
|
||||
|
||||
```bash
|
||||
$ find / -name "*php*.ini" 2>&1 | grep -v "Permission denied"
|
||||
/etc/php/php.ini
|
||||
/volume1/@appstore/PHP7.0/usr/local/etc/php70/php.ini
|
||||
/volume1/@appstore/PHP7.2/misc/php-fpm.ini
|
||||
/volume1/@appstore/PHP7.2/usr/local/etc/php72/cli/php.ini
|
||||
/volume1/@appstore/PHP7.3/misc/php-fpm.ini
|
||||
/volume1/@appstore/PHP7.3/usr/local/etc/php73/cli/php.ini
|
||||
/volume1/@appstore/WebStation/misc/php56.ini
|
||||
/volume1/@appstore/WebStation/misc/php70.ini
|
||||
/volume1/@appstore/phpMyAdmin/php_conf/phpMyAdmin.ini
|
||||
/volume1/@appstore/PHP7.4/misc/php-fpm.ini
|
||||
/volume1/@appstore/PHP7.4/usr/local/etc/php74/cli/php.ini
|
||||
...
|
||||
/volume1/@Entware/opt/etc/php.ini
|
||||
/volume1/docker/piwigo/config/php/php-local.ini
|
||||
/etc.defaults/php/php.ini
|
||||
/opt/etc/php.ini
|
||||
/usr/syno/etc/packages/WebStation/php70/php.ini
|
||||
/usr/syno/etc/packages/WebStation/php56/php.ini
|
||||
/usr/local/etc/php70/php.ini
|
||||
/usr/local/etc/php73/cli/php.ini
|
||||
/usr/local/etc/php74/cli/php.ini
|
||||
/usr/local/etc/php72/cli/php.ini
|
||||
/usr/local/etc/php72/cli/conf.d/phpMyAdmin.ini
|
||||
find: ‘/proc/24000/net’: Invalid argument
|
||||
```
|
||||
|
||||
|
||||
@@ -314,7 +314,7 @@ raspbian
|
||||
|
||||
|
||||
|
||||
#### Suprression de caractères:
|
||||
#### Supression de caractères:
|
||||
|
||||
Commande:
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
|
||||
|
||||
|
||||
### Recharger la configuration:
|
||||
#### Recharger la configuration:
|
||||
|
||||
```bash
|
||||
$ source ~/.profile
|
||||
@@ -38,4 +38,101 @@ ou
|
||||
$ . ~/.profile
|
||||
```
|
||||
|
||||
On peut aussi créer un alias: `alias rload=". ~/.profile"`
|
||||
On peut aussi créer un alias: `alias rload=". ~/.profile"`
|
||||
|
||||
#### Historique:
|
||||
|
||||
```bash
|
||||
❯ history
|
||||
4235* cd perl
|
||||
4237* git reset
|
||||
4238* git reset --hard
|
||||
4239* kymsu2
|
||||
4242* rm -rf .git
|
||||
4244* git init
|
||||
4246* cd
|
||||
4247* cd Pictures/thumbsup
|
||||
4248* nano config.json
|
||||
4249* cd ..
|
||||
4250* cd thumbsup
|
||||
4252* 916e
|
||||
4255 rm .DS_Store
|
||||
4257 l
|
||||
4258 nano LICENSE
|
||||
4259 nano README.md
|
||||
```
|
||||
|
||||
Exécuter une précédente commande (!):
|
||||
|
||||
```bash
|
||||
❯ !4231
|
||||
916e
|
||||
bruno@DS916:~ $
|
||||
```
|
||||
|
||||
Executer la commande précédente (!!):
|
||||
|
||||
```bash
|
||||
❯ nano README.md
|
||||
|
||||
❯ !!
|
||||
nano README.md
|
||||
```
|
||||
|
||||
Les 5 dernières commandes:
|
||||
|
||||
```
|
||||
❯ history -5
|
||||
4253 pwd
|
||||
4254 hostname
|
||||
4255 history
|
||||
4256 nano config.json
|
||||
4257 history 5
|
||||
```
|
||||
|
||||
Exécuter la dernière commande 'nano':
|
||||
|
||||
```bash
|
||||
❯ !nano
|
||||
nano config.json
|
||||
```
|
||||
|
||||
Voir la dernière commande 'nano (:p)':
|
||||
|
||||
```bash
|
||||
❯ !nano:p
|
||||
nano config.json
|
||||
```
|
||||
|
||||
#### "Reverse i" search:
|
||||
|
||||
Taper **Ctrl+R** puis 'ssh':
|
||||
|
||||
```bash
|
||||
❯ ssh dsm414
|
||||
bck-i-search: ssh_
|
||||
```
|
||||
|
||||
Taper à nouveau **Ctrl+R**:
|
||||
|
||||
```bash
|
||||
❯ git clone https://git.php.net/repository/pecl/networking/ssh2.git
|
||||
bck-i-search: ssh_
|
||||
```
|
||||
|
||||
Quand la bonne commande est trouvée, taper **Enter**. Sinon, taper Ctrl+G pour sortir.
|
||||
|
||||
<u>Commentaires interactifs:</u> ajouter #comment pour retrouver plus facilement une commande.
|
||||
|
||||
Pour zsh, activer cette fonction avec *setopt interactivecomments*.
|
||||
|
||||
```
|
||||
❯ setopt interactivecomments
|
||||
|
||||
❯ ping 192.168.1.8 #nas
|
||||
PING 192.168.1.8 (192.168.1.8): 56 data bytes
|
||||
|
||||
❯ ping 192.168.1.8 #nas
|
||||
bck-i-search: nas_
|
||||
```
|
||||
|
||||
|
||||
Reference in New Issue
Block a user