Ağustos 17, 2011 § § Kalıcı bağlantı
Komutların sırasını ve tarihlerini görebilmek için
export HISTTIMEFORMAT='%F %T '
history | more
1 2008-08-05 19:02:39 service network restart
2 2008-08-05 19:02:39 exit
3 2008-08-05 19:02:39 id
4 2008-08-05 19:02:39 cat /etc/redhat-release
Ctrl+R ile historyde arama yapılabilir.
Her Ctrl+R basıldığında bir diğer arama sonucu getirilir.
Sağ-Sol ok tuşları ile bulunan komut alınabilir.
History sırasına göre komut çalıştırmak için
history | more
1 service network restart
2 exit
3 id
4 cat /etc/redhat-release
!4
cat /etc/redhat-release
Fedora release 9 (Sulphur)
Başlangıcı bilinen (ps ile başlayan son komut) komutu history’de çalıştırmak
!ps
ps aux | grep yp
root 16947 0.0 0.1 36516 1264 ? Sl 13:10 0:00 ypbind
root 17503 0.0 0.0 4124 740 pts/0 S+ 19:19 0:00 grep yp
Komutun historyde görünmemesi için
export HISTCONTROL=ignorespace
ls -ltr
pwd
service httpd stop
[Note that there is a space at the beginning of service,
to ignore this command from history]
history | tail -3
67 ls -ltr
68 pwd
69 history | tail -3
Ağustos 17, 2011 § § Kalıcı bağlantı
Programı yazalım
$ vim factorial.c
# include <stdio.h>
int main()
{
int i, num, j;
printf ("Enter the number: ");
scanf ("%d", &num );
for (i=1; i<num; i++)
j=j*i;
printf("The factorial of %d is %d\n",num,j);
}
$ cc factorial.c
$ ./a.out
Enter the number: 3
The factorial of 3 is 12548672
gdb kullanabilmek için ”cc -g” ile compile edelim
$ cc -g factorial.c
Önce gdb yi a.out için çalıştırıyoruz.
$ gdb a.out
Sonra break point koyuyoruz
Syntax:
break line_number
*
break [file_name]:line_number
*
break [file_name]:func_name
break 10
Breakpoint 1 at 0x804846f: file factorial.c, line 10.
“run ” ile programı çalıştır
run [args]
run
Starting program: /home/sathiyamoorthy/Debugging/c/a.out
İlk break pointe kadar program çalışır eder
Breakpoint 1, main () at factorial.c:10
10 j=j*i;
Bu noktada debug edebiliriz
Değişken değerlerine bakalım
Syntax: print {variable}
Examples:
print i
print j
print num
(gdb) p i
$1 = 1
(gdb) p j
$2 = 3042592
(gdb) p num
$3 = 3
(gdb)
gdb ile kullanılabilecek diğer seçenekler
c (continue kısaltması): Bir sonraki break point e kadar sür.
n (next kısaltması): Birsonraki satırı sür
s (step kısaltması): n ile aynıdır fakat fonksiyon geldiğinde fonksiyonu tek satır olarak almaz fonksiyona gidip onu satır satır çalıştırır
Diğer seçeekler
l – list
p – print
c – continue
s – step
ENTER: bir önceki emri tekrar et
l command: Kaynak kodu görmek için kullanılır
bt: backtrack – Print backtrace of all stack frames, or innermost COUNT frames.
help – help TOPICNAME.
quit – çıkış
kaynak
Ağustos 17, 2011 § § Kalıcı bağlantı
#!/usr/bin/env bash
for x in one two three four
do
echo number $x
done
output:
number one
number two
number three
number four
#!/usr/bin/env bash
for myfile in /etc/r*
do
if [ -d "$myfile" ]
then
echo "$myfile (dir)"
else
echo "$myfile"
fi
done
output:
/etc/rc.d (dir)
/etc/resolv.conf
/etc/resolv.conf~
/etc/rpc
for x in /etc/r??? /var/lo* /home/drobbins/mystuff/* /tmp/${MYPATH}/*
do
cp $x /mnt/mydir
done
for x in ../* mystuff/*
do
echo $x is a silly file
done
for x in /var/log/*
do
echo `basename $x` is a file living in /var/log
done
#!/usr/bin/env bash
for thing in "$@"
do
echo you typed ${thing}.
done
output:
$ allargs hello there you silly
you typed hello.
you typed there.
you typed you.
you typed silly.
Ağustos 17, 2011 § § Kalıcı bağlantı
tar dosyasının içeriğini görmek:
tarview() {
echo -n "Displaying contents of $1 "
if [ ${1##*.} = tar ]
then
echo "(uncompressed tar)"
tar tvf $1
elif [ ${1##*.} = gz ]
then
echo "(gzip-compressed tar)"
tar tzvf $1
elif [ ${1##*.} = bz2 ]
then
echo "(bzip2-compressed tar)"
cat $1 | bzip2 -d | tar tvf -
fi
}
$ tarview shorten.tar.gz
Displaying contents of shorten.tar.gz (gzip-compressed tar)
drwxr-xr-x ajr/abbot 0 1999-02-27 16:17 shorten-2.3a/
-rw-r--r-- ajr/abbot 1143 1997-09-04 04:06 shorten-2.3a/Makefile
-rw-r--r-- ajr/abbot 1199 1996-02-04 12:24 shorten-2.3a/INSTALL
-rw-r--r-- ajr/abbot 839 1996-05-29 00:19 shorten-2.3a/LICENSE
Ağustos 17, 2011 § § Kalıcı bağlantı
find -name "MyCProgram.c"
./backup/MyCProgram.c
./MyCProgram.c
Büyük-küçük harf duyarlılığı olmaksızın aramak
find -iname "MyCProgram.c"
./mycprogram.c
./backup/mycprogram.c
./backup/MyCProgram.c
./MyCProgram.c
Klasör derinliğini belirleyerek dosya aramak
find / -name passwd
./usr/share/doc/nss_ldap-253/pam.d/passwd
./usr/bin/passwd
./etc/pam.d/passwd
./etc/passwd
find -maxdepth 2 -name passwd
./etc/passwd
find / -maxdepth 3 -name passwd
./usr/bin/passwd
./etc/pam.d/passwd
./etc/passwd
find -mindepth 3 -maxdepth 5 -name passwd
./usr/bin/passwd
./etc/pam.d/passwd
Bulunan dosyalar için işlem yapılmak istenirse “{}” dosya ismi yerine kullanılabilir.
find -iname "MyCProgram.c" -exec md5sum {} \;
d41d8cd98f00b204e9800998ecf8427e ./mycprogram.c
d41d8cd98f00b204e9800998ecf8427e ./backup/mycprogram.c
d41d8cd98f00b204e9800998ecf8427e ./backup/MyCProgram.c
d41d8cd98f00b204e9800998ecf8427e ./MyCProgram.c
Kriterlerle uyuşmayan dosyaları bulmak.
(maxdebth 1 olduğu için sadece bulunduğu klasöre bakar)
find -maxdepth 1 -not -iname "MyCProgram.c"
.
./MybashProgram.sh
./create_sample_files.sh
./backup
./Program.c
inode numarasına göre dosya bulmak
find -inum 16187430 -exec mv {} new-test-file-name \;
ls -i1 *test*
16187430 new-test-file-name
16187429 test-file-name
İzinlerine göre dosya aramak
Diğer izinlerine bakmaksızın grup tarafından okunabilen dosyaları bulmak
find . -perm -g=r -type f -exec ls -l {} \;
-rw-r--r-- 1 root root 0 2009-02-19 20:30 ./everybody_read
-rwxrwxrwx 1 root root 0 2009-02-19 20:31 ./all_for_all
----r----- 1 root root 0 2009-02-19 20:27 ./others_can_only_read
-rw-r----- 1 root root 0 2009-02-19 20:27 ./others_can_also_read
Sadece grupun okuma iznine sahip olduğu dosyaları bulmak
find . -perm g=r -type f -exec ls -l {} \;
----r----- 1 root root 0 2009-02-19 20:27 ./others_can_only_read
İzinleri octal olarak verilip dosyaların bulunması
find . -perm 040 -type f -exec ls -l {} \;
----r----- 1 root root 0 2009-02-19 20:27 ./others_can_only_read
0 bytelık lock vs dosyalarını tesbit etmek
find ~ -empty
Gizli olmayan 0 byte dosyalarını bulmak
find . -maxdepth 1 -empty -not -name ".*"
Boyutu en büyük 5 dosyayı bulmak
find . -type f -exec ls -s {} \; | sort -n -r | head -5
Yüre göre dosya aramak
Soket dosyalarını bulmak
find . -type s
Dizinleri bulmak
find . -type d
Normal dosyaları bulmak
find . -type f
Gizli dosyaları bulmak
find . -type f -name ".*"
Gizli dizinleri bulmak
find -type d -name ".*"
Boyutlarına göre dosya aramak
Belirli boyuttan büyük dosyaları bulmak
find ~ -size +100M
Belirli boyuttan küçük dosyaları bulmak
find ~ -size -100M
Belirli boyuttaki dosyaları bulmak
find ~ -size 100M
Dosya içeriklerini araştırmak
find . -type f -exec grep '4583_20080820115047.mp4' /dev/null {} \;
./databasemp4isim.txt: 4583_20080820115047.mp4
./isimmp4.txt:4583_20080820115047.mp4
Dosya boyutlarının bulmak
find . -size +100M -type f -print0 | xargs -0 ls -lahS
Regular expression kullanımı
find . -name \txt -exec tail -1 {} \;
Modifikasyonu belirli aralıkda olan dosyaları bulmak
find . -type f -newermt "2010-01-01" ! -newermt "2010-06-01"
Ağustos 16, 2011 § § Kalıcı bağlantı
Ekran görüntüsü yakalamak için
ffmpeg -f x11grab -s 1280x1024 -i 0:0 /home/egitim/desktop.avi
veya
ffmpeg -video_size 1920x1080 -framerate 25 -f x11grab -i :0 -f mpegts udp://172.16.101.131:5555
ekranı nc ile ağa basıp yakalamak
ffmpeg -video_size 1920x1080 -framerate 25 -f x11grab -i :0 -f mpegts -| nc -l -p 9000
nc localhost 9000 > 1.mp4
Ağustos 16, 2011 § § Kalıcı bağlantı
Bir videoyu mpeg4e dönüştürmek
ffmpeg -i 4126_20071228004214.mp4 -f avi -vcodec mpeg4 -b 637k -acodec mp3 -ab 32k ../sonuc/32k_4126_20071228004214.mp4
libx264 ile multithread kullanarak (ffmpeg static build ile: http://dl.dropboxusercontent.com/u/24633983/ffmpeg/index.html ; http://dl.dropbox.com/u/24633983/ffmpeg/builds/ffmpeg-linux64-20130508.tar.bz2)
../ffmpeg -i "shuttle-flip.mp4" -codec:v libx264 -quality good -cpu-used 0 -b:v 4000k -profile:v baseline -level 30 -y -maxrate 4000k -y -bufsize 2000k -vf scale=-1:1080 -threads 2 -codec:a libvo_aacenc -b:a 128k "fullhd.mp4"
webm için
../ffmpeg -i "shuttle-flip.mp4" -codec:v libvpx -quality good -cpu-used 0 -b:v 2000k -qmin 10 -qmax 42 -maxrate 2000k -y -bufsize 2000k -vf scale=-1:720 -threads 2 -codec:a libvorbis -b:a 128k "webm.webm"
Not:-preset değerinin slow olması sıkıştırmanın oldukça iyi yapılacağı anlamına gelmektedir.
Yapılan denemede, slow ile oluşan dosya 570M iken ultrafast ile oluşan dosyanın 1.1G olduğu gözlemlenmiştir. Fakat slowda encoding süresi 59m58.255s iken ultrafastde encoding 9m6.937s zamanda tamamlanmıştır. -preset degeri ultrafast,veryfast,faster,fast,medium, slow,slower,veryslow,placebo olabilir.
Not: Daha detaylı bilhi için “x264 –help” kullanılabilir.
Not: -crf değeri ne kadar kayıp verilebileceğini belirler.
Verilen değer küçüldükçe kayıp azalır. Makul değerler 18-28 arasıdır. 0 değeri kayıpsızdır.
ffmpeg -i input -acodec copy -vcodec libx264 -preset slow -crf 22 output.mp4
Animasyon için tune edilmiş bir örnek:
ffmpeg -i input -acodec copy -vcodec libx264 -preset medium -tune animation
-profile baseline -level 3.0 -crf 20 output.mp4
Değişik level kullanımları mümkündür.
Örneğin:
iPhone, iPod 5.5G
--level 30 --profile baseline --vbv-bufsize 10000 --vbv-maxrate 10000
iPod
--level 1.3 --no-cabac --vbv-bufsize 768 --vbv-maxrate 768
PSP
--level 2.1 --vbv-bufsize 4000 --vbv-maxrate 4000
Zune
--level 30 --no-cabac --vbv-bufsize 10000 --vbv-maxrate 10000
AppleTV
--level 3.1 --no-cabac --vbv-bufsize 14000 --vbv-maxrate 14000
PS3-Xbox360
--level 4.1 --vbv-bufsize 62500 --vbv-maxrate 62500
Dosyanın bitrate verilerek belirli bir boyutta sonuçlanmasını sağlamak için 2 fazlı dönüşüm yapılabilir. Örneğin
Not:bitratei sabitlemek yerine crf kullanmak tavsiye edilir. Zira farklı bitratelerde aynı kalitede görüntü elde edilebilir. Kaynak
ffmpeg -i input -pass 1 -vcodec libx264 -preset fast -b 512k -f mp4 -an -y /dev/null \
&& ffmpeg -i input -pass 2 -vcodec libx264 -preset fast -b 512k -acodec libfaac \
-ab 128k -ac 2 output.mp4
Kayıpsız H264 oluşturmak için:
ffmpeg -i input -vcodec libx264 -preset ultrafast -crf 0 -acodec copy output.mkv
Not: Kayıpsız video oluştururken -preset değeriyle yapılan denemelerde
-preset ultrafast iken
oluşan dosya 8.5G (9108193825) ve gerekli zaman 23m54.441s
-preset medium iken
oluşan dosya 6.6G (7070383360) ve gerekli zaman 99m18.887s
-preset placebo iken
oluşan dosya 6.6G (7036744106) ve gerekli zaman 433m10.011s
ffmpeg hakkına iyi bir kaynak
FFMpeg in static buildi. Herhangi bir bağımlılığı yoktur.
Static build referansı ve yeni versiyonları…
Ağustos 16, 2011 § § Kalıcı bağlantı
Birbirinin aynı olan dosyaları “fdupes” kullanarak tebit eebiliriz.
/var/www klasöründe arama yapmak için
fdupes /var/www
/var/www klasöründe recursive arama yapmak için
fdupes -r /var/www
/var/www klasöründe recursive arama yapıp tekrarları silmek için soru sorması içim
fdupes -rd /var/www
Temmuz 25, 2011 § § Kalıcı bağlantı
Bunu başarmak için:
Öncelikle bc_yapilacakis isimli dosyayi olusturalim.
Dosyanın içeriği
d = a / b
print a," divided by ",b," with scale ",scale," is ",d
quit
Şimdi bc_userparametre.sh isimli shell dosyasını oluşturalım.
Dosyanın içeriği
# This is a shell script to request two numbers
# and pass those numbers to the bc interpreter
# for doing a calculation
echo -n "Enter numerator (top number) "
read var1
echo -n "Enter denominator (bottom number) "
read var2
echo -n "Enter scope (number of decimal places) "
read var3
cat <<eee > bc_parametreler
a = $var1
b = $var2
scale = $var3
eee
bc -q bc_parametreler bc_yapilacakis
rm -f bc_parametreler
echo ""
Görüldüğü gibi bc_userparametre.sh dosyasi bc_parametreler isimli dosyayi oluşturuyor.
bc ise quite modda önce bc_parametreler sonra bc_yapilacakis dosyasını okuyarak işini tamamlıyor.
Temmuz 21, 2011 § § Kalıcı bağlantı
iostat kullanımı:
$ iostat
Linux 2.6.32-100.28.5.el6.x86_64 (dev-db) 07/09/2011
avg-cpu: %user %nice %system %iowait %steal %idle
5.68 0.00 0.52 2.03 0.00 91.76
Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn
sda 194.72 1096.66 1598.70 2719068704 3963827344
sda1 178.20 773.45 1329.09 1917686794 3295354888
sda2 16.51 323.19 269.61 801326686 668472456
sdb 371.31 945.97 1073.33 2345452365 2661206408
sdb1 371.31 945.95 1073.33 2345396901 2661206408
sdc 408.03 207.05 972.42 513364213 2411023092
sdc1 408.03 207.03 972.42 513308749 2411023092
Sadece CPU kullanımını görmek
$ iostat -c
Linux 2.6.32-100.28.5.el6.x86_64 (dev-db) 07/09/2011
avg-cpu: %user %nice %system %iowait %steal %idle
5.68 0.00 0.52 2.03 0.00 91.76
Sadece disk I/O’unu görmek
$ iostat -d
Linux 2.6.32-100.28.5.el6.x86_64 (dev-db) 07/09/2011
Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn
sda 194.71 1096.61 1598.63 2719068720 3963827704
sda1 178.20 773.41 1329.03 1917686810 3295355248
sda2 16.51 323.18 269.60 801326686 668472456
sdb 371.29 945.93 1073.28 2345452365 2661209192
sdb1 371.29 945.91 1073.28 2345396901 2661209192
sdc 408.01 207.04 972.38 513364213 2411024484
sdc1 408.01 207.02 972.38 513308749 2411024484
Network devicelarını ve NFS partitionlarının bilgilerini görmek:
$ iostat -n
Linux 2.6.32-100.28.5.el6.x86_64 (dev-db) 07/09/2011
avg-cpu: %user %nice %sys %iowait %idle
4.33 0.01 1.16 0.31 94.19
Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn
sda 2.83 0.35 5.39 29817402 457360056
sda1 3.32 50.18 4.57 4259963994 387641400
sda2 0.20 0.76 0.82 64685128 69718576
sdb 6.59 15.53 42.98 1318931178 3649084113
sdb1 11.80 15.53 42.98 1318713382 3649012985
Device: rBlk_nor/s wBlk_nor/s rBlk_dir/s wBlk_dir/s rBlk_svr/s wBlk_svr/s
192.168.1.4:/home/data 90.67 0.00 0.00 0.00 5.33 0.00
192.168.1.4:/backup 8.74 0.00 0.00 0.00 8.74 0.00
192.168.1.8:/media 0.02 0.00 0.00 0.00 0.01 0.00
MB cinsinden istatistikleri görmek
$ iostat -m
Linux 2.6.32-100.28.5.el6.x86_64 (dev-db) 07/09/2011
avg-cpu: %user %nice %system %iowait %steal %idle
5.68 0.00 0.52 2.03 0.00 91.76
Device: tps MB_read/s MB_wrtn/s MB_read MB_wrtn
sda 194.70 0.54 0.78 1327670 1935463
sda1 178.19 0.38 0.65 936370 1609060
sda2 16.51 0.16 0.13 391272 326402
sdb 371.27 0.46 0.52 1145240 1299425
sdb1 371.27 0.46 0.52 1145213 1299425
sdc 407.99 0.10 0.47 250666 1177259
sdc1 407.99 0.10 0.47 250639 1177259
Belirli bir device ın istatistiklerini görmek
$ iostat -p sda
Linux 2.6.32-100.28.5.el6.x86_64 (dev-db) 07/09/2011
avg-cpu: %user %nice %system %iowait %steal %idle
5.68 0.00 0.52 2.03 0.00 91.76
Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn
sda 194.69 1096.51 1598.48 2719069928 3963829584
sda2 336.38 27.17 54.00 67365064 133905080
sda1 821.89 0.69 243.53 1720833 603892838
Genişletilmiş istatistikler için
$ iostat -x
Linux 2.6.32-100.28.5.el6.x86_64 (dev-db) 07/09/2011
avg-cpu: %user %nice %system %iowait %steal %idle
5.68 0.00 0.52 2.03 0.00 91.76
Device: rrqm/s wrqm/s r/s w/s rsec/s wsec/s avgrq-sz avgqu-sz await svctm %util
sda 27.86 63.53 61.77 132.91 1096.46 1598.40 13.84 0.21 1.06 2.28 44.45
sda1 0.69 33.22 48.54 129.63 773.30 1328.84 11.80 1.39 7.82 2.28 40.57
sda2 27.16 30.32 13.23 3.28 323.13 269.56 35.90 0.55 32.96 3.44 5.68
sdb 39.15 215.16 202.20 169.04 945.80 1073.13 5.44 1.05 2.78 1.64 60.91
sdb1 39.15 215.16 202.20 169.04 945.77 1073.13 5.44 1.05 2.78 1.64 60.91
sdc 8.90 3.63 356.56 51.40 207.01 972.24 2.89 1.04 2.56 1.55 63.30
sdc1 8.90 3.63 356.55 51.40 206.99 972.24 2.89 1.04 2.56 1.55 63.30
Belirli bir partition için istatistikler
$ iostat -x sda1
Linux 2.6.32-100.28.5.el6.x86_64 (dev-db) 07/09/2011
avg-cpu: %user %nice %system %iowait %steal %idle
5.68 0.00 0.52 2.03 0.00 91.76
Device: rrqm/s wrqm/s r/s w/s rsec/s wsec/s avgrq-sz avgqu-sz await svctm %util
sda1 0.69 33.21 48.54 129.62 773.23 1328.76 11.80 1.39 7.82 2.28 40.56
Belirli aralıklarla (2 saniyede bir) iostat çıktısnı güncellemek
$ iostat 2
Linux 2.6.32-100.28.5.el6.x86_64 (dev-db) 07/09/2011
avg-cpu: %user %nice %system %iowait %steal %idle
5.68 0.00 0.52 2.03 0.00 91.76
Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn
sda 194.67 1096.39 1598.33 2719070584 3963891256
sda1 178.16 773.26 1328.79 1917688482 3295418672
sda2 16.51 323.11 269.54 801326878 668472584
sdb 371.22 945.74 1073.08 2345454041 2661251200
sdb1 371.22 945.72 1073.08 2345398577 2661251200
sdc 407.93 207.00 972.19 513366813 2411036564
sdc1 407.93 206.98 972.19 513311349 2411036564
..
2 saniyede birr 3 kere çalıştırmak
iostat 2 3
mpstat kullanmak
mpstat ile CPU kullanım istatistikleri toplanabilir
$ mpstat
Linux 2.6.32-100.28.5.el6.x86_64 (dev-db) 07/09/2011
10:25:32 PM CPU %user %nice %sys %iowait %irq %soft %steal %idle intr/s
10:25:32 PM all 5.68 0.00 0.49 2.03 0.01 0.02 0.00 91.77
Her core için bilgi toplamak
$ mpstat -P ALL
Linux 2.6.32-100.28.5.el6.x86_64 (dev-db) 07/09/2011 _x86_64_ (4 CPU)
10:28:04 PM CPU %usr %nice %sys %iowait %irq %soft %steal %guest %idle
10:28:04 PM all 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 99.99
10:28:04 PM 0 0.01 0.00 0.01 0.01 0.00 0.00 0.00 0.00 99.98
10:28:04 PM 1 0.00 0.00 0.01 0.00 0.00 0.00 0.00 0.00 99.98
10:28:04 PM 2 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00
10:28:04 PM 3 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00