193 lines
2.2 KiB
Markdown
193 lines
2.2 KiB
Markdown
|
---
|
||
|
title: Linux
|
||
|
tags: note software linux
|
||
|
created: 2023-07-01T08:51:23Z
|
||
|
published: true
|
||
|
---
|
||
|
|
||
|
The following commands have been tested with Arch Linux.
|
||
|
They might work in other distributions with a few modifications.
|
||
|
The commands assume standard user permissions and will include `sudo` if root permissions are required.
|
||
|
|
||
|
## lsof
|
||
|
|
||
|
### List open TCP connections
|
||
|
|
||
|
```bash
|
||
|
sudo lsof -PniTCP
|
||
|
```
|
||
|
|
||
|
### List open UDP connections
|
||
|
|
||
|
```bash
|
||
|
sudo lsof -PniUDP
|
||
|
```
|
||
|
|
||
|
## nu
|
||
|
|
||
|
### Sort files and directories by size
|
||
|
|
||
|
```bash
|
||
|
ls -ad | sort-by size | reverse
|
||
|
```
|
||
|
|
||
|
### Filter processes with a high cpu usage
|
||
|
|
||
|
```bash
|
||
|
ps | where cpu > 0 | sort-by cpu | reverse
|
||
|
```
|
||
|
|
||
|
### Filter processes with a high memory usage
|
||
|
|
||
|
```bash
|
||
|
ps | where mem > 30MB | sort-by mem | reverse
|
||
|
```
|
||
|
|
||
|
## openssl
|
||
|
|
||
|
### Show certificate info
|
||
|
|
||
|
```bash
|
||
|
openssl x509 -text -noout -in $file
|
||
|
```
|
||
|
|
||
|
## pacman
|
||
|
|
||
|
### Install a package
|
||
|
|
||
|
```bash
|
||
|
sudo pacman -S $package
|
||
|
```
|
||
|
|
||
|
### Uninstall a package and its dependencies
|
||
|
|
||
|
```bash
|
||
|
sudo pacman -Rs $package
|
||
|
```
|
||
|
|
||
|
### List installed packages
|
||
|
|
||
|
```bash
|
||
|
pacman -Q
|
||
|
```
|
||
|
|
||
|
### List orphaned packages
|
||
|
|
||
|
```bash
|
||
|
pacman -Qtdq
|
||
|
```
|
||
|
|
||
|
### Clear cache
|
||
|
|
||
|
```bash
|
||
|
sudo pacman -Sc
|
||
|
```
|
||
|
|
||
|
## rg
|
||
|
|
||
|
### Search recursively
|
||
|
|
||
|
```bash
|
||
|
rg $text
|
||
|
```
|
||
|
|
||
|
### Search single file
|
||
|
|
||
|
```bash
|
||
|
rg $text $file
|
||
|
```
|
||
|
|
||
|
### Disable all filters
|
||
|
|
||
|
```bash
|
||
|
rg -uuu $text
|
||
|
```
|
||
|
|
||
|
## rsync
|
||
|
|
||
|
### Sync directory with a server
|
||
|
|
||
|
```bash
|
||
|
rsync -avz $source $destination
|
||
|
```
|
||
|
|
||
|
### Preview changes
|
||
|
|
||
|
```bash
|
||
|
rsync -avz $source $destination --dry-run
|
||
|
```
|
||
|
|
||
|
## systemd
|
||
|
|
||
|
### List all running services
|
||
|
|
||
|
```bash
|
||
|
systemctl --type=service --state=running
|
||
|
```
|
||
|
|
||
|
### List all enabled services
|
||
|
|
||
|
```bash
|
||
|
systemctl list-unit-files --type=service --state=enabled
|
||
|
```
|
||
|
|
||
|
### Follow log messages
|
||
|
|
||
|
```bash
|
||
|
journalctl -f
|
||
|
```
|
||
|
|
||
|
### Follow log messages for a specific unit
|
||
|
|
||
|
```bash
|
||
|
journalctl -f -u $unit
|
||
|
```
|
||
|
|
||
|
### Show boot time analysis
|
||
|
|
||
|
```bash
|
||
|
systemd-analyze blame
|
||
|
```
|
||
|
|
||
|
### Reboot into BIOS
|
||
|
|
||
|
```bash
|
||
|
systemctl reboot --firmware-setup
|
||
|
```
|
||
|
|
||
|
## tar
|
||
|
|
||
|
### Compress ze vucking files
|
||
|
|
||
|
```bash
|
||
|
tar czvf $name.tar.gz .
|
||
|
```
|
||
|
|
||
|
### Extract ze vucking files
|
||
|
|
||
|
```bash
|
||
|
tar xzvf $name.tar.gz
|
||
|
```
|
||
|
|
||
|
## users
|
||
|
|
||
|
### Add a user
|
||
|
|
||
|
```bash
|
||
|
useradd -m $user
|
||
|
```
|
||
|
|
||
|
### Add a group to a user
|
||
|
|
||
|
```bash
|
||
|
usermod -aG $group $user
|
||
|
```
|
||
|
|
||
|
## wmctrl
|
||
|
|
||
|
### Close all windows
|
||
|
|
||
|
```bash
|
||
|
wmctrl -l | awk '{print $1}' | xargs -rn1 wmctrl -ic
|
||
|
```
|