Rename part of a filename with discrete shell expansion:
mv /long/annoying/path/{file,stuff}.txt # rename to stuff
mv /long/annoying/path/{,the-}file.txt # adds prefix
How to figure out how many bits your id private key. https://security.stackexchange.com/a/42272/135955
openssl rsa -text -noout -in id_rsa
Generate a random password. https://unix.stackexchange.com/a/306107/162041
openssl rand -hex 12
Copy an ssh key to a box, inluding adding to authorized_keys
.
ssh-copy-id -n -f -i ~/.ssh/mykey user@host
Choose all of one or another during a git conflict. http://gitready.com/advanced/2009/02/25/keep-either-file-in-merge-conflicts.html
git checkout --ours FILE
git checkout --theirs FILE
Undo a git commit --amend https://stackoverflow.com/a/1459264/2601179
git reset --soft HEAD@{1} && git reset
Write several lines to a file in a script. Note that the EOF is just an arbitrary string.
cat > FILE <<<EOF
some
lines
about
stuff
EOF
Get aggregations of some field in Elasticsearch.
d = requests.get('http://localhost:9200/INDEX/doc/_search', json={
'size': 0, 'aggregations': {'NAME': {'terms': {'size': 32, 'field': 'FIELD'}}},
}).json()
[(b['doc_count'], b['key']) for b in d['aggregations']['NAME']['buckets']]
Do command -V FOO
to display what an alias is set to or, whether it's a
function instead. To see how that custom function is defined as do declare -f FOO
.
One can loop and assign over multiple return values or tuples like in shell like
# Create a toy CSV file.
cat > /tmp/foo.csv <<EOF
letter,number,fruit
a,1,apple
b,2,orange
c,3,pear
EOF
# Skip first row, and split by comma.
awk 'NR>1' < /tmp/foo.csv | while IFS=, read col1 col2 col3; do
echo "ROW: $col1 $col2 $col3"
done | column -t
# https://stackoverflow.com/a/3801554/2601179
git ls-files --others --exclude-standard
For example, cat followed by \n, , \n, , \n, , will allow you to see which terminal sequences correspond to those key presses [1]:
% cat
^[[1;3D
^[[1;3C
[1] https://stackoverflow.com/a/12403798/2601179
Here's two different ways to do it:
echo " padded " | xargs
echo " padded " | awk '{$1=$1;1}'
Another more flexible alternative to sleep is to do something like this:
while sleep 2; do foobar; done