Check These Out
Converts any number of seconds into days, hours, minutes and seconds.
sec2dhms() {
declare -i SS="$1"
D=$(( SS / 86400 ))
H=$(( SS % 86400 / 3600 ))
M=$(( SS % 3600 / 60 ))
S=$(( SS % 60 ))
[ "$D" -gt 0 ] && echo -n "${D}:"
[ "$H" -gt 0 ] && printf "%02g:" "$H"
printf "%02g:%02g\n" "$M" "$S"
}
Using OpenSSL we can encrypt any input we wish and then use Netcat to create a socket which can be connected to from an externally source (even using a Web Browser)
Here's an annotated version of the command, using full-names instead of aliases. It is exactly equivalent to the short-hand version.
# Recursively list all the files in the current directory.
Get-ChildItem -Recurse |
# Filter out the sub-directories themselves.
Where-Object { return -not $_.PsIsContainer; } |
# Group the resulting files by their extensions.
Group-Object Extension |
# Pluck the Name and Count properties of each group and define
# a custom expression that calculates the average of the sizes
# of the files in that group.
# The back-tick is a line-continuation character.
Select-Object `
Name,
Count,
@{
Name = 'Average';
Expression = {
# Average the Length (sizes) of the files in the current group.
return ($_.Group | Measure-Object -Average Length).Average;
}
} |
# Format the results in a tabular view, automatically adjusted to
# widths of the values in the columns.
Format-Table -AutoSize `
@{
# Rename the Name property to something more sensible.
Name = 'Extension';
Expression = { return $_.Name; }
},
Count,
@{
# Format the Average property to display KB instead of bytes
# and use a formatting string to show it rounded to two decimals.
Name = 'Average Size (KB)';
# The "1KB" is a built-in constant which is equal to 1024.
Expression = { return $_.Average / 1KB };
FormatString = '{0:N2}'
}
Requires display.
Corrected version thanks to sputnick and eightmillion user.
Removes ANSI color and end of line codes to the [{attr1};...;{attrn}m format.
I often use it to find recently added ou removed device, or using find in /dev, or anything similar.
Just run the command, plug the device, and wait to see him and only him
You might want to secure your AWS operations requiring to use a MFA token. But then to use API or tools, you need to pass credentials generated with a MFA token.
This commands asks you for the MFA code and retrieves these credentials using AWS Cli. To print the exports, you can use:
`awk '{ print "export AWS_ACCESS_KEY_ID=\"" $1 "\"\n" "export AWS_SECRET_ACCESS_KEY=\"" $2 "\"\n" "export AWS_SESSION_TOKEN=\"" $3 "\"" }'`
You must adapt the command line to include:
* $MFA_IDis ARN of the virtual MFA or serial number of the physical one
* TTL for the credentials