Shell Knowledge
- Spawn a TTY using Python
- Manually generate a crypt (/etc/shadow) password
- Get total duration of video files
- Iterate over lines in a file or a command
- Unique files using AWK
Spawn a TTY using Python
Spawn a “real” TTY. Useful for sudo, su, ssh…
python -c 'import pty; pty.spawn("/bin/sh")'
Manually generate a crypt (/etc/shadow) password
Generate a UNIX crypt password with a given salt and password
openssl passwd -1 -salt <SALT> <PASSWORD>
# openssl passwd -1 -salt salty bacon
$1$salty$OxTbIoRN3a6XyEn362VfU0
Found here
Get total duration of video files
Get the total duration of video files in a directory.
exiftool -n -q -p '${Duration;our $sum;$_=ConvertDuration($sum+=$_)}' */*.mp4 | tail -n1
Found here
Iterate over lines in a file or a command
Execute any command on every single line of a given file.
while read p; do
echo $p;
done < file
This may be used also on multi-line spaced outputs.
find S0* | while read p; do
echo $p;
done
Unique files using AWK
For a given file, print unique lines, even if the file is not sorted (unlike
uniq
). High memory use for big files!
awk '!a[$0]++' FILE