mkdir -p
instead of mkdir
ln -sfn source target
instead of ln -s source target
rm -f example.txt
instead of rm example.txt
Modifying a file
if ! grep -qF "/mnt/dev" /etc/fstab; then
echo "/dev/sda1 /mnt/dev ext4 defaults 0 0" | sudo tee -a /etc/fstab
fi
Check if variable, file or dir exists
formatting a device
mounting a device
touch {hero,lightbox,form,another-component}.njk
Only one same job at a time ?
My solution to deal with this is to bind an IPv6 localhost ::1 socket to a given port. Only one process can do this, and thus it’s a very effective mutex. No lock files to cause havoc, no dealing with the dark and buggy corners of advisory file locking.
For shell scripts, simply replace the #!/bin/sh with #!/somewhere/bin/lock 2048 where 2048 is the port number you will use to enforce the lock (greater than 1024 if you do not want to deal with the hassles of privileged ports).
Using the tool jc to convert the output of a command to JSON.
Takeaways:
- It is possible to list a directory with 8 million files in it.
- strace is your friend
- Don't be afraid to compile code and modify it (hell, simple C compiles so fast it could be interpreted)
- There is no good reason to have 8 million files in a directory :-), but this was a good learning experience (and possibly a good interview question).
The last point is the most important :D
$'$HOME'
expands escape sequences like \n or \'
Do one thing per command and one only. Everything will be fine.
Amend a commit message by ID. A simple script.
Yes 👍
I really enjoy the explanation on how to use pushd and popd to navigate between directories.
After pushd, it is possible de navigate through cd ~n
with n the index of the path in the stack.
cd -
to return to the previous path :)
A great list of tools. A majority of them are written in Rust 😄
😮
cat toto.txt | sort | uniq > pas-de-doublons.txt
to
cat toto.txt | awk '!x[$0]++' > pas-de-doublons.txt
Using the shell for daily tiny tasks ❤️
Fun ! This respect the KISS principle 😄
Using the tool named souffle
.
command | meaning |
---|---|
${parameter:-defaultValue} | Get default shell variables value |
${parameter:=defaultValue} | Set default shell variables value |
${parameter:?"Error Message"} | Display an error message if parameter is not set |
${#var} | Find the length of the string |
${var%pattern} | Remove from shortest rear (end) pattern |
${var%%pattern} | Remove from longest rear (end) pattern |
${var:num1:num2} | Substring |
${var#pattern} | Remove from shortest front pattern |
${var##pattern} | Remove from longest front pattern |
${var/pattern/string} | Find and replace (only replace first occurrence) |
${var//pattern/string} | Find and replace all occurrences |
${!prefix*} | Expands to the names of variables whose names begin with prefix. |
${var,} | Convert first character to lowercase. |
${var,pattern} | Convert only if the pattern match |
${var,,} | Convert all characters to lowercase. |
${var,,pattern} | Convert only if the pattern match |
${var^} | Convert first character to uppercase. |
${var^pattern} | Convert only if pattern match |
${var^^} | Convert all character to uppercase.} |
${var^^pattern} | Convert only if pattern match |
Using two clipboards: one main + one swap
Make import of bash functions from an URL, mhmhmhmh