2022-06-28 18:39:45 +02:00
|
|
|
---
|
2023-02-23 14:48:51 +01:00
|
|
|
title: "Useful Commands"
|
2022-11-19 15:25:20 +01:00
|
|
|
visible: true
|
2022-06-28 18:39:45 +02:00
|
|
|
---
|
|
|
|
|
|
|
|
[toc]
|
2023-02-19 11:02:44 +01:00
|
|
|
|
2022-06-28 18:39:45 +02:00
|
|
|
## Imagemagick
|
2023-02-19 11:02:44 +01:00
|
|
|
|
2022-06-28 18:39:45 +02:00
|
|
|
### Splitting PDF files
|
2023-02-19 11:02:44 +01:00
|
|
|
|
2023-02-23 14:48:51 +01:00
|
|
|
```sh
|
2023-02-19 15:07:31 +01:00
|
|
|
convert -density 600 {INPUT.PDF} -crop 50x100% +repage {OUT.PDF}
|
2023-02-19 11:02:44 +01:00
|
|
|
```
|
2022-06-28 18:39:45 +02:00
|
|
|
|
|
|
|
```
|
|
|
|
-density: adjusts the quality of the resulting pdf. Higher values look better, but take longer to process
|
|
|
|
-crop 50x100%: this splits the pdf into "left" and "right". 100x50% would split into "top" and "bottom"
|
2022-07-07 08:35:48 +02:00
|
|
|
```
|
|
|
|
|
2023-07-29 15:37:39 +02:00
|
|
|
## Ghostscript
|
|
|
|
|
|
|
|
### Merge multiple PDF files
|
|
|
|
|
|
|
|
Ghostscript is preinstalled on a lot of Linux systems and can quite easily be used to merge and optimize multiple PDF files into one.
|
|
|
|
|
|
|
|
[shuser]
|
|
|
|
|
|
|
|
```sh
|
|
|
|
gs -q -sDEVICE=pdfwrite -dPDFSETTINGS=/prepress -o merged.pdf <first>.pdf <second>.pdf
|
|
|
|
```
|
|
|
|
|
|
|
|
[/shuser]
|
|
|
|
|
|
|
|
> [Merge / convert multiple PDF files into one PDF](https://stackoverflow.com/a/19358402)
|
|
|
|
|
2022-07-07 08:35:48 +02:00
|
|
|
## Find
|
2023-02-19 11:02:44 +01:00
|
|
|
|
2022-07-07 08:35:48 +02:00
|
|
|
### Change filtered permissions
|
2023-02-19 11:02:44 +01:00
|
|
|
|
2022-07-07 08:35:48 +02:00
|
|
|
Using find with its `exec` switch one can set different permissions based on the usual find filters.
|
2023-02-19 11:02:44 +01:00
|
|
|
One example would be only changing file or directory permissions.
|
|
|
|
|
|
|
|
```sh
|
2023-02-23 14:48:51 +01:00
|
|
|
find (directory) -type f -exec chmod 744 {} +
|
2023-02-19 11:02:44 +01:00
|
|
|
```
|
|
|
|
|
|
|
|
Replacing `-type f` with `-type d` would execute the `chmod` for directories instead.
|
2022-10-18 20:43:26 +02:00
|
|
|
|
2023-07-29 15:12:57 +02:00
|
|
|
## Arch Linux
|
|
|
|
|
|
|
|
### Detect AUR package rebuilds
|
|
|
|
|
|
|
|
Install the package `extra/rebuild-detector`
|
|
|
|
It will create a `pacman` hook to check which packages need to be rebuild, but can also be executed with the following command.
|
|
|
|
|
|
|
|
[shuser]
|
|
|
|
|
|
|
|
```sh
|
|
|
|
checkrebuild
|
|
|
|
```
|
|
|
|
|
|
|
|
[/shuser]
|
|
|
|
|
|
|
|
The packages might be rebuilt automatically a lot of the time, but sometimes it is necessary to for a rebuild using the AUR helper.
|
|
|
|
This is an example using `paru`
|
|
|
|
|
|
|
|
[shuser]
|
|
|
|
|
|
|
|
```sh
|
|
|
|
paru -S --rebuild=yes <package>
|
|
|
|
```
|
|
|
|
|
|
|
|
[/shuser]
|
|
|
|
|
2022-10-18 20:43:26 +02:00
|
|
|
## Various
|
2023-02-19 11:02:44 +01:00
|
|
|
|
2022-10-18 20:43:26 +02:00
|
|
|
### Overwrite disk with pseudorandom data
|
2023-02-19 11:02:44 +01:00
|
|
|
|
2022-10-18 20:43:26 +02:00
|
|
|
Using openssl on CPUs with AES acceleration one can create pseudorandom data with high speeds.
|
2023-02-19 11:02:44 +01:00
|
|
|
Much faster than `/dev/urandom` at least
|
|
|
|
|
|
|
|
```sh
|
2023-02-23 14:48:51 +01:00
|
|
|
openssl enc -aes-128-ctr -md sha512 -pbkdf2 -nosalt -pass file:/dev/urandom < /dev/zero | pv > {TARGET DISK}
|
2023-02-19 11:02:44 +01:00
|
|
|
```
|
|
|
|
|
|
|
|
Around 2GiB/s on my Ryzen 7 1700x if output to `/dev/null`
|
2022-10-18 20:43:26 +02:00
|
|
|
|
2022-10-23 20:44:13 +02:00
|
|
|
### Formatted csv in terminal
|
2022-10-23 20:51:00 +02:00
|
|
|
|
2023-02-19 11:02:44 +01:00
|
|
|
> [From Pretty CSV viewing on the Command Line](https://www.stefaanlippens.net/pretty-csv.html)
|
|
|
|
|
|
|
|
```sh
|
2023-02-23 14:48:51 +01:00
|
|
|
column -t -s, < {FILE.CSV}
|
2023-02-19 11:02:44 +01:00
|
|
|
```
|
|
|
|
|
|
|
|
### Download directory from webdav
|
|
|
|
|
|
|
|
Using `wget`, it's possible to download directories recursively from WebDAV.
|
|
|
|
|
|
|
|
```sh
|
2023-02-23 14:48:51 +01:00
|
|
|
wget -r -nH -np --cut-dirs=1 --user={USERNAME} --password={PASSWORD} https://WEBDAVHOST/DIR/DIR
|
2023-02-19 11:02:44 +01:00
|
|
|
```
|
2023-07-12 19:58:43 +02:00
|
|
|
|
|
|
|
### Find USB speed in use
|
|
|
|
|
|
|
|
First, the USB device you want to check has to be selected
|
|
|
|
|
|
|
|
[shuser]
|
|
|
|
|
|
|
|
```sh
|
|
|
|
lsusb
|
2023-07-12 20:03:56 +02:00
|
|
|
(out)Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
|
|
|
|
(out)Bus 003 Device 003: ID 0c45:652f Microdia Backlit Gaming Keyboard
|
|
|
|
(out)Bus 003 Device 002: ID 046d:c084 Logitech, Inc. G203 Gaming Mouse
|
|
|
|
(out)Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
|
|
|
|
(out)Bus 002 Device 002: ID 0781:55a3 SanDisk Corp. SanDisk 3.2Gen1
|
|
|
|
(out)Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
|
|
|
|
(out)Bus 001 Device 002: ID 2972:0047 FiiO Electronics Technology FiiO BTR5
|
|
|
|
(out)Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
|
2023-07-12 19:58:43 +02:00
|
|
|
```
|
|
|
|
|
|
|
|
[/shuser]
|
|
|
|
|
|
|
|
Now, using the ID, the USB class used can be determined
|
|
|
|
|
|
|
|
[shuser]
|
|
|
|
|
|
|
|
```sh
|
|
|
|
lsusb -d 0781:55a3 -v | grep bcdUSB
|
2023-07-12 20:03:56 +02:00
|
|
|
(out)bcdUSB 3.20
|
2023-07-12 19:58:43 +02:00
|
|
|
```
|
|
|
|
|
|
|
|
[/shuser]
|
2023-07-29 14:43:09 +02:00
|
|
|
|
2023-07-29 15:12:57 +02:00
|
|
|
### Change file modify time
|
2023-07-29 14:43:09 +02:00
|
|
|
|
2023-07-29 15:12:57 +02:00
|
|
|
Using `touch` it is possible to change the timestamps on a file.
|
|
|
|
_Note: The file has to be owned by the user executing the command_
|
2023-07-29 14:43:09 +02:00
|
|
|
|
2023-07-29 15:12:57 +02:00
|
|
|
Example changing the access and modify timestamps:
|
2023-07-29 14:43:09 +02:00
|
|
|
|
|
|
|
[shuser]
|
|
|
|
|
2023-07-29 15:12:57 +02:00
|
|
|
```
|
|
|
|
touch -a -m -t 202307291506.07 <file>
|
2023-07-29 14:43:09 +02:00
|
|
|
```
|
|
|
|
|
|
|
|
[/shuser]
|
|
|
|
|
2023-07-29 15:12:57 +02:00
|
|
|
```
|
|
|
|
-a: accessed time
|
|
|
|
-m: modified time
|
|
|
|
-t: timestamp - [[CC]YY]MMDDhhmm[.ss] time format
|
|
|
|
```
|
|
|
|
|
|
|
|
Alternatively to `-t` it is also possible to use `-d` for a looser format.
|
|
|
|
[ISO8061](https://en.wikipedia.org/wiki/ISO_8601) obviously works as well.
|
2023-07-29 14:43:09 +02:00
|
|
|
|
|
|
|
[shuser]
|
|
|
|
|
2023-07-29 15:12:57 +02:00
|
|
|
```
|
|
|
|
touch -a -m -d "2 hours ago" <file>
|
|
|
|
touch -a -m -d "2023-07-29T00:23" <file>
|
2023-07-29 14:43:09 +02:00
|
|
|
```
|
|
|
|
|
|
|
|
[/shuser]
|
2023-07-29 15:12:57 +02:00
|
|
|
|
|
|
|
> [Linux - modify file modify/access/change time](https://stackoverflow.com/questions/40630695/linux-modify-file-modify-access-change-time)
|
|
|
|
> [How can I change the date modified/created of a file?](https://askubuntu.com/questions/62492/how-can-i-change-the-date-modified-created-of-a-file)
|
2023-07-29 15:22:32 +02:00
|
|
|
|
|
|
|
### Create a random temporary directory / file
|
|
|
|
|
|
|
|
Using `mktemp`, a randomly named file or directory will be created in `/tmp`
|
|
|
|
|
|
|
|
Create a file:
|
|
|
|
[shuser]
|
|
|
|
|
|
|
|
```sh
|
|
|
|
mktemp
|
|
|
|
```
|
|
|
|
|
|
|
|
[/shuser]
|
|
|
|
|
|
|
|
Create a directory:
|
|
|
|
[shuser]
|
|
|
|
|
|
|
|
```sh
|
|
|
|
mktemp -d
|
|
|
|
```
|
|
|
|
|
|
|
|
[/shuser]
|
|
|
|
|
|
|
|
Save the output into an environment variable for future referencing
|
|
|
|
|
|
|
|
sh / Bash:
|
|
|
|
[shuser]
|
|
|
|
|
|
|
|
```sh
|
|
|
|
export TMPDIR=$(mktemp -d)
|
|
|
|
```
|
|
|
|
|
|
|
|
[/shuser]
|
|
|
|
|
|
|
|
Fish:
|
|
|
|
[shuser]
|
|
|
|
|
|
|
|
```fish
|
|
|
|
set TMPDIR (mktemp -d)
|
|
|
|
```
|
|
|
|
|
|
|
|
[/shuser]
|