Linux kullanıcıları için kullanışlı bir komut bütünü, Satır İçindeki Belli Kelimeleri Silme için;
1 |
find / -maxdepth 1 -xdev -type f -exec grep -i "stringtofind" -l {} \; -exec sed -i '/./d' {} \; |
Linux kullanıcıları için kullanışlı bir komut bütünü, Satır İçindeki Belli Kelimeleri Silme için;
1 |
find / -maxdepth 1 -xdev -type f -exec grep -i "stringtofind" -l {} \; -exec sed -i '/./d' {} \; |
Örnek
1 2 3 |
var = 'abc' var = "${var}def" echo $var |
abcdef
Shell script yazmayı seven biri olarak, bazen kabuk programlama yaparken birden fazla satırı comment yani yorum satırı haline getirmek için aşağıdaki yönetemi kullanabilirsiniz.
1 2 3 4 5 6 7 |
<<COMMENT1 //kod bloğu COMMENT1 (or) <<comment1 //kod bloğu comment1 |
Linux’da Tshark ile Mysql,Memcache ve PostgreSQL Trafiğini Analiz Etme
1 |
# /usr/sbin/tshark -d tcp.port==3306,mysql -T fields -R mysql.query -e frame.time -e ip.src -e ip.dst -e mysql.query |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
[root@sessiondb ~]$tshark -d tcp.port==3306,mysql -T fields -R mysql.query -e frame.time -e ip.src -e ip.dst -e mysql.query Running as user "root" and group "root". This could be dangerous. Capturing on eth0 May 22, 2015 14:24:13.515665000 10.10.140.30 10.10.141.70 select @@session.tx_read_only May 22, 2015 14:24:13.516158000 10.10.140.30 10.10.141.70 update sessionsV2 set accessTime = 1432293853449, lastAccessTime = 1432293736476, lastUpdatedTime = 1432293853511, expiryTime = 1432295653449 where sessionId = '56edda9cfaaf44f8a57cfb0c85094200' May 22, 2015 14:24:13.518402000 10.10.140.30 10.10.141.70 SET autocommit=1 May 22, 2015 14:24:13.518697000 10.10.140.30 10.10.141.70 set session transaction read write May 22, 2015 14:24:13.536207000 10.10.140.29 10.10.141.70 select * from sessionsV2 where sessionId = 'f1e21f16ae7b4b958a8223cf9022b4c0' May 22, 2015 14:24:13.537542000 10.10.140.29 10.10.141.70 SET autocommit=1 May 22, 2015 14:24:13.537781000 10.10.140.29 10.10.141.70 set session transaction read write May 22, 2015 14:24:13.554846000 10.10.140.29 10.10.141.70 select @@session.tx_read_only May 22, 2015 14:24:13.555251000 10.10.140.29 10.10.141.70 update sessionsV2 set accessTime = 1432293853537, lastAccessTime = 1432293757464, lastUpdatedTime = 1432293853553, expiryTime = 1432295653537 where sessionId = 'f1e21f16ae7b4b958a8223cf9022b4c0' May 22, 2015 14:24:13.556247000 10.10.140.9 10.10.141.70 select * from sessionsV2 where sessionId = 'f8ff81b391e34c1098f6fd08df0ebabc' May 22, 2015 14:24:13.557241000 10.10.140.9 10.10.141.70 SET autocommit=1 May 22, 2015 14:24:13.557481000 10.10.140.9 10.10.141.70 set session transaction read write May 22, 2015 14:24:13.558348000 10.10.140.29 10.10.141.70 SET autocommit=1 May 22, 2015 14:24:13.558625000 10.10.140.29 10.10.141.70 set session transaction read write May 22, 2015 14:24:13.559593000 10.10.140.29 10.10.141.70 select * from sessionsV2 where sessionId = '84dd557532d745cf83063a9d65c0d67d' May 22, 2015 14:24:13.561145000 10.10.140.29 10.10.141.70 SET autocommit=1 May 22, 2015 14:24:13.561483000 10.10.140.29 10.10.141.70 set session transaction read write May 22, 2015 14:24:13.561614000 10.10.140.9 10.10.141.70 select * from sessionsV2 where sessionId = 'be5167049cce4b2eaccd619fbe2fc6d0' May 22, 2015 14:24:13.562634000 10.10.140.30 10.10.141.70 select * from sessionsV2 where sessionId = '47d6b5fca3ca413b87b1184b0339ced9' May 22, 2015 14:24:13.562658000 10.10.140.9 10.10.141.70 SET autocommit=1 |
1 |
# /usr/sbin/tshark -d tcp.port==3306,mysql -T fields -R mysql.query -e frame.time -e ip.src -e ip.dst -e mysql.query |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
[root@memcache ~]$tshark -d tcp.port==11211,memcache -T fields -R memcache.command -e frame.time -e ip.src -e ip.dst -e memcache.key -e tcp.analysis.ack_rtt Running as user "root" and group "root". This could be dangerous. Capturing on eth0 May 22, 2015 14:21:46.309078000 10.10.11.150 10.10.11.60 videosRelated:1035167-20 May 22, 2015 14:21:46.311851000 10.10.11.150 10.10.11.60 videosRelated:1035167-20 May 22, 2015 14:21:46.359910000 10.10.11.131 10.10.11.60 getWeeklyMostLikedVideosByCategoryId-2233785415175766016-true-0-4 May 22, 2015 14:21:46.406764000 10.10.11.131 10.10.11.60 getMostUsedTagsByCategory144188787844644864 May 22, 2015 14:21:46.408895000 10.10.11.131 10.10.11.60 getMostUsedTagsByCategory144188787844644864 May 22, 2015 14:21:46.409494000 10.10.11.131 10.10.11.60 getAllTimeMostViewedVideosBySubjectId-144188787844644864-false-0-12 0.000525000 May 22, 2015 14:21:46.414209000 10.10.11.131 10.10.11.60 getAllTimeMostViewedVideosBySubjectId-144188787844644864-false-0-12 0.004652000 May 22, 2015 14:21:46.416596000 10.10.11.131 10.10.11.60 getMostUsedTagsByCategory144188787844644864 0.002320000 May 22, 2015 14:21:46.464455000 10.10.11.161 10.10.11.60 getAllTimeMostViewedVideosBySubjectId-144188787843465216-false-0-1000 May 22, 2015 14:21:46.510011000 10.10.11.161 10.10.11.60 getAllTimeMostViewedVideosBySubjectId-144188787843465216-false-0-1000 May 22, 2015 14:21:46.534224000 10.10.11.132 10.10.11.60 getAllTimeMostViewedVideosByCategoryId-144115188075855872-true-0-7 May 22, 2015 14:21:46.534705000 10.10.11.132 10.10.11.60 getAllTimeMostViewedVideosBySubjectId-144468750186315776-false-0-1000 May 22, 2015 14:21:46.538686000 10.10.11.132 10.10.11.60 getAllTimeMostViewedVideosBySubjectId-144468750186315776-false-0-100 0.003943000 May 22, 2015 14:21:46.686373000 10.10.11.131 10.10.11.60 getMostUsedTagsByCategory2233997002444636160 May 22, 2015 14:21:46.725696000 10.10.11.131 10.10.11.60 getMostUsedTagsByCategory2233997002444636160 May 22, 2015 14:21:46.830658000 10.10.11.132 10.10.11.60 getAllTimeMostViewedVideosByCategoryId-792633534417207296-true-0-7 May 22, 2015 14:21:46.841205000 10.10.11.151 10.10.11.60 videosRelated:11449-2 May 22, 2015 14:21:46.845536000 10.10.11.152 10.10.11.60 videosRelated:1060604-20 May 22, 2015 14:21:46.845899000 10.10.11.151 10.10.11.60 videosRelated:11449-2 May 22, 2015 14:21:46.848504000 10.10.11.132 10.10.11.60 getAllTimeMostViewedVideosBySubjectId-794463877680070656-false-0-100 May 22, 2015 14:21:46.851233000 10.10.11.152 10.10.11.60 videosRelated:1060604-20 May 22, 2015 14:21:46.852728000 10.10.11.132 10.10.11.60 getAllTimeMostViewedVideosBySubjectId-794463877680070656-false-0-100 0.004186000 May 22, 2015 14:21:46.855717000 10.10.11.130 10.10.11.60 getAllTimeMostViewedVideosBySubjectId-433616118632939520-false-0-1000 May 22, 2015 14:21:46.860161000 10.10.11.130 10.10.11.60 getAllTimeMostViewedVideosBySubjectId-433616118632939520-false-0-1000 May 22, 2015 14:21:46.863011000 10.10.11.130 10.10.11.60 getRelatedVideos:1051279 0.002803000 May 22, 2015 14:21:46.869374000 10.10.11.130 10.10.11.60 getRelatedVideos:1051279 May 22, 2015 14:21:46.902502000 10.10.11.131 10.10.11.60 getAllTimeMostViewedVideosByCategoryId-144115188075855872-true-0-7 May 22, 2015 14:21:46.915220000 10.10.11.150 10.10.11.60 videosRelated:13266-2 May 22, 2015 14:21:46.921715000 10.10.11.150 10.10.11.60 videosRelated:13266-2 |
1 |
# /usr/sbin/tshark -d tcp.port==3306,pgsql -T fields -R pgsql.query -e frame.time -e ip.src -e ip.dst -e pgsql.query |
Sunucunuzun belleği belirli bir anda ihtiyaçları için RAM yetersiz olduğunda, RAM yerine sabit sürücüden(disk) bir parça, “takas alanı(swap)” kullanmaya başlar.
Linux sistemi üzerinde takas alanı(swap) temizlemek için gerekli zamanlar olabilir. Bunu yapmak için, ilk önce takas alanı (swap) tarafından kullanılan memory alanı kadar yeterli boş hafıza olduğundan emin olmanız gerekir.
Bunu görmek için
1 |
# free -m |
Swap alanı check etmek için:
1 |
# swapon -s |
1 2 3 |
[root@omeroner ~]$sudo swapon -s Filename Type Size Used Priority /dev/dm-1 partition 524284 0 -1 |
Sonra kullanılan swap alanı free etmek için aşağıdaki komutları çalıştırın:
1 2 |
# swapoff -a # swapon -a |
Sonra bu yaptıktan sonra kullanılıyor ne olduğunu kontrol edin.
1 |
# free -m |
1 2 3 4 5 6 7 8 9 10 11 12 |
[root@omeroner ~]$free -m total used free shared buffers cached Mem: 2893 1708 1185 0 22 106 -/+ buffers/cache: 1579 1313 Swap: 1023 738 285 [root@omeroner ~]$swapoff -a && swapon -a [root@omeroner ~]$free -m total used free shared buffers cached Mem: 2893 2445 448 0 23 107 -/+ buffers/cache: 2314 579 Swap: 1023 0 1023 [root@omeroner ~]$ |
ls komutu, Linux ve Unix gibi işletim sistemleri altında dizin içeriğini listelemek için kullanılır. Herhangi bir seçenek verilmeden ls komutu ile alfabetik sıralama yapılır.
1 |
# ls |
Varsayılan ls komut çıktısı:
1 2 3 |
[root@omeroner /mnt/data]$ls archive backup blogtema bounced_logs download license old_unitednations omer scripts slow_logs slow_logs_full SSL sw_backup ugur unitednation_www |
-l seçeneği ile liste şeklinde ayrıntılı olarak dizin içeriğini listeyebiliriz.
1 |
# ls -l |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
[root@unitednations /mnt/data]$ls -l total 92 drwxr-xr-x 10 root root 4096 Jun 18 2014 archive drwxr-xr-x 6 root root 4096 Sep 22 2014 backup drwxr-xr-x 2 root root 4096 Apr 9 13:09 blogtema drwxr-xr-x 2 root root 4096 May 14 23:44 bounced_logs drwxr-xr-x 5 root root 4096 Aug 5 2014 download drwxr-xr-x 3 root root 4096 Jun 23 2014 license drwxr-xr-x 22 root root 4096 Jun 19 2014 old_unitednations drwxr-xr-x 2 root root 4096 Sep 11 2014 omer drwxr-xr-x 3 root root 4096 May 13 17:48 scripts drwxr-xr-x 219 root root 20480 Mar 23 05:59 slow_logs drwxr-xr-x 213 root root 16384 Mar 23 05:59 slow_logs_full drwxr-xr-x 3 root root 4096 Apr 9 11:27 SSL drwxr-xr-x 4 root root 4096 Jun 20 2014 sw_backup drwxr-xr-x 2 root root 4096 Jun 29 2014 ugur drwxr-xr-x 15 root root 4096 Mar 18 14:55 unitednation_www [root@unitednations /mnt/data]$ |
1 2 3 4 5 |
# ls -S # ls -S -l # ls --sort=size -l # ls --sort=size *.sh # ls -S -l *.sh |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
[root@omeroner /mnt/data/scripts]$ls -lS total 80 -rwxr-xr-x 1 root root 13437 Apr 24 15:26 ssh_select.sh drwxr-xr-x 5 root root 4096 Aug 5 2014 node_modules -rwxr-xr-x 1 root root 2519 Apr 30 15:33 fw.ex -rwxr-xr-x 1 root root 2515 Jul 2 2014 video_get_status.sh -rwxr-xr-x 1 root root 2487 Nov 18 16:13 jnprconfig.ex -rwxr-xr-x 1 root root 2359 Aug 27 2014 driver_info.sh -rwxr-xr-x 1 root root 1821 Jun 28 2014 mysql_slow_analiz.sh -rwxr-xr-x 1 root root 1368 Jun 28 2014 run.sh -rwxr-xr-x 1 root root 1345 Apr 24 10:40 arecordupdate.sh -rwxr-xr-x 1 root root 1096 Aug 15 2014 error_page_count.sh -rwxr-xr-x 1 root root 1039 Aug 7 2014 server.js -rwxr-xr-x 1 root root 1030 Sep 10 2014 server_check.sh -rwxr-xr-x 1 root root 856 Jun 23 2014 f5.ex -rwxr-xr-x 1 root root 615 Nov 18 16:17 move.sh -rwxr-xr-x 1 root root 483 Aug 5 2014 ptr_control.sh -rwxr-xr-x 1 root root 201 Nov 18 16:20 move_ssl.sh -rwxr-xr-x 1 root root 172 Jun 20 2014 ankara_config_backup.sh [root@omeroner /mnt/data/scripts]$ |
1 2 |
# ls -l -S -r # ls -lSr |
1 2 3 4 5 6 7 8 9 10 11 12 13 |
[root@unitednations /mnt/data/scripts]$ls -lSr *.sh -rwxr-xr-x 1 root root 172 Jun 20 2014 ankara_config_backup.sh -rwxr-xr-x 1 root root 201 Nov 18 16:20 move_ssl.sh -rwxr-xr-x 1 root root 483 Aug 5 2014 ptr_control.sh -rwxr-xr-x 1 root root 615 Nov 18 16:17 move.sh -rwxr-xr-x 1 root root 1030 Sep 10 2014 server_check.sh -rwxr-xr-x 1 root root 1096 Aug 15 2014 error_page_count.sh -rwxr-xr-x 1 root root 1345 Apr 24 10:40 arecordupdate.sh -rwxr-xr-x 1 root root 1368 Jun 28 2014 run.sh -rwxr-xr-x 1 root root 1821 Jun 28 2014 mysql_slow_analiz.sh -rwxr-xr-x 1 root root 2359 Aug 27 2014 driver_info.sh -rwxr-xr-x 1 root root 2515 Jul 2 2014 video_get_status.sh -rwxr-xr-x 1 root root 13437 Apr 24 15:26 ssh_select.sh |
Belli bir dizinde bulunan sıkıştırılmış (*.gzip) dosyaları tespit edip bu dosyaların içinde belli bir patern aramak:
1 |
find . -iname '*.gz' -print0 | xargs -0 zgrep PATTERN |
1 |
find . -iname '*.gz' -exec zgrep PATTERN {} + |
Bir dosyada sıralama yaptıktan sonra bazı yinelenen veriler olabilir, bu kayıtları tekilleştirme ihtiyacı duyabilirsiniz. Bunun için sort ve uniq hızlı ve kolay bir yöntemdir. Aşağıdaki komut, sadece dupilcate kayıtları kaldırıp sıralamaya yarayan komut bütünüdür. Uniq komutu ile dosyadaki çift kayıtları kaldırarakmak için;
1 |
# sort dosya.txt | uniq |
1 |
# sort dosya.txt | uniq -u |
1 |
# sort dosya.txt | uniq -d |
1 2 |
sort dosya.txt | uniq -uc sort dosya.txt | uniq -dc |
Linux konsolu kullanırken konsol üzerinde çalıştırdığımız her komut bash history dosyasında yani varsayılan dosya ‘~ / .bash_history’ içerisinde tutulur. Komut geçmişini görmek için en basit kullanım:
1 |
# history |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
root@omeroner ~]$ history 1 PS1='\e[1;35m[\u@\h \w]\$ \e[m ' 2 PS1="\e[0;32m[\u@\h \W]\$ \e[m " 3 PS1="\u@\h:\w [\j]\$ " 4 ping google.com 5 echo $PS1 6 tail -f /var/log/messages 7 tail -f /var/log/messages 8 exit 9 clear 10 history 11 clear 12 history |
Bu çıktıya tarih zaman damgasını eklemek için daha önce paylaştığım history dosyasına tarih damgası ekleme yazısını inceleyebilirsiniz. Continue Reading
Linux konsolunda çalışırken kısayol komutları hızlı çalışmamıza sebep olur. Bunlardan bazıları aşağıda belirttiğim gibi: