Files
linux/README.md
marcio.fernandes f89a2f36ed modified: README.md
modified:   gnome/README.md
2024-06-29 15:09:16 +01:00

579 lines
12 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Linux
## Table of contents
<!-- TOC -->
- [Linux](#linux)
- [Table of contents](#table-of-contents)
- [Update](#update)
- [Debian / Ubuntu](#debian--ubuntu)
- [Fedora](#fedora)
- [ls](#ls)
- [Users](#users)
- [hostname / hostnamectl](#hostname--hostnamectl)
- [static ip](#static-ip)
- [Disks](#disks)
- [mount](#mount)
- [gio](#gio)
- [mount samba share](#mount-samba-share)
- [unmount](#unmount)
- [File System](#file-system)
- [ext4](#ext4)
- [ext3](#ext3)
- [exFat](#exfat)
- [ntfs](#ntfs)
- [space usage](#space-usage)
- [Manutenção de discos](#manutenção-de-discos)
- [tar](#tar)
- [SSH](#ssh)
- [Create key](#create-key)
- [Copy public key](#copy-public-key)
- [Add existing Key](#add-existing-key)
- [Alias](#alias)
- [Port Binding](#port-binding)
- [Documentation](#documentation)
- [Benchmarking](#benchmarking)
- [themes](#themes)
- [shell](#shell)
- [terminal](#terminal)
- [Backups](#backups)
- [bash](#bash)
- [disable touch screen](#disable-touch-screen)
- [disable suspend black screen](#disable-suspend-black-screen)
- [lightdm auto login](#lightdm-auto-login)
- [btop](#btop)
- [Setup](#setup)
- [Debian \& Ubuntu](#debian--ubuntu-1)
- [lspci](#lspci)
- [gnome files / nautilus](#gnome-files--nautilus)
<!-- /TOC -->
## Update
### Debian / Ubuntu
```bash
apt update -y
apt upgrade -y
apt autoremove -y
```
References:
[https://linuxsimply.com/linux-basics/package-management/update-packages/sudo-apt-update/](https://linuxsimply.com/linux-basics/package-management/update-packages/sudo-apt-update/)
### Fedora
```bash
dnf
```
References:
[https://docs.fedoraproject.org/en-US/quick-docs/dnf-vs-apt/](https://docs.fedoraproject.org/en-US/quick-docs/dnf-vs-apt/)
## ls
List information about the FILEs (the current directory by default).
```bash
#order by date
ls -t
#order by date reverse
ls -r
```
source: man
## Users
```bash
#create
useradd USERNAME
# create with home directory
useradd -m USERNAME
#remove
userdel USERNAME
#useradd -r USERNAME
passwd
passwd USERNAME
groups
groupadd GROUPNAME
groups USERNAME
usermod -a -G GROUPNAME USERNAME
chown [-c|--changes] [-v|--verbose] [-f|--silent|--quiet] [--dereference]
[-h|--no-dereference] [--preserve-root]
[--from=currentowner:currentgroup] [--no-preserve-root]
[-R|--recursive] [--preserve-root] [-H] [-L] [-P]
{new-owner|--reference=ref-file} file ...
```
## hostname / hostnamectl
``` bash
#get hostname
hostname
#set hostname
hostnamectl
sudo nano /etc/hostname
#alterar o nome
sudo nano /etc/hosts
#alterar o nome
Static IP
A configuração para um ip estático poderá ser um pouco diferente de distribuição para distribuição mas a lógica é similar
```
## static ip
Debian
sudo nano /etc/network/interfaces
Exemplo de configuração
``` bash
# neste exemplo de configuração a place de rede tem o nome enxd0374555c1f8
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
source /etc/network/interfaces.d/*
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
allow-hotplug enxd0374555c1f8
iface enxd0374555c1f8 inet static
address 192.168.0.2
netmask 255.255.255.0
gateway 192.168.0.1
dns-nameservers 89.207.128.252 89.207.130.252
Reiniciar configuração sem reboot de computador
```
``` bash
Reiniciar configuração sem reboot de computador
#sudo /etc/init.d/networking restart
```
## Disks
File System & Space Usage
``` bash
df -h
```
List physical disks and partition size
``` bash
lsblk
```
List partition ids
``` bash
blkid /dev/sdc1
```
Partition Manager
``` bash
fdisk /dev/<DISK NAME>
#Example:
fdisk /dev/sdc
#Partições como mais de 2 TB
sudo parted /dev/sdc
#(parted) mklabel gpt
#alterar para a unidade de medida que desejar
#(parted) unit TB
#ver espaço livre
(parted) print free
#criar partição com espaço livre (exemplo:4 Teras)
mkpart primary ext4 0 4
#Formatar uma partição
```
## mount
Mount partition on boot fstab
``` bash
nano /etc/fstabexemplo de alias
```
ext4 example
``` bash
#add line
PARTUUID=<PARTUUID GIVEN blksid> <FOLDER WHERE TO MOUNT> ext4 defaults,nofail 0 02
```
Mount fstab partions without reboot
``` bash
mount -a
```
smb share
Create credentials file
``` bash
#/home/mf/.credentials/smb:mf@nas.lan
username=shareuser
password=sharepassword
domain=domain_or_workgroupname
```
Secure credentials file permission
``` bash
chmod 0600 /home/mf/.credentials/smb:mf@nas.lan
```
Add line
``` bash
#/etc/fstab
//nas.lan/homes /mnt/smb-share:mf@nas.lan,share=homes cifs credentials=/home/mf/.credentials/smb:mf@nas.lan,uid=1000,gid=1000,nofail 0 0
```
## gio
### mount samba share
```bash
#/home/username/.credentials
#username
#SAMBA
#password
gio mount smb://server/share < /home/username/.credentials
```
### unmount
```bash
gio mount -u smb://server/share
```
## File System
### ext4
mkfs.ext4 _filesys_
Example
```
mkfs.ext4 /dev/sdb1
```
### ext3
mkfs.ext3 _filesys_
Example
``` bash
mkfs.ext3 /dev/sdb1
#exFat
mkfs.exfat /dev/sdc1
```
### exFat
mkfs.exfat _filesys_
``` bash
mkfs.exfat /dev/sdc1
```
### ntfs
``` bash
apt-get install ntfs-3g
mkntfs --fast --label Backups /dev/sdc1
```
## space usage
df
df -h
du -h --max-depth=1
## Manutenção de discos
Bad Sectors
sudo e2fsck -cfpv /dev/sda1
O Exemplo foi com o disco sda1 mas deverá ser substituído pelo disco desejado
Os parâmetros têm os seguintes significados:
“c” procura por blocos defeituosos e os adiciona à lista
“f” força uma verificação no sistema de arquivos
“p” repara qualquer coisa que possa ser reparada com segurança
“v” está no modo detalhado. você pode ver o progresso do comando
Esse comando pode levar muito tempo para ser executado, até várias horas em uma unidade particularmente grande.
## tar
A utilização o comando tar é uma das formas de comprimir no linux
```
tar -cvf --exclude='.cache' --exclude='Cache' --exclude='.cache' --exclude='.tmp' --exclude='tmp' /tmp/nomedoficheiro.tar.gz /PATHPARAFICEHIROOUDIRECTORIO
#Caso seja necessário paralelismo
tar -I pigz -cvf - /fileserver/media/music/*
#Se for necessário limitar o tamanho do ficheiro compresso (dividindo em multiplos ficheiros)
tar -I pigz -cvf - /sourcefolder/* | split --bytes=8GB - /tmp/file.tar.gz
```
## SSH
### Create key
```bash
ssh-keygen -t ecdsa -b 521
#or
ssh-keygen -t ecdsa -b 521 -f ~/.ssh/key-ecdsa
```
### Copy public key
```bash
ssh-add ~/.ssh/id_ed25519
ssh-copy-id -i ~/.ssh//ey-ecdsa.pub example_user@192.0.2.4
```
### Add existing Key
```bash
ssh-add ~/.ssh/key-ecdsa
```
### Alias
```bash
Host srv01
HostName srv01.lan
User john
RemoteCommand cd ~/; exec bash --login
RequestTTY yes
```
### Port Binding
Bind local port 8001 to target-server port 80 using jump-machine.local.
_(local machine without direct access to target-server)_
```bash
ssh -f -N -L localhost:8001:target-server:80 usr@jump-machine.local
```
#### Documentation
``` bash
# man
-f Requests ssh to go to background just before command
execution. This is useful if ssh is going to ask for
passwords or passphrases, but the user wants it in the
background. This implies -n. The recommended way to
start X11 programs at a remote site is with something
like ssh -f host xterm.
-N Do not execute a remote command. This is useful for just
forwarding ports. Refer to the description of
SessionType in ssh_config(5) for details.
-L [bind_address:]port:host:hostport
-L [bind_address:]port:remote_socket
-L local_socket:host:hostport
-L local_socket:remote_socket
Specifies that connections to the given TCP port or Unix socket on the
local (client) host are to be forwarded to the given host and port, or
Unix socket, on the remote side. This works by allocating a socket to
listen to either a TCP port on the local side, optionally bound to the
specified bind_address, or to a Unix socket. Whenever a connection is
made to the local port or socket, the connection is forwarded over the
secure channel, and a connection is made to either host port hostport,
or the Unix socket remote_socket, from the remote machine.
Port forwardings can also be specified in the configuration file. Only
the superuser can forward privileged ports. IPv6 addresses can be
specified by enclosing the address in square brackets.
By default, the local port is bound in accordance with the GatewayPorts
setting. However, an explicit bind_address may be used to bind the
connection to a specific address. The bind_address of “localhost”
indicates that the listening port be bound for local use only, while an
empty address or * indicates that the port should be available from
all interfaces.
```
## Benchmarking
Discos
sudo apt install hdparm
sudo hdparm -Tt /dev/sdc
## themes
- <https://github.com/EliverLara/Nordic>
### shell
- zsh
```bash
sudo apt install zsh
chsh -s /bin/zsh $whoami
sudo apt-get install fonts-powerline
#source https://ohmyz.sh/#install
ssh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
#~/home/.zshrc
#ZSH_THEME="agnoster"
```
### terminal
- guake
```bash
apt install guake
```
```bash
# ~/.config/autostart/guake.desktop
[Desktop Entry]
Name=guake
GenericName=guake auto start
Comment=
Exec=guake --hide
Terminal=false
Type=Application
X-GNOME-Autostart-enabled=true
```
- terminator
```bash
apt install terminator
```
## Backups
### bash
```bash
tar -cvpzf "/vault/.backups/devices/homeserver/tar/backup_$(date +"%Y%m%d%H%M%S").tar.gz \
--exclude=/proc \
--exclude=/tmp \
--exclude=/mnt \
--exclude=/dev \
--exclude=/sys \
--exclude=/run \
--exclude=/media \
--one-file-system \
/
```
```bash
#!/bin/bash
gio mount ftp://ftp.backups@backupsrv01.dev.lan < ~/.credentials/ftp.backups@backupsrv01.dev.lan
DATE=$(date +%d-%m-%Y)
BACKUP_DIR="/run/user/1000/gvfs/ftp:host=backupsrv01.dev.lan,user=ftp.backups/mf.brutus.dev.lan"
#To backup 2daygeek's home directory
tar -zcvpf $BACKUP_DIR/home-mf_$DATE.tar.gz --exclude="**/.tmp/*" --exclude="**/Downloads/*" --exclude="**/.cache/*" --exclude="**/Trash/*" --exclude="**/cache/*" /home/mf
#To delete files older than 10 days
find $BACKUP_DIR/* -mtime +10 -exec rm {} \;
gio mount -u ftp://ftp.backups@backupsrv01.dev.lan
```
## disable touch screen
``` bash
sudo apt-get -y install xinput
xinput
```
Run xinput to list out the input devices. Your touchscreen should show as one of the "pointers".
xinput disable "NTRG0001:01 1B96:1B05" (your device ID may differ than mine)
Add this to your ~/.profile or such to do automatically upon login
xinput disable "NTRG0001:01 1B96:1B05"
Source: https://askubuntu.com/questions/759335/how-to-disable-a-touchscreen-on-surface-pro-3
## disable suspend black screen
```bash
# /etc/lightdm/lightdm.conf
[Seat:*]
xserver-command=X -s 0 dpms
```
## lightdm auto login
```bash
# /etc/lightdm/lightdm.conf
[SeatDefaults]
autologin-user=public
autologin-user-timeout=5
# Uncomment the following, if running Unity
#greeter-session=unity-greeter
```
## btop
### Setup
#### Debian & Ubuntu
```bash
apt update && apt install btop -y
```
## lspci
Displays information about each PCI bus on your system. This includes information about the devices connected to the PCI subsystem.
lspci [options]
| Option | Description |
| -------- | ------------- |
| -v | Verbose |
``` bash
lspci -v
```
## gnome files / nautilus
<https://www.maketecheasier.com/useful-nautlius-tweaks-linux/>