Added command examples from external blogs

This commit is contained in:
Michele Cereda
2023-02-07 16:04:57 +01:00
parent 6151dde1d0
commit f4455f598f
10 changed files with 145 additions and 47 deletions

View File

@@ -9,6 +9,7 @@
"btrfs",
"cereda",
"chezmoi",
"cpulimit",
"dhclient",
"diffpdf",
"dkms",
@@ -51,6 +52,8 @@
"tclsh",
"templating",
"tfvars",
"tmpfs",
"tput",
"zstd"
]
}

View File

@@ -31,6 +31,21 @@ echo $(tr '[:upper:]' '[:lower:]' <<< "$name")
# Bash 5 has a special parameter expansion for upper- and lowercasing strings.
echo ${name,,}
echo ${name^^}
# Add a clock to the top-right part of the terminal.
while sleep 1
do
tput sc;
tput cup 0 $(($(tput cols)-29))
date
tput rc
done &
# Show a binary clock.
watch -n 1 'echo "obase=2; `date +%s`" | bc'
# Fork bomb.
:(){ :|: & };:
```
## Startup files loading order

18
knowledge base/chmod.md Normal file
View File

@@ -0,0 +1,18 @@
# Chmod
## TL;DR
```sh
# Copy permissions from another file.
# Only available in GNU cp.
chmod --reference 'reference-file' 'changed-file'
```
## Sources
- [18 selected super-useful Linux one-liners]
<!-- project's references -->
<!-- internal references -->
<!-- external references -->
[18 selected super-useful linux one-liners]: https://medium.com/codex/18-selected-super-useful-linux-one-liners-398ba6d20f8c

View File

@@ -34,7 +34,11 @@ curl -o '/dev/null' -w '%{http_code}\n' -s -I 'http://example.com'
curl --request 'PUT' 'http://example.com'
# Specify headers.
curl 'http://example.com' -H 'Content-Type:application/json' 'http://example.com'
curl 'http://example.com' -H 'Content-Type:application/json'
# Fail fast with no output.
# Returns the HTTP error code.
curl -f 'http://example.com'
# Skip certificate validation.
curl --insecure 'https://example.com'

View File

@@ -5,79 +5,82 @@
```sh
# Change the permissions of all files and directories in the current directory,
# recursively.
find . -type d -exec chmod 755 {} +
find . -type f -exec chmod 644 {} +
find . -type 'd' -exec chmod '755' {} +
find . -type 'f' -exec chmod '644' {} +
# Change the ownership of all files and directories owned by a specific user or
# group, recursively.
find . -type d -user harry -exec chown daisy {} +
find . -type f -group users -exec chown :admin {} +
find . -type 'd' -user 'harry' -exec chown 'daisy' {} +
find . -type 'f' -group 'users' -exec chown ':admin' {} +
# Delete all empty files and directories in the 'Documents' directory.
find Documents -empty -delete # recursively
find Documents -maxdepth 1 -empty -delete # non recursively
find Documents -maxdepth '1' -empty -delete # non recursively
# Get the extensions of all files larger than 1MB.
find . -type f -size +1M -exec basename {} \; | sed 's|.*\.||' | sort -u
find . -type 'f' -size '+1M' -exec basename {} \; | sed 's|.*\.||' | sort -u
# Find all files between 5 and 10 MB.
find . -type 'f' -size '+5M' -size '-10M'
# Find files last accessed exactly 5 hour ago.
find . -type f -amin 300
find . -type f -atime 5h
find . -type 'f' -amin '300'
find . -type 'f' -atime '5h'
# Find files last modified in the last hour.
find . -type f -mmin -60
find . -type f -mtime -1h
find . -type 'f' -mmin '-60'
find . -type 'f' -mtime '-1h'
# Find files created more than 2 days ago.
find . -type f -ctime +2
find . -type 'f' -ctime '+2'
# Find all empty directories in a git repository that are not from git itself.
find path/to/repo -type d -empty -not -path "./.git/*"
find 'path/to/repo' -type 'd' -empty -not -path "./.git/*"
# Find broken symlinks in the given directories, recursively.
find dir/1 dir/n -type l -exec test ! -e {} \; -print
find dir/1 dir/n -xtype l # gnu find only
find 'dir/1' 'dir/N' -type 'l' -exec test ! -e {} \; -print
find 'dir/1' 'dir/N' -xtype 'l' # gnu find only
# Sort files by name, in numeric order, regardless of the directory they are in.
find . -type f -o -type l \
find . -type 'f' -o -type 'l' \
| awk 'BEGIN {FS="/"; OFS="|"} {print $NF,$0}' \
| sort --field-separator '|' --numeric-sort \
| cut -d '|' -f2
# Print quoted file paths.
# %p is for path.
find . -type f -printf '"%p"\n'
find . -type f -printf "'%p'\n"
find . -type 'f' -printf '"%p"\n'
find . -type 'f' -printf "'%p'\n"
# Sort files by size.
# %s is for size, %p is for path.
find . -type f -printf '%s %p\n' | sort -nr | head -50
find . -type 'f' -printf '%s %p\n' | sort -nr | head -50
# Find files which are executable but not readable.
find /sbin /usr/sbin -executable -not -readable -print
find '/sbin' '/usr/sbin' -executable -not -readable -print
# Find files which are writable by either their owner or their group.
find . -perm /220
find . -perm /u+w,g+w
find . -perm /u=w,g=w
find . -perm '/220'
find . -perm '/u+w,g+w'
find . -perm '/u=w,g=w'
# Find files which are writable by both their owner and their group.
find . -perm -220
find . -perm -g+w,u+w
find . -perm '-220'
find . -perm '-g+w,u+w'
# Record set-user-ID files and directories into '/root/suid.txt', and large
# files into 'big-files.txt'
find / \
\( -perm -4000 -fprintf /root/suid.txt '%#m %u %p\n' \) , \
\( -size +100M -fprintf big-files.txt '%-10s %p\n' \)
\( -perm '-4000' -fprintf '/root/suid.txt' '%#m %u %p\n' \) , \
\( -size '+100M' -fprintf 'big-files.txt' '%-10s %p\n' \)
# Show files with hard links.
find . -type f -not -links 1
find -type f -links +1
find . -type 'f' -not -links '1'
find -type 'f' -links '+1'
# Show files hard linked to a given file.
# GNU extension.
find -samefile path/to/file
find -samefile 'path/to/file'
```
## Time specifications

View File

@@ -0,0 +1,13 @@
# Limit the CPU usage of a process
## TL;DR
```sh
sudo cpulimit -p 'process-id' -l 'cpu-percentage'
```
## Sources
- [25 awesome linux command one-Liners]
[25 awesome linux command one-liners]: https://betterprogramming.pub/25-awesome-linux-command-one-liners-9495f26f07fb

View File

@@ -19,6 +19,9 @@ mount -t 'cifs' -o 'username=DOMAIN\Administrator,seal,vers=3.0' \
# Mount a NFS share
mount -t 'nfs' 'server:/share_name' '/mount/point'
mount -t 'nfs' -o 'nfsvers=3,nolock' 'server:/share_name' '/mount/point'
# Mount a temporary RAM disk.
mount -t tmpfs tmpfs '/mount/point' -o 'size=2048m'
```
## Further readings

