HowTo/Linux: mudanças entre as edições
< HowTo
Sem resumo de edição |
Sem resumo de edição |
||
(16 revisões intermediárias pelo mesmo usuário não estão sendo mostradas) | |||
Linha 1: | Linha 1: | ||
{{SUBHEAD}} | |||
==Debian 12== | ==Debian 12== | ||
<center>'''HowTo''' em modo intermediário, entendedores entenderão.</center> | |||
* Descomentar as seguintes linhas no arquivo: '''.bashrc''' | |||
<syntaxhighlight lang="bash" style="border: 1px solid blue;"> | |||
# colored GCC warnings and errors | |||
export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01' | |||
# some more ls aliases | |||
alias ll='ls -l' | |||
alias la='ls -A' | |||
alias l='ls -CF' | |||
</syntaxhighlight> | |||
* sudo: | * sudo: | ||
Instalar o pacote '''sudo''' e adicionar o usuário ao grupo '''sudo''': | |||
<syntaxhighlight lang="bash" style="border: 1px solid blue;"> | |||
su -l | |||
apt install sudo | |||
usermod -aG sudo <username> | |||
</syntaxhighlight> | |||
* Desligar a máquina: | * Desligar a máquina: | ||
<syntaxhighlight lang="bash" style="border: 1px solid blue;"> | |||
sudo systemctl poweroff | |||
</syntaxhighlight> | |||
===Versão=== | |||
<syntaxhighlight lang="bash" style="border: 1px solid blue;"> | |||
cat /etc/issue | |||
</syntaxhighlight> | |||
ou | |||
<syntaxhighlight lang="bash" style="border: 1px solid blue;"> | |||
cat /etc/os-release | |||
</syntaxhighlight> | |||
ou | |||
<syntaxhighlight lang="bash" style="border: 1px solid blue;"> | |||
cat /etc/debian_version | |||
</syntaxhighlight> | |||
ou | |||
<syntaxhighlight lang="bash" style="border: 1px solid blue;"> | |||
uname -a | |||
</syntaxhighlight> | |||
ou | |||
<syntaxhighlight lang="bash" style="border: 1px solid blue;"> | |||
lsb_release -a | |||
</syntaxhighlight> | |||
ou | |||
<syntaxhighlight lang="bash" style="border: 1px solid blue;"> | |||
hostnamectl | |||
</syntaxhighlight> | |||
===IP=== | ===IP=== | ||
* Obter o IP: | * Obter o IP: | ||
<syntaxhighlight lang="bash" style="border: 1px solid blue;"> | |||
ip a | |||
</syntaxhighlight> | |||
* Obter o nome da interface | * Obter o nome da interface | ||
<syntaxhighlight lang="bash" style="border: 1px solid blue;"> | |||
ip link | |||
</syntaxhighlight> | |||
* DHCP | |||
:Caso mantenha o IP dinâmico e estaja em ambiente de testes/desenvolvimento, utilizando o VirtualBox, por exemplo, para não ter que logar na máquina para descobrir o IP e acessá-la através de um cliente TTY, tipo o PuTTY, altere o arquivo: '''/etc/issue''' | |||
<syntaxhighlight lang="bash" style="border: 1px solid blue;"> | |||
Debian GNU/Linux 12 \n \l | |||
enp0s3: \4{enp0s3} | |||
</syntaxhighlight> | |||
* Configurar o IP estático: | * Configurar o IP estático: | ||
:* Comentar as linhas em: /etc/network/interfaces | :* Comentar as linhas em: '''/etc/network/interfaces''' | ||
<syntaxhighlight lang="bash" style="border: 1px solid blue;"> | |||
#allow-hotplug enp0s3 | |||
:* Acrescentar as linhas em: /etc/network/interfaces | #iface enp0s3 inet dhcp | ||
</syntaxhighlight> | |||
:* Acrescentar as linhas em: '''/etc/network/interfaces''' | |||
<syntaxhighlight lang="bash" style="border: 1px solid blue;"> | |||
auto enp0s3 | |||
iface enp0s3 inet static | |||
: | address 192.168.2.10 | ||
: | netmask 255.255.255.0 | ||
gateway 192.168.2.1 | |||
</syntaxhighlight> | |||
* Reiniciar o serviço de rede: | |||
<syntaxhighlight lang="bash" style="border: 1px solid blue;"> | |||
sudo systemctl restart networking.service | |||
</syntaxhighlight> | |||
===No Windows/VirtualBox=== | |||
# Conectar o '''Adaptador 1''' da '''Rede''' a: '''Placa em modo Bridge'''. | |||
# Para verificar qual adaptador, no host Windows, está com o '''Gateway Padrão''' e utilizá-lo para configurar o IP estático em '''/etc/network/interfaces''' acima, executar o seguinte comando em: '''cmd''' | |||
<syntaxhighlight lang="bash" style="border: 1px solid blue;"> | |||
ipconfig | |||
</syntaxhighlight> | |||
====Memória==== | |||
Caso instale o ambiente gráfico e haja problemas de memória e estaja em ambiente de testes/desenvolvimento: | |||
* Criar o script: '''/root/clearcache''' | |||
<syntaxhighlight lang="bash" style="border: 1px solid blue;"> | |||
#!/bin/bash | |||
# | |||
[[ $(</proc/meminfo awk '/^SwapCached:/ {print $2}') -gt 0 || $(</proc/meminfo awk '/^MemFree:/ {print $2}') -lt 100000 || $(</proc/meminfo awk '/^Cached:/ {print $2}') -gt 2000000 || $(</proc/meminfo awk '/^Buffers:/ {print $2}') -gt 100000 ]] && sync && echo 1 > /proc/sys/vm/drop_caches && swapoff -a && swapon -a && date >> /var/log/clear-cached.log | |||
</syntaxhighlight> | |||
* Acrescente o modo de execução ao script: | |||
<syntaxhighlight lang="bash" style="border: 1px solid blue;"> | |||
sudo chmod u+x /root/clearcache | |||
</syntaxhighlight> | |||
* Na crontab do root: | |||
<syntaxhighlight lang="bash" style="border: 1px solid blue;"> | |||
sudo crontab -u root -e | |||
</syntaxhighlight> | |||
* Acrescentar a seguinte linha: | |||
<syntaxhighlight lang="bash" style="border: 1px solid blue;"> | |||
* * * * * /bin/bash /root/clearcache | |||
</syntaxhighlight> | |||
===Pacotes=== | ===Pacotes=== | ||
* Atualizar pacotes: | * Atualizar pacotes: | ||
<syntaxhighlight lang="bash" style="border: 1px solid blue;"> | |||
sudo apt update | |||
sudo apt upgrade | |||
</syntaxhighlight> | |||
* Remover dependencias de pacotes que já não são mais necessários: | * Remover dependencias de pacotes que já não são mais necessários: | ||
<syntaxhighlight lang="bash" style="border: 1px solid blue;"> | |||
sudo apt autoremove | |||
</syntaxhighlight> | |||
* Limpar o repositório local de pacotes baixados: | * Limpar o repositório local de pacotes baixados: | ||
<syntaxhighlight lang="bash" style="border: 1px solid blue;"> | |||
sudo apt autoclean | |||
</syntaxhighlight> | |||
* Instalar pacotes: | * Instalar pacotes: | ||
** | <syntaxhighlight lang="bash" style="border: 1px solid blue;"> | ||
sudo apt install <package_name> | |||
</syntaxhighlight> | |||
* Continuar instalação interrompida: | |||
<syntaxhighlight lang="bash" style="border: 1px solid blue;"> | |||
sudo dpkg --configure -a | |||
</syntaxhighlight> | |||
* Remover pacotes: | |||
<syntaxhighlight lang="bash" style="border: 1px solid blue;"> | |||
sudo apt remove <package_name> | |||
</syntaxhighlight> | |||
* Remover completamente os pacotes (arquivos de configuração): | |||
<syntaxhighlight lang="bash" style="border: 1px solid blue;"> | |||
sudo apt purge <package_name> | |||
</syntaxhighlight> | |||
===Usuários=== | ===Usuários=== | ||
* Criar usuário: | * Criar usuário: | ||
<syntaxhighlight lang="bash" style="border: 1px solid blue;"> | |||
adduser <username> | |||
</syntaxhighlight> | |||
* Excluir usuário: | |||
<syntaxhighlight lang="bash" style="border: 1px solid blue;"> | |||
deluser <username> | |||
</syntaxhighlight> | |||
* Adicionar usuário a um grupo: | |||
<syntaxhighlight lang="bash" style="border: 1px solid blue;"> | |||
usermod -aG <group> <username> | |||
</syntaxhighlight> | |||
* Remover usuário de um grupo: | |||
<syntaxhighlight lang="bash" style="border: 1px solid blue;"> | |||
usermod -rG <group> <username> | |||
</syntaxhighlight> | |||
* Exibir os grupos de um usuário: | |||
<syntaxhighlight lang="bash" style="border: 1px solid blue;"> | |||
groups <username> | |||
</syntaxhighlight> | |||
ou | |||
<syntaxhighlight lang="bash" style="border: 1px solid blue;"> | |||
grep -w <username> /etc/group | |||
</syntaxhighlight> | |||
===Comando úteis=== | |||
* Comandos para verificar a memória: | |||
<syntaxhighlight lang="bash" style="border: 1px solid blue;"> | |||
free [-h ou -m] | |||
</syntaxhighlight> | |||
ou | |||
<syntaxhighlight lang="bash" style="border: 1px solid blue;"> | |||
head -6 /proc/meminfo | |||
</syntaxhighlight> | |||
* Para avaliar melhor o consumo de CPU e memória dos processos em tempo de execução: | |||
<syntaxhighlight lang="bash" style="border: 1px solid blue;"> | |||
top | |||
</syntaxhighlight> | |||
* Para mostrar as 10 últimas linhas de um arquivo: | |||
<syntaxhighlight lang="bash" style="border: 1px solid blue;"> | |||
tail | |||
</syntaxhighlight> | |||
* Para mostrar as últimas linhas de um arquivo e ficar monitorando a saída, útil para avaliar logs em tempo de execução: | |||
<syntaxhighlight lang="bash" style="border: 1px solid blue;"> | |||
tail -f /var/log/<filename.log> | |||
</syntaxhighlight> | |||
* Para mostrar as 5 últimas linhas de um arquivo: | |||
<syntaxhighlight lang="bash" style="border: 1px solid blue;"> | |||
tail -5 | |||
</syntaxhighlight> | |||
* Para mostrar as 10 primeiras linhas de um arquivo: | |||
<syntaxhighlight lang="bash" style="border: 1px solid blue;"> | |||
head | |||
</syntaxhighlight> | |||
* Para mostrar as 5 primeiras linhas de um arquivo: | |||
<syntaxhighlight lang="bash" style="border: 1px solid blue;"> | |||
head -5 | |||
</syntaxhighlight> | |||
==Fontes== | |||
* [https://riptutorial.com/bash/awesome-learning/tutorial Bash - Awesome Tutorial] | |||
* [https://bash.cyberciti.biz/guide/Main_Page Linux Bash Shell Scripting Tutorial] | |||
* [https://www.makeuseof.com/tag/5-ways-generate-secure-passwords-linux/ 10 Ways to Generate Secure Passwords on Linux] | |||
* [https://pt.linux-console.net/ Linux-Console.net] | |||
** [https://pt.linux-console.net/?p=20090 Como verificar a versão Debian no terminal Linux] | |||
** [https://pt.linux-console.net/?p=33827 Evite esses problemas limitando a execução de scripts Bash uma vez por vez] | |||
* [https://phoenixnap.com/kb/linux-diff diff Command in Linux: Syntax, Options, Examples] | |||
* [https://tecadmin.net/use-logical-or-and-in-shell-script/ How to Use Logical OR & AND in Shell Script with Examples] | |||
* [https://www.namehero.com/blog/practical-examples-of-how-a-bash-case-statement-can-be-used-in-shell-scripts/ Practical Examples Of How A Bash Case Statement Can Be Used In Shell Scripts] | |||
* [https://kodekloud.com/blog/regex-shell-script/ Bash Regex: How to Use Regex in a Shell Script] | |||
* [https://kodekloud.com/blog/bash-scripts-loop-through-array-values/ How to Write Bash Scripts to Loop Through Array Values] |
Edição atual tal como às 15h21min de 8 de outubro de 2024
Linux
Debian 12
- Descomentar as seguintes linhas no arquivo: .bashrc
# colored GCC warnings and errors
export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'
# some more ls aliases
alias ll='ls -l'
alias la='ls -A'
alias l='ls -CF'
- sudo:
Instalar o pacote sudo e adicionar o usuário ao grupo sudo:
su -l
apt install sudo
usermod -aG sudo <username>
- Desligar a máquina:
sudo systemctl poweroff
Versão
cat /etc/issue
ou
cat /etc/os-release
ou
cat /etc/debian_version
ou
uname -a
ou
lsb_release -a
ou
hostnamectl
IP
- Obter o IP:
ip a
- Obter o nome da interface
ip link
- DHCP
- Caso mantenha o IP dinâmico e estaja em ambiente de testes/desenvolvimento, utilizando o VirtualBox, por exemplo, para não ter que logar na máquina para descobrir o IP e acessá-la através de um cliente TTY, tipo o PuTTY, altere o arquivo: /etc/issue
Debian GNU/Linux 12 \n \l
enp0s3: \4{enp0s3}
- Configurar o IP estático:
- Comentar as linhas em: /etc/network/interfaces
#allow-hotplug enp0s3
#iface enp0s3 inet dhcp
- Acrescentar as linhas em: /etc/network/interfaces
auto enp0s3
iface enp0s3 inet static
address 192.168.2.10
netmask 255.255.255.0
gateway 192.168.2.1
- Reiniciar o serviço de rede:
sudo systemctl restart networking.service
No Windows/VirtualBox
- Conectar o Adaptador 1 da Rede a: Placa em modo Bridge.
- Para verificar qual adaptador, no host Windows, está com o Gateway Padrão e utilizá-lo para configurar o IP estático em /etc/network/interfaces acima, executar o seguinte comando em: cmd
ipconfig
Memória
Caso instale o ambiente gráfico e haja problemas de memória e estaja em ambiente de testes/desenvolvimento:
- Criar o script: /root/clearcache
#!/bin/bash
#
[[ $(</proc/meminfo awk '/^SwapCached:/ {print $2}') -gt 0 || $(</proc/meminfo awk '/^MemFree:/ {print $2}') -lt 100000 || $(</proc/meminfo awk '/^Cached:/ {print $2}') -gt 2000000 || $(</proc/meminfo awk '/^Buffers:/ {print $2}') -gt 100000 ]] && sync && echo 1 > /proc/sys/vm/drop_caches && swapoff -a && swapon -a && date >> /var/log/clear-cached.log
- Acrescente o modo de execução ao script:
sudo chmod u+x /root/clearcache
- Na crontab do root:
sudo crontab -u root -e
- Acrescentar a seguinte linha:
* * * * * /bin/bash /root/clearcache
Pacotes
- Atualizar pacotes:
sudo apt update
sudo apt upgrade
- Remover dependencias de pacotes que já não são mais necessários:
sudo apt autoremove
- Limpar o repositório local de pacotes baixados:
sudo apt autoclean
- Instalar pacotes:
sudo apt install <package_name>
- Continuar instalação interrompida:
sudo dpkg --configure -a
- Remover pacotes:
sudo apt remove <package_name>
- Remover completamente os pacotes (arquivos de configuração):
sudo apt purge <package_name>
Usuários
- Criar usuário:
adduser <username>
- Excluir usuário:
deluser <username>
- Adicionar usuário a um grupo:
usermod -aG <group> <username>
- Remover usuário de um grupo:
usermod -rG <group> <username>
- Exibir os grupos de um usuário:
groups <username>
ou
grep -w <username> /etc/group
Comando úteis
- Comandos para verificar a memória:
free [-h ou -m]
ou
head -6 /proc/meminfo
- Para avaliar melhor o consumo de CPU e memória dos processos em tempo de execução:
top
- Para mostrar as 10 últimas linhas de um arquivo:
tail
- Para mostrar as últimas linhas de um arquivo e ficar monitorando a saída, útil para avaliar logs em tempo de execução:
tail -f /var/log/<filename.log>
- Para mostrar as 5 últimas linhas de um arquivo:
tail -5
- Para mostrar as 10 primeiras linhas de um arquivo:
head
- Para mostrar as 5 primeiras linhas de um arquivo:
head -5
Fontes
- Bash - Awesome Tutorial
- Linux Bash Shell Scripting Tutorial
- 10 Ways to Generate Secure Passwords on Linux
- Linux-Console.net
- diff Command in Linux: Syntax, Options, Examples
- How to Use Logical OR & AND in Shell Script with Examples
- Practical Examples Of How A Bash Case Statement Can Be Used In Shell Scripts
- Bash Regex: How to Use Regex in a Shell Script
- How to Write Bash Scripts to Loop Through Array Values