poniedziałek, 28 grudnia 2015

check all host's in network

┌─[marek@lati]─[~/projekty/python]
└──╼ nmap -sP 192.168.1.0/24

Starting Nmap 6.47 ( http://nmap.org ) at 2015-12-28 23:18 CET
Nmap scan report for 192.168.1.1
Host is up (0.0045s latency).
Nmap scan report for 192.168.1.16
Host is up (0.0011s latency).
Nmap scan report for 192.168.1.47
Host is up (0.059s latency).
Nmap scan report for 192.168.1.213
Host is up (0.00021s latency).
Nmap done: 256 IP addresses (4 hosts up) scanned in 2.71 seconds


we can also use:

[root@virt ~]# arp-scan --interface=enp0s9 --localnet
Interface: enp0s9, datalink type: EN10MB (Ethernet)
Starting arp-scan 1.8.4 with 256 hosts (http://www.nta-monitor.com/tools/arp-scan/)
192.168.1.1     a0:c5:62:72:c6:00       (Unknown)
192.168.1.16    34:7a:60:d4:e4:43       (Unknown)
192.168.1.54    a4:34:d9:46:9b:c3       (Unknown)
192.168.1.243   78:40:e4:f9:a5:32       (Unknown)

4 packets received by filter, 0 packets dropped by kernel
Ending arp-scan 1.8.4: 256 hosts scanned in 1.906 seconds (134.31 hosts/sec). 4 responded





print lines perl linux

┌─[marek@lati]─[/tmp/test]
└──╼ perl -ne 'print if 1..3' /etc/passwd

root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
bin:x:2:2:bin:/bin:/usr/sbin/nologin

print lines from 1 to 3



delete except some file

┌─[marek@lati]─[/tmp/test]
└──╼ ll
razem 0
-rw-rw-r-- 1 marek marek 0 gru 28 20:38 test.html
-rw-rw-r-- 1 marek marek 0 gru 28 20:38 marek.txt
-rw-rw-r-- 1 marek marek 0 gru 28 20:38 gosia.txt
-rw-rw-r-- 1 marek marek 0 gru 28 20:38 wiktor.html

┌─[marek@lati]─[/tmp/test]
└──╼ rm !(*.html) #delete all except html files

┌─[marek@lati]─[/tmp/test]
└──╼ ls -ltr
razem 0
-rw-rw-r-- 1 marek marek 0 gru 28 20:38 test.html
-rw-rw-r-- 1 marek marek 0 gru 28 20:38 wiktor.html
┌─[marek@lati]─[/tmp/test]



┌─[marek@lati]─[/tmp/test]
└──╼ ll
razem 0
-rw-rw-r-- 1 marek marek 0 gru 28 20:38 test.html
-rw-rw-r-- 1 marek marek 0 gru 28 20:38 wiktor.html
-rw-rw-r-- 1 marek marek 0 gru 28 20:40 2.html
-rw-rw-r-- 1 marek marek 0 gru 28 20:40 1.html
-rw-rw-r-- 1 marek marek 0 gru 28 20:40 3.html
-rw-rw-r-- 1 marek marek 0 gru 28 20:40 5.html
-rw-rw-r-- 1 marek marek 0 gru 28 20:40 4.html
-rw-rw-r-- 1 marek marek 0 gru 28 20:40 6.html
-rw-rw-r-- 1 marek marek 0 gru 28 20:40 8.html
-rw-rw-r-- 1 marek marek 0 gru 28 20:40 7.html
-rw-rw-r-- 1 marek marek 0 gru 28 20:40 9.html
-rw-rw-r-- 1 marek marek 0 gru 28 20:40 10.html
-rw-rw-r-- 1 marek marek 0 gru 28 20:40 1.txt
-rw-rw-r-- 1 marek marek 0 gru 28 20:40 3.txt
-rw-rw-r-- 1 marek marek 0 gru 28 20:40 2.txt
-rw-rw-r-- 1 marek marek 0 gru 28 20:40 4.txt
-rw-rw-r-- 1 marek marek 0 gru 28 20:40 5.txt
-rw-rw-r-- 1 marek marek 0 gru 28 20:40 7.txt
-rw-rw-r-- 1 marek marek 0 gru 28 20:40 6.txt
-rw-rw-r-- 1 marek marek 0 gru 28 20:40 8.txt
-rw-rw-r-- 1 marek marek 0 gru 28 20:40 9.txt
-rw-rw-r-- 1 marek marek 0 gru 28 20:40 10.txt
┌─[marek@lati]─[/tmp/test]
└──╼ rm !(10.txt|9.txt|2.html) #delete all except files in bracket

┌─[marek@lati]─[/tmp/test]
└──╼ ls -ltr
razem 0
-rw-rw-r-- 1 marek marek 0 gru 28 20:40 2.html
-rw-rw-r-- 1 marek marek 0 gru 28 20:40 9.txt
-rw-rw-r-- 1 marek marek 0 gru 28 20:40 10.txt



calc bc - terminal calc

┌─[marek@lati]─[~]
└──╼ for i in `seq 1 50`;do echo "2^$i" | bc; done
2
4
8
16
32
64
128
256
512
1024
2048
4096
8192
16384
32768
65536
131072
262144
524288
1048576
2097152
4194304
8388608
16777216
33554432
67108864
134217728
268435456
536870912
1073741824
2147483648
4294967296
8589934592
17179869184
34359738368
68719476736
137438953472
274877906944
549755813888
1099511627776
2199023255552
4398046511104
8796093022208
17592186044416
35184372088832
70368744177664
140737488355328
281474976710656
562949953421312
1125899906842624

piątek, 11 grudnia 2015

how to customize ps command

ps -eo user,comm,pid,ppid,%mem --sort -%mem | head -20

output:

┌─[marek@lati]─[~]
└──╼ ps -eo user,comm,pid,ppid,%mem --sort -%mem | head -20
USER     COMMAND           PID  PPID %MEM
marek    chrome                   20783 19909  6.5
marek    chrome                   19721 20801  2.4
marek    chrome                   17491 20801  1.8
marek    chrome                   32489 20801  1.4
marek    chrome                   17216 20801  1.3
marek    compiz                   20317 20109  1.3
marek    firefox                    28810 19909  1.3
marek    chrome                   6114 20801  1.2
marek    chrome                   20970 20801  1.0
marek    chrome                   20905 20801  1.0
marek    chrome                   27848 20801  1.0
marek    chrome                   17174 20801  0.9
marek    chrome                   32512 20801  0.7
marek    chrome                   31889 20801  0.6
marek    chrome                   32173 20801  0.6
marek    chrome                   17194 20801  0.6
marek    chrome                   20879 20783  0.5
marek    gnome-keyring-d   19907     1  0.5