Ir para o conteúdo
ou

Software livre Brasil

Tela cheia Sugerir um artigo
 Feed RSS

CommandLineFu

4 de Junho de 2009, 0:00 , por Software Livre Brasil - | Ninguém está seguindo este artigo ainda.

Troca de conhecimentos sobre o uso da linha de comando e referencia direta ao site commandlinefu.com.


Quickly (soft-)reboot skipping hardware checks

6 de Agosto de 2009, 0:00, por Software Livre Brasil - 0sem comentários ainda$ /sbin/kexec -l /boot/$KERNEL --append="$KERNELPARAMTERS" --initrd=/boot/$INITRD; sync; /sbin/kexec -e

If you are doing some tests which require reboots (e. g. startup skripts, kernel module parameters, ...), this is very time intensive, if you have got a hardware with a long pre-boot phase due to hardware checks.

At this time, kexec can help, which only restarts the kernel with all related stuff.

First the kernel to be started is loaded, then kexec -e jumps up to start it.

Is as hard as a reboot -f, but several times faster (e. g. 1 Minute instead of 12 on some servers here).

commandlinefu.com

by David Winterbottom (codeinthehole.com)



Query Wikipedia via console over DNS

6 de Agosto de 2009, 0:00, por Software Livre Brasil - 0sem comentários ainda$ dig +short txt <keyword>.wp.dg.cx

Query Wikipedia by issuing a DNS query for a TXT record. The TXT record will also include a short URL to the complete corresponding Wikipedia entry.You can also write a little shell script like:

$ cat wikisole.sh

#!/bin/sh

dig +short txt ${1}.wp.dg.cx

and run it like

./wikisole.sh unix

were your first option ($1) will be used as search term.

commandlinefu.com

by David Winterbottom (codeinthehole.com)



Have an ssh session open forever

6 de Agosto de 2009, 0:00, por Software Livre Brasil - 0sem comentários ainda$ autossh -M50000 -t server.example.com 'screen -raAd mysession'

Open a ssh session opened forever, great on laptops losing Internet connectivity when switching WIFI spots.

commandlinefu.com

by David Winterbottom (codeinthehole.com)



Get all these commands in a text file with description.

6 de Agosto de 2009, 0:00, por Software Livre Brasil - 0sem comentários ainda$ for x in `jot - 0 2400 25`; do curl "http://www.commandlinefu.com/commands/browse/sort-by-votes/plaintext/$x" ; done > commandlinefu.txt

I tried out on my Mac, jot to generate sequence ( 0,25,50,..), you can use 'seq' if it is linux to generate numbers, need curl installed on the machine, then it rocks.

@Satya

commandlinefu.com

by David Winterbottom (codeinthehole.com)



Show me a histogram of the busiest minutes in a log file:

30 de Julho de 2009, 0:00, por Software Livre Brasil - 0sem comentários ainda$ cat /var/log/secure.log | awk '{print substr($0,0,12)}' | uniq -c | sort -nr | awk '{printf("\n%s ",$0) ; for (i = 0; i<$1 ; i++) {printf("*")};}'

Busiest seconds:

cat /var/log/secure.log | awk '{print substr($0,0,15)}' | uniq -c | sort -nr | awk '{printf("\n%s ",$0) ; for (i = 0; i<$1 ; i++) {printf("*")};}'

commandlinefu.com

by David Winterbottom (codeinthehole.com)



Port Knocking!

29 de Julho de 2009, 0:00, por Software Livre Brasil - 0sem comentários ainda$ knock <host> 3000 4000 5000 && ssh -p <port> user@host && knock <host> 5000 4000 3000

Knock on ports to open a port to a service (ssh for example) and knock again to close the port. You have to install knockd.

See example config file below.

[options]

logfile = /var/log/knockd.log

[openSSH]

sequence = 3000,4000,5000

seq_timeout = 5

command = /sbin/iptables -A INPUT -i eth0 -s %IP% -p tcp --dport 22 -j ACCEPT

tcpflags = syn

[closeSSH]

sequence = 5000,4000,3000

seq_timeout = 5

command = /sbin/iptables -D INPUT -i eth0 -s %IP% -p tcp --dport 22 -j ACCEPT

tcpflags = syn

commandlinefu.com

by David Winterbottom (codeinthehole.com)



Attach screen over ssh

24 de Julho de 2009, 0:00, por Software Livre Brasil - 0sem comentários ainda$ ssh -t remote_host screen -r

Directly attach a remote screen session (saves a useless parent bash process)

commandlinefu.com

by David Winterbottom (codeinthehole.com)



Diff on two variables

22 de Julho de 2009, 0:00, por Software Livre Brasil - 0sem comentários ainda$ diff <(echo "$a") <(echo "$b")

You got some results in two variables within your shell script and would like to find the differences? Changes in process lists, reworked file contents, ... . No need to write to temporary files. You can use all the diff parameters you'll need. Maybe anything like $ grep "^>"

is helpful afterwards.

commandlinefu.com

by David Winterbottom (codeinthehole.com)



Draw a Sierpinski triangle

10 de Julho de 2009, 0:00, por Software Livre Brasil - 0sem comentários ainda$ perl -e 'print "P1\n256 256\n", map {$_&($_>>8)?1:0} (0..0xffff)' | display

OK, not the most useful but a good way to impress friends. Requires the "display" command from ImageMagick.

(by dstahlke)

commandlinefu.com

by David Winterbottom (codeinthehole.com)



Show a 4-way scrollable process tree with full details.

9 de Julho de 2009, 0:00, por Software Livre Brasil - 0sem comentários ainda$ ps awwfux | less -S

If you want a visual representation of the parent/child relationships between processes, this is one easy way to do it. It's useful in debugging collections of shell scripts, because it provides something like a call traceback.

When a shell script breaks, just remember "awwfux".

(by ToyKeeper)

commandlinefu.com

by David Winterbottom (codeinthehole.com)



Tags deste artigo: cli commandline unix terminal