cat exitstatus.sh #! /bin/bash echo -e "Successful execution" echo -e "=====================" echo "hello world" # Exit status returns 0, because the above command is a success. echo "Exit status" $? echo -e "Incorrect usage" echo -e "=====================" ls --option # Incorrect usage, so exit status will be 2. echo "Exit status" $? echo -e "Command Not found" echo -e "=====================" bashscript # Exit status returns 127, because bashscript command not found echo "Exit status" $? echo -e "Command is not an executable" echo -e "=============================" ls -l execution.sh ./execution.sh # Exit status returns 126, because its not an executable. echo "Exit status" $?
Bash exit status
Temmuz 21, 2011 § Yorum yok § Kalıcı bağlantı
ethtool kullanımı
Temmuz 21, 2011 § Yorum yok § Kalıcı bağlantı
Nic’in özelliklerinin elde edilmesi
ethtool eth0 Settings for eth0: Supported ports: [ TP ] Supported link modes: 10baseT/Half 10baseT/Full 100baseT/Half 100baseT/Full 1000baseT/Full Supports auto-negotiation: Yes Advertised link modes: 10baseT/Half 10baseT/Full 100baseT/Half 100baseT/Full 1000baseT/Full Advertised auto-negotiation: Yes Speed: 100Mb/s Duplex: Full Port: Twisted Pair PHYAD: 1 Transceiver: internal Auto-negotiation: on Supports Wake-on: d Wake-on: d Link detected: yes
Duplex değeri için 3 olasılık vardır
- Full duplex : Enables sending and receiving of packets at the same time. This mode is used when the ethernet device is connected to a switch.
- Half duplex : Enables either sending or receiving of packets at a single point of time. This mode is used when the ethernet device is connected to a hub.
- Auto-negotiation : If enabled, the ethernet device itself decides whether to use either full duplex or half duplex based on the network the ethernet device attached to.
ethtool -s ile nic özellikleri değiştirilebilir.
autoneg özelliğini değiştirelim.
ifdown eth0 eth0 device: Broadcom Corporation NetXtreme II BCM5709 Gigabit Ethernet (rev 20) eth0 configuration: eth-bus-pci-0000:0b:00.0 ethtool -s eth0 autoneg off ethtool eth0 Settings for eth0: Supported ports: [ TP ] Supported link modes: 10baseT/Half 10baseT/Full 100baseT/Half 100baseT/Full 1000baseT/Full Supports auto-negotiation: Yes Advertised link modes: Not reported Advertised auto-negotiation: No Speed: Unknown! (65535) Duplex: Unknown! (255) Port: Twisted Pair PHYAD: 1 Transceiver: internal Auto-negotiation: off Supports Wake-on: g Wake-on: g Link detected: no # ifup eth0
Nic’in speed değerini sabitlemek için:
ethtool -s eth0 speed 100 autoneg off ethtool eth0 Settings for eth0: Supported ports: [ TP ] Supported link modes: 10baseT/Half 10baseT/Full 100baseT/Half 100baseT/Full 1000baseT/Full Supports auto-negotiation: Yes Advertised link modes: Not reported Advertised auto-negotiation: No Speed: Unknown! (65535) Duplex: Unknown! (255) Port: Twisted Pair PHYAD: 1 Transceiver: internal Auto-negotiation: off Supports Wake-on: g Wake-on: g Link detected: no
ethtool -i ile firmware ve driver özellikleri öğrenilebilir.
# ethtool -i eth0 driver: bnx2 version: 2.0.1-suse firmware-version: 1.9.3 bus-info: 0000:04:00.0
Nic’in ağ istatistiklerini öğrenmek için ethtool -S kullanılabilir
# ethtool -S eth0 NIC statistics: rx_bytes: 74356477841 rx_error_bytes: 0 tx_bytes: 110725861146 tx_error_bytes: 0 rx_ucast_packets: 104169941 rx_mcast_packets: 138831 rx_bcast_packets: 59543904 tx_ucast_packets: 118118510 tx_mcast_packets: 10137453 tx_bcast_packets: 2221841 tx_mac_errors: 0 tx_carrier_errors: 0 rx_crc_errors: 0 rx_align_errors: 0 tx_single_collisions: 0 tx_multi_collisions: 0 tx_deferred: 0 tx_excess_collisions: 0 tx_late_collisions: 0 tx_total_collisions: 0 rx_fragments: 0 rx_jabbers: 0 rx_undersize_packets: 0 rx_oversize_packets: 0 rx_64_byte_packets: 61154057 rx_65_to_127_byte_packets: 55038726 rx_128_to_255_byte_packets: 426962 rx_256_to_511_byte_packets: 3573763 rx_512_to_1023_byte_packets: 893173 rx_1024_to_1522_byte_packets: 42765995 rx_1523_to_9022_byte_packets: 0 tx_64_byte_packets: 3633165 tx_65_to_127_byte_packets: 51169838 tx_128_to_255_byte_packets: 3812067 tx_256_to_511_byte_packets: 113766 tx_512_to_1023_byte_packets: 104081 tx_1024_to_1522_byte_packets: 71644887 tx_1523_to_9022_byte_packets: 0 rx_xon_frames: 0 rx_xoff_frames: 0 tx_xon_frames: 0 tx_xoff_frames: 0 rx_mac_ctrl_frames: 0 rx_filtered_packets: 14596600 rx_discards: 0 rx_fw_discards: 0
Network düzgün çalışmıyorsa
- Speed ve Duplex değerlerinin “Unknown” olmasına
- Link detection değerinin No olmasına
bakılabilir.
Nic’in ledini yakmak için -p kullanılabilir
ethtool -p eth0
Split ile dosyaları bölmek
Temmuz 21, 2011 § Yorum yok § Kalıcı bağlantı
$ split --bytes=5M file.txt $ ls -lh -rw------- 1 ramesh programmers 15.2M Apr 2 13:13 file.txt -rw------- 1 ramesh programmers 5.0M Apr 2 18:54 xaa -rw------- 1 ramesh programmers 5.0M Apr 2 18:54 xab -rw------- 1 ramesh programmers 5.0M Apr 2 18:54 xac -rw------- 1 ramesh programmers 128K Apr 2 18:54 xad
Dosya isimlerinin daha anlamlı olması için prefix kullanılabilir
$ split --bytes=5M file.txt split_ $ ls -lh -rw------- 1 ramesh programmers 5.0M Apr 2 18:54 split_aa -rw------- 1 ramesh programmers 5.0M Apr 2 18:54 split_ab -rw------- 1 ramesh programmers 5.0M Apr 2 18:54 split_ac -rw------- 1 ramesh programmers 128K Apr 2 18:54 split_ad -rw------- 1 ramesh programmers 15.2M Apr 2 13:13 file.txt
Dosyaları birleştirmek için
$ cat xa? > outfile.txt.zip (or) $ cat split_a? > outfile.txt.zip
Zip ile dosya sıkıştırmak
Temmuz 21, 2011 § Yorum yok § Kalıcı bağlantı
zip hem Linux hem de windows kullanıcılarının açabileceği bir dosya formatı olarak
sıkıştırma için tercih edilebilir.
Bir adet dosyayı sıkıştırmak
zip output-file.zip input-file
Birden fazla dosyayı sıkıştırmak
zip output-file.zip input-file1 input-file2 input-file3 ...
Klasör sıkıştırmak
zip -r output-file.zip input-dir-name
Sıkıştırırken şifrelemek için -e kullanılabilir
zip -e output-file.zip intput-file
Sıkıştırılmış dosyaları açmak için
zip -e output-file.zip intput-file
Donanım Bilgilerini Öğrenmek
Temmuz 21, 2011 § Yorum yok § Kalıcı bağlantı
lshal
lshw
bu sonuclarda “vendor” aranabilir.
lspci kullanılarak
lspci -vvnn
Diff ile dosya karşılaştırmak
Temmuz 21, 2011 § Yorum yok § Kalıcı bağlantı
Boş satırları görmezden gelerek dosya karşılaştırmak
diff -w file1.txt file2.txt 2c2 < hscripts.com --- > HSCRIPTS.com 4d3 < Hioxindia.com
diff -y kullanarak satır satır karşılaştırma yapılabilir.
-b ile boş satırlar ihmal ediliyor
diff -by file1.txt file2.txt HIOX TEST HIOX TEST hscripts.com | HSCRIPTS.com with friend ship with friend ship Hioxindia.com <
diff -i ile case insensitive karşılaştırma yapılabilir.
diff -iy file1.txt file2.txt HIOX TEST HIOX TEST hscripts.com HSCRIPTS.com with friend ship | with friend ship Hioxindia.com <
Diff sonucunu okumak:
cat email 1 John erpl08@ed 2 Joe CZT@cern.ch 3 Kim ks@x.co 4 Keith keith@festival cat addresses 1 John erpl08@ed 2 Joe CZT@cern.ch 3 Jean JRS@pollux.ucs.co 4 Jim jim@frolix8 5 Kim ks@x.co 6 Keith keith@festival
diff email addresses 2a3,4 > Jean JRS@pollux.ucs.co > Jim jim@frolix8
To make these files match you need to add (a) lines 3 and 4 (3,4) of the file addresses (>) after line 2 in the file email.
diff cookies.old cookies.new 5c5 < One cup vanilla extract --- > One teaspoon vanilla extract 7d6 < Six ounces chopped liver 21a22 > Note: The previous version of this recipe had a few errors!
The output is actually a description of how to transform the old file into the new one. Here, diff is telling you three things:
· The fifth line of the file has undergone a change. The 5c5 message says to replace line 5 of the old file with line 5 of the new file. Both the old and new text are displayed, separated by a line of three dashes. (The less-than (<) notation means “remove this line,” and the greater-than (>) sign means “add this line.”)
· Line 7 of the old file does not appear in the new file. The 7d6 message says to delete line 7 from the old file, and the files will then be in sync, starting at line 6 of the new file. The text to be deleted is displayed on the next line.
· A line was added to the new file. The 21a22 message says to add a new line after line 21 of the old file. The text to be added is displayed on the final line of the output.
Cut ile dosya kesmek
Temmuz 21, 2011 § Yorum yok § Kalıcı bağlantı
Veri dosyasinin içeriği:
”
406378:Sales:Itorre:Jan
031762:Marketing:Nasium:Jim
636496:Research:Ancholie:Mel
396082:Sales:Jucacion:Ed
”
olsun.
İlk 6 sütunun alınmasu
cut -c1-6 company.data 406378 031762 636496 396082
4. ve 8. sütunun alınması
cut -c4,8 company.data 3S 7M 4R 0S
seperator olarak “:” kullanıp 3. kolonu almak
cut -d: -f3 company.data Itorre Nasium Ancholie Jucacion
-c [n | n,m | n-m] Specify a single column, multiple columns (separated by a comma), or range of columns (separated by a dash). -f [n | n,m | n-m] Specify a single field, multiple fields (separated by a comma), or range of fields (separated by a dash). -dc Specify the field delimiter. -s Suppress (don’t print) lines not containing the delimiter.
Shell değiştirmek
Temmuz 21, 2011 § Yorum yok § Kalıcı bağlantı
$ cat /etc/shells # /etc/shells: valid login shells /bin/csh /bin/sh /usr/bin/es /usr/bin/ksh /bin/ksh /usr/bin/rc /usr/bin/tcsh /bin/tcsh /usr/bin/esh /bin/dash /bin/bash /bin/rbash /usr/bin/screen /bin/ksh93
Shell değiştirmek
$ echo $0 /bin/bash $ exec /bin/sh $ echo $0 /bin/sh
Kalıcı olarak shell değiştirmek
$ chsh -s /bin/sh Password:
Dosya ve directory isimleri
Temmuz 21, 2011 § Yorum yok § Kalıcı bağlantı
$ basename /usr/local/share/doc/foo/foo.txt foo.txt $ basename /usr/home/drobbins drobbins
$ dirname /usr/local/share/doc/foo/foo.txt /usr/local/share/doc/foo $ dirname /usr/home/drobbins/ /usr/home
BC ile aritmetik
Temmuz 21, 2011 § Yorum yok § Kalıcı bağlantı
$ echo $(( 100 / 3 )) 33 $ myvar="56" $ echo $(( $myvar + 12 )) 68 $ echo $(( $myvar - $myvar )) 0 $ myvar=$(( $myvar + 1 )) $ echo $myvar 57
Toplama
$ echo '57+43' | bc 100
Çıkarma
$ echo '57-43' | bc 14
Çarpma
$ echo '57*43' | bc 2451
scale değişkeni sonucun virgülden sonrası için gösterilecek basamak adedini belirler.
Default değeri 0 dır.
-l ile kullanılırsa değeri 20 kabul edilir.
Bölme
$ echo 'scale=25;57/43' | bc 1.3255813953488372093023255
Karekök alma
$ echo 'scale=30;sqrt(2)' | bc 1.414213562373095048801688724209
Üs almak
$ echo '6^6' | bc 46656
Değişik tabanlarda işlem yapmak için obase ve ibase kullanabiliriz.
obase output tabanını belirler ve 2 ila 999 arasında değer alabilir.
ibase input tabanını belirler ve 2 ila 16 arasında değer alabilir.
255 sayısını 10 tabanından 16 tabanına çevirme:
$ echo 'obase=16;255' | bc FF
2 tabanındaki sayıyı 10 tabanına çevirmek
$ echo 'ibase=2;obase=A;10' | bc 2
bc’yi bash içinde kullanmak için
$ FIVE=5 ; echo "$FIVE^2" | bc 25
bc’ye dosyadan işlem yaptırmak için “bc -q filename” kullanılabilir.
Dosya içeriği aşagıdaki gibi olabilir.
scale=2 /* C-style comments are allowed, as are spaces */ print "\nConvert Fahrenheit to Celsius\n\n" print "Temperature in Fahrenheit: " ; fah = read() print "\n" print "Equivalent Temperature in Celsius is: " (fah - 32.0) * 5.0 / 9.0 quit