Short tips – Parte 1

Dicas curtas publicadas no meu perfil do Twitter. Para ver outras dicas acesse o índice com todas as partes.

Short tip of the day:
server $ cat hello.txt
Hello World!
server $ python -m http.server
Serving HTTP on :: port 8000 (http://[::]:8000/) ...

client $ curl http://server.local:8000/hello.txt
Hello World!
Short tip of the day:
local $ man ssh  # search for 'ESCAPE CHARACTERS'
local $ ssh remote
remote $ # frozen ssh session...
~.<ENTER>

local $ # use ~<SPACE>.<ENTER> in keyboards with deadkey accents
Short tip of the day:
$ cat msg.json
{"meta": {"fmt": "msg", "type": "json"}, "files": ["m1.json"]}
$ cat msg.json | python -m json.tool --indent 2
{
  "meta": {
    "fmt": "msg",
    "type": "json"
  },
  "files": [
    "m1.json"
  ]
}
$ cat msg.json | jq  # syntax highlight
Short tip of the day (continuação de ontem):
$ # bash
$ echo "Hello World!" > hello.txt
$ du hello.txt
8 hello.txt
$ > hello.txt
$ du hello.txt
0 hello.txt
$ # bash
$ du new
du: new: No such file or directory
$ > new
$ du new
0 new
$ ./highlander
Who wants to live forever?
Who wants to live forever?
^C
^C
^C
^\
Quit: 3
$ # CTRL-C sends a SIGINT, and CTRL-\ (or CTRL-4) sends a SIGQUIT to the process
$ stty -a | sed -n '/^cchars/,$p'  # print all control characters
$ cat ./bin_file
����@��
       �@�0����X
� H__PAGEZERO__TEXT@@	__text__TEXT�7�7�__stubs__TEXT�;T��__stub_
^C
^C
�@�0����X $ # broken terminal (you aren't seeing this message :P)
$ reset
$ # restored terminal
$ python -m webbrowser -t example.com  # open new tab browser at example.com
$ python -m webbrowser -n example.com  # open new window browser at example.com
$ time cp -r ./src/* ./target/
real0m2.193s
$ rm -rf ./target/*
$ time ((cd ./src/; tar cf - .) | tar xfp -)
real0m1.920s
$ # lots of things on terminal
$ clear
$ # ... and again...
linux $ ^L  # CTRL-L on Linux -> clear terminal
macos $ CMD-K  # COMMAND-K on macOS -> clear terminal
dir1 $ rm *
-bash: /bin/rm: Argument list too long
dir1 $ find . -type f -exec rm {} \;
dir1 $ cd ../dir2
dir2 $ rm *
-bash: /bin/rm: Argument list too long
dir2 $  find . -type f | while read f; do rm "$f"; done
$ find / > files.log 2> /dev/null
???
^C
$ find / | tee files.log 2> /dev/null
... all files ...
^C
$ cat files.log
... all files again ...
Available for Amazon Prime