Troca de conhecimentos sobre o uso da linha de comando e referencia direta ao site commandlinefu.com.
Nice weather forecast on your shell
28 de Agosto de 2016, 9:43 - sem comentários ainda$ curl wttr.in/seville
Change Seville for your prefered city.
Diff your entire server config at ScriptRock.com
Optimal way of deleting huge numbers of files
7 de Junho de 2016, 16:56 - sem comentários ainda$ rsync -a --delete empty-dir/ target-dir/
This command works by rsyncing the target directory (containing the files you want to delete) with an empty directory. The '--delete' switch instructs rsync to remove files that are not present in the source directory. Since there are no files there, all the files will be deleted.
I'm not clear on why it's faster than 'find -delete', but it is.
Benchmarks here: https://web.archive.org/web/20130929001850/http://linuxnote.net/jianingy/en/linux/a-fast-way-to-remove-huge-number-of-files.html
Diff your entire server config at ScriptRock.com
random git-commit message
4 de Maio de 2016, 9:51 - sem comentários ainda$ git commit -m "$(curl -s http://whatthecommit.com/index.txt)";
Do a git commit using a random message.
Diff your entire server config at ScriptRock.com
Disco lights in the terminal
24 de Novembro de 2015, 15:21 - sem comentários ainda$ while true; do printf "\e[38;5;$(($(od -d -N 2 -A n /dev/urandom)%$(tput colors)))m.\e[0m"; done
Looks best in an 80x24 256-color terminal emulator.
Diff your entire server config at ScriptRock.com
Select rectangular screen area
10 de Novembro de 2015, 22:08 - sem comentários ainda$ Ctrl + Alt
Hold 'Ctrl' + 'Alt' key while selecting rectangular text area of the screen with
left mouse button.
Should work in any terminal screen (xterm, konsole, ...) under X, if not
then try with 'Ctrl' + 'Shift' + 'Alt' or two-combination of these.
Diff your entire server config at ScriptRock.com
du with colored bar graph
12 de Setembro de 2015, 10:36 - sem comentários ainda$ du -x --max-depth=1|sort -rn|awk -F / -v c=$COLUMNS 'NR==1{t=$1} NR>1{r=int($1/t*c+.5); b="\033[1;31m"; for (i=0; i<r; i++) b=b"#"; printf " %5.2f%% %s\033[0m %s\n", $1/t*100, b, $2}'|tac
A more efficient way, with reversed order to put the focus in the big ones.
Diff your entire server config at ScriptRock.com
Determine if a port is open with bash
28 de Agosto de 2015, 19:07 - sem comentários ainda$ : </dev/tcp/127.0.0.1/80
For times when netcat isn't available.
Will throw a Connection refused message if a port is closed.
Scriptable:
(: </dev/tcp/127.0.0.1/80) &>/dev/null && echo "OPEN" || echo "CLOSED"
Diff your entire server config at ScriptRock.com
Read and write to TCP or UDP sockets with common bash tools
30 de Julho de 2015, 21:12 - sem comentários ainda$ exec 5<>/dev/tcp/time.nist.gov/13; cat <&5 & cat >&5; exec 5>&-
Ever needed to test firewalls but didn't have netcat, telnet or FTP?
Enter /dev/tcp, your new best friend. /dev/tcp/(hostname)/(port) is a virtual device that bash can use to talk to TCP ports
First, exec sets up a redirect for /dev/tcp/$server/$host to file descriptor 5.
Then, as per some excellent feedback from @flatcap, we launch a redirect from file descriptor 5 to STDOUT (implied by
Finally, when the second cat dies (the connection is closed), we clean up the file descriptor with 'exec 5>&-'.
This one-liner opens a connection on a port to a server and lets you read and write to it from the terminal.
Example test
replace time.nist.gov with 127.0.0.1
replace 13 with 22
You should see a response from your SSH server:
SSH-2.0-OpenSSH_6.6.1p1 Ubuntu-2ubuntu2
Typing TEST should net you a Protocol Mismatch:
TEST
Protocol mismatch.
It can be used for FTP, HTTP, NTP, or netcat listening on a port (makes for a simple chat client!)
Replace /tcp/ with /udp/ to use UDP instead.
Diff your entire server config at ScriptRock.com
drop first column of output by piping to this
26 de Maio de 2015, 20:55 - sem comentários ainda$ awk '{ $1="";print}'
Diff your entire server config at ScriptRock.com
Search for a process by name
20 de Abril de 2015, 13:09 - sem comentários ainda$ ps -fC PROCESSNAME
ps and grep is a dangerous combination -- grep tries to match everything on each line (thus the all too common: grep -v grep hack). ps -C doesn't use grep, it uses the process table for an exact match. Thus, you'll get an accurate list with: ps -fC sh rather finding every process with sh somewhere on the line.
Diff your entire server config at ScriptRock.com