140 lines
3.3 KiB
Markdown
140 lines
3.3 KiB
Markdown
# Linux Cheats
|
|
|
|
## General (tested in Debian)
|
|
Create directory recursivly: `mkdir -p these/folders/doesnt/exist`
|
|
> -p for "parent"
|
|
|
|
<br>
|
|
|
|
List directory sorted by file-size: `ls -lhS /path`
|
|
> -S sorts them. -lh gives a list with "human-readable" file-sizes.
|
|
|
|
<br>
|
|
|
|
Find the size of each item in a folder: `du -sm *`
|
|
You can sort them by adding: `du -sm * | sort -nr`
|
|
> You can add `-h`, but it won't sort correctly
|
|
|
|
|
|
To find the largest 20 files in a directory:
|
|
> `du -ah ./ | sort -rh | head -20`
|
|
|
|
<br>
|
|
|
|
Find the total size of a folder: `du -hs /foldername`
|
|
|
|
<br>
|
|
|
|
### Set script as startup
|
|
If, for some reason, apache isn't startup:
|
|
|
|
> `sudo update-rc.d apache2 defaults`
|
|
|
|
### Check a package version/info
|
|
> `dpkg -l matrix-synapse`
|
|
|
|
### See logs for services:
|
|
> `sudo journalctl -e -u matrix-synapse`
|
|
> (`-f` instead of `-e` to keep it running)
|
|
|
|
<br>
|
|
|
|
### Installing from tar.gz
|
|
Pure binaries:
|
|
|
|
> `sudo tar --directory=/opt -xvf <file>.tar.[bz2|gz]`
|
|
> add the directory to your path: `export PATH=$PATH:/opt/[package_name]/bin`
|
|
|
|
<br>
|
|
|
|
#### More:
|
|
|
|
+ [Creating custom services](https://wiki.debian.org/systemd/Services)
|
|
|
|
<br>
|
|
|
|
## SSH
|
|
Copy files to/from an SSH connection: (SSH format: `user@host:/path` )
|
|
> `scp <source> <destination>`
|
|
|
|
Recursivly give directories execute privileges: (`-type f` for files instead)
|
|
> `find /path/to/base/dir -type d -exec chmod +c {} +`
|
|
|
|
<br>
|
|
|
|
## GROUPS
|
|
Create groups
|
|
> `groupadd <groupName>`
|
|
|
|
Add user to a group
|
|
> `usermod -a -G <group> <user>`
|
|
|
|
List all groups
|
|
> `getent group`
|
|
|
|
List all members of a group
|
|
> `getent group <group>`
|
|
|
|
<br>
|
|
|
|
### Open ports with iptables
|
|
|
|
Don't do that. Use [UFW](https://www.digitalocean.com/community/tutorials/how-to-set-up-a-firewall-with-ufw-on-debian-10) instead.
|
|
|
|
Allow a connection with UFW:
|
|
> `sudo ufw allow <port/service>`
|
|
|
|
Enable ufw service:
|
|
|
|
> `sudo ufw enable`
|
|
|
|
+ [Source](https://www.linuxquestions.org/questions/linux-security-4/how-to-open-ports-with-iptables-237939/)
|
|
+ [Source2](https://www.digitalocean.com/community/tutorials/iptables-essentials-common-firewall-rules-and-commands)
|
|
|
|
<br>
|
|
|
|
### Partitioning and mounting drives
|
|
List connected drives (?):
|
|
> `lsblk`
|
|
|
|
It might give you something like:
|
|
```bash
|
|
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
|
|
sda 8:0 0 931.5G 0 disk
|
|
├─sda1 8:1 0 200M 0 part
|
|
└─sda2 8:2 0 931.3G 0 part /media/massStorage
|
|
mmcblk0 179:0 0 7.4G 0 disk
|
|
├─mmcblk0p1 179:1 0 41.8M 0 part /boot
|
|
└─mmcblk0p2 179:2 0 7.4G 0 part /
|
|
```
|
|
|
|
Use that info like this: (NB: Not permanent)
|
|
> `mount /dev/sda2 /media/massStorage`
|
|
|
|
To mount partition permanently, first find the UUID by:
|
|
> `ls -la /dev/disk/by-uuid/`
|
|
|
|
Then instert the following into `/etc/fstab`:
|
|
> `UUID=03ec5dd3-45c0-4f95-a363-61ff321a09ff /opt ext4 defaults 0 2`
|
|
|
|
<br>
|
|
|
|
## Arduino
|
|
Find what 'channel'(?) the Arduino is plugged in at:
|
|
`dmesg | grep tty`
|
|
|
|
Do following commands to "talk" with an Arduino (with a set script):
|
|
```python
|
|
> python
|
|
> import serial
|
|
> ser = serial.Serial('/dev/ttyACM0',115200)
|
|
> ser.readline()
|
|
> ser.write("PP\n")
|
|
```
|
|
|
|
To set the time of current clock-program, continue with:
|
|
```python
|
|
> from datetime import datetime
|
|
> ser.write("T"+datetime.now().strftime("%y%m%d0%w%H%M%S")+"\n")
|
|
> ser.readline()
|
|
``` |