17
knowledge base/ping.md Normal file
View File

@@ -0,0 +1,17 @@
# Ping
## TL;DR
```sh
# Make a sound every time the server receives a packet.
ping -i 120 -a 'ip-address'
```
## Sources
- [18 selected super-useful Linux one-liners]
<!-- project's references -->
<!-- internal references -->
<!-- external references -->
[18 selected super-useful linux one-liners]: https://medium.com/codex/18-selected-super-useful-linux-one-liners-398ba6d20f8c

18
knowledge base/rm.md Normal file
View File

@@ -0,0 +1,18 @@
# Rm
## TL;DR
```sh
# Remove all files but the ones specified.
rm !('path/to/file')
rm !(*.xls|*.slsx|*.csv)
```
## Sources
- [18 selected super-useful Linux one-liners]
<!-- project's references -->
<!-- internal references -->
<!-- external references -->
[18 selected super-useful linux one-liners]: https://medium.com/codex/18-selected-super-useful-linux-one-liners-398ba6d20f8c

View File

@@ -15,21 +15,22 @@
eval `ssh-agent` && ssh-add
# Create new keys.
ssh-keygen -t rsa -b 4096
ssh-keygen -t dsa
ssh-keygen -t ecdsa -b 521
ssh-keygen -t ed25519 -f ~/.ssh/keys/id_ed25519 -C test@winzoz
ssh-keygen -t 'rsa' -b '4096'
ssh-keygen -t 'dsa'
ssh-keygen -t 'ecdsa' -b '521'
ssh-keygen -t 'ed25519' -f ~/.ssh/keys/id_ed25519 -C 'test@winzoz'
# Remove elements from the known hosts list.
ssh-keygen -R "pi4.lan"
ssh-keygen -R 192.168.1.237 -f .ssh/known_hosts
ssh-keygen -R "raspberrypi.lan" -f "${HOME}/.ssh/known_hosts"
ssh-keygen -R 'pi4.lan'
ssh-keygen -R '192.168.1.237' -f '.ssh/known_hosts'
ssh-keygen -R 'pi.lan' -f "${HOME}/.ssh/known_hosts"
# Change the password of a key.
ssh-keygen -f ~/.ssh/id_rsa -p
# Mount a remote folder.
sshfs nas.lan:/mnt/data Data -o auto_cache,reconnect,defer_permissions,noappledouble,volname=Data
sshfs 'nas.lan:/mnt/data' 'Data' \
-o 'auto_cache,reconnect,defer_permissions,noappledouble,volname=Data'
# List keys added to the agent by fingerprint.
ssh-add -l
@@ -37,6 +38,9 @@ ssh-add -L # full key in OpenSSH format
# Authorize keys for passwordless access.
ssh-copy-id -i ~/.ssh/id_rsa.pub user@nas.lan
# Connect to an unreachable host tunnelling the session through a bastion.
ssh -t 'bastion-host' ssh 'unreachable-host'
```
## Key Management
@@ -44,10 +48,10 @@ ssh-copy-id -i ~/.ssh/id_rsa.pub user@nas.lan
Create a new key:
```sh
ssh-keygen -t rsa -b 4096
ssh-keygen -t dsa
ssh-keygen -t ecdsa -b 521
ssh-keygen -t ed25519 -f .ssh/id_ed25519 -C test@winzoz
ssh-keygen -t 'rsa' -b '4096'
ssh-keygen -t 'dsa'
ssh-keygen -t 'ecdsa' -b '521'
ssh-keygen -t 'ed25519' -f '.ssh/id_ed25519' -C 'test@winzoz'
```
```plaintext
@@ -75,9 +79,9 @@ The key's randomart image is:
Remove a host from the list of known hosts:
```sh
ssh-keygen -R "pi4.lan"
ssh-keygen -R 192.168.1.237 -f .ssh/known_hosts
ssh-keygen -R "raspberrypi.lan" -f ".ssh/known_hosts"
ssh-keygen -R 'pi4.lan'
ssh-keygen -R '192.168.1.237' -f '.ssh/known_hosts'
ssh-keygen -R 'raspberrypi.lan' -f '.ssh/known_hosts'
```
```plaintext
@@ -109,14 +113,14 @@ sshfs -o $OPTIONS_LIST $HOST:$REMOTE_PATH $LOCAL_PATH
```
```sh
sshfs user@nas.lan:/mnt/data Data -o auto_cache,reconnect,defer_permissions,noappledouble,volname=Data
sshfs 'user@nas.lan:/mnt/data' 'Data' -o 'auto_cache,reconnect,defer_permissions,noappledouble,volname=Data'
```
### Installation
```sh
# Mac OS X requires `macports`, since `brew` does not offer 'sshfs' anymore
sudo port install sshfs
sudo port install 'sshfs'
```
## Configuration