commandlinefu.com is the place to record those command-line gems that you return to again and again.
Delete that bloated snippets file you've been using and share your personal repository with the world. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.
You can sign-in using OpenID credentials, or register a traditional username and password.
First-time OpenID users will be automatically assigned a username which can be changed after signing in.
Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.
» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10
Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):
Subscribe to the feed for:
Captures video from webcam and encodes it using the accelerated hardware provided by videotoolbox framework. It takes about 20% cpu in a i5 2015 macbook air.
Downloads each file from a github gist individually.
Requires jq ( https://stedolan.github.io/jq/ ).
I wanted to count and display the top directories containing JavaScript files in some of my project. Here it is. Maybe it can be written to more simply syntax by using find -exec...
simple jq one-liner to convert from configmaps to secrets (which require the values to be base64 encoded).
To automatically pull the config map, convert it, and re-upload the corresponding secret:
kubectl get --export -o json cm [configmap name] | jq 'with_entries(if .key == "data" then .value=(.value | to_entries | map( { (.key): (.value|@base64) } ) | add ) elif .key == "kind" then .value="Secret" else . end)' > secret.json; kubectl create -f secret.json
The classical 'ps aux | grep' can do this with one more parameter, the '-v', with means 'NOT' to grep.
Hides the process "your_command" from showing with ps, displaying some other random process name already running for a better camouflage.
This is a bit of a bash hack to catch STDERR and append a log level to it.
So for example, if your script has pseudo loglevels like so:
echo "INFO - finding files"
[ -f ${files} ] || echo "WARN - no files found"
Any subcommands that write to STDERR will screw that up
Adding 2> >(fb=$(dd bs=1 count=1 2>/dev/null | od -t o1 -A n); [ "$fb" ] && err=$(printf "\\${fb# }"; cat) && echo "ERROR - $err") to the command does the following:
2>
Redirect STDERR
>(
Spawn a subshell (STDERR is then redirected to the file descriptor for this subshell)
fb=$(....)
get the first byte of input
[ "$fb" ]
test if there's a first byte
&& err=$(printf....)
save the output to the $err variable
&& echo "ERROR - $err"
append your pseudo loglevel and the error message
Heavily borrowed from https://unix.stackexchange.com/questions/33049/check-if-pipe-is-empty-and-run-a-command-on-the-data-if-it-isnt
It takes the first value of /prov/loadavg to print that many stars followed by the value.
Docker's local man pages are (often) half of what you have online, so I wanted that as local man.
Install lynx and run my oneliner, then use as follows:
dockpage
Adjust lynx's page width at will
Usefull, for example, when many ports are exposed and the docker ps output looks cluttered.
Disable password expiration and clear password history for VMware vcenter appliance
Won't work with password login. You must add your RSA key to the server's authorizedkeys file, or change the ssh command adding the -i option for a custom RSA key:
socat "UNIX-LISTEN:/tmp/mysqld.temp.sock,reuseaddr,fork" EXEC:"ssh [email protected] -i /home/user/rsa-keys/id_rsa socat STDIO UNIX-CONNECT\:/var/run/mysqld/mysqld.sock"
---
/tmp/mysqld.temp.sock will be created locally by socat, don't create it yourself. The folder it lives must be writable. Connect your MySQL client to this socket, with database and username set properly.
---
In case you need to forward a remote socket to a LOCAL PORT instead, check http://www.commandlinefu.com/commands/view/9436/socat-tcp-listen5500-execssh-userremotehost-socat-stdio-unix-connectvarrunmysqldmysqld.sock
For example to add up the disk usage at several disjoint locations.
The $[..] is for arithmetic evaluation in bash.
Alternatively pipe to the bc command.
Some sites running on basic web servers don't support the HEAD request, so using "curl -I" on them doesn't work. This will automatically try "curl -I" at first and if that fails with a 4xx or 5xx status code, it falls back to "curl -i" and prints only the headers from that.