Aria2 ile dosya download etmek

Ağustos 18, 2011 § Yorum yok § Kalıcı bağlantı

Aria2 ile çoklu bağlantili, max bandwith ile dosya downloadu mümkün.
Geliştiricileri süper iş çıkarmış.
Kullanımı:

aria2c "http://host/file.zip"

2 kaynaktan aynı dosyanın indirilmesi

aria2c "http://host/file.zip" "http://mirror/file.zip"

HTTP ve FTP nin beraber kullanımı

aria2c "http://host1/file.zip" "ftp://host2/file.zip"

Bir dosyadaki fileların download edilmesi

aria2c -ifiles.txt -j2

Sayı sequanci ile download

aria2c -Z -P "http://host/image[000-100].png"

Ayrıntılı bilgi

Never say no to Panda!

Ağustos 17, 2011 § Yorum yok § Kalıcı bağlantı

Dosya isimlerini değiştirmek

Ağustos 17, 2011 § Yorum yok § Kalıcı bağlantı

    echo "bizim ilk filemiz:"${filename:4:19}
    #echo ${filename[0]:4}".birles."$i".mp4"
 
    avimerge -i 32*mp4 -o ${filename:4:19}.birles.$i.mp4
    echo "avimerge bitti basa don"

if kullanımı

Ağustos 17, 2011 § Yorum yok § Kalıcı bağlantı

Dosya için varlık kontrolü

if [ -a tmp.tmp ]; then
   rm -f tmp.tmp # Make sure we're not bothered by an old temporary file
fi

Dizin için varlık kontrolü

if [ -d ~/.kde ]; then
    echo "You seem to be a kde user."
fi

Dosyanın regular dosya olarak varlığının kontrolü icin -f regularfile
Regular dosyalar blok veya karakter special dosyaları(/dev dizinindeki device tanımlayan kernel dosyaları) değildir.

if [ -f ~/.bashrc ]; then
    source ~/.bashrc
fi

Dosyayı inceleyen kullanıcı dosyanın sahibi mi?

if [ -O file ]; then
    chmod 600 file # Makes the file private, which is a bad idea if you don't own it
fi

Dosya okunabiliyor mu?(izinleri var mı)

if [-r file ]; then
    content=$(cat file) # Set $content to the content of the file
fi

Dosya 0 bytedan farklı okunabilen bir dosya mı?

if [ -s logfile ]; then
  gzip logfile    # Backup the old logfile
  touch logfile # before creating a fresh one.
fi

Dosya yazılabilir mi?

if [ -w /dev/hda ]; then
    grub-install /dev/hda
fi

Dosya çalıştırılabilir mi?(Dizinler için içeriği listelenebilir mi?)

if [ -x /root ]; then
    echo "You can view the contents of the /root directory."
fi

Dosyaların değiştirilme tarihini karşılaştırmak:
(olderfile yokken de True döner)

if [ newerfile -nt olderfile ]; then
    echo "story.txt1 is newer than story.txt; I suggest continuing with the former."
fi

veya

if [ /mnt/remote/remotefile -ot localfile ]; then
    cp -f localfile /mnt/remote/remotefile # Make sure the remote location has the newest version of the file, too
fi

Dosyaların inodelarını karşılaştırmak.

if [ /dev/cdrom -ef /dev/dvd ]; then
    echo "Your primary cd drive appears to read dvd's, too."
fi

String karşılaştırmak:

if [ "$1" == "moo" ]; then
    echo $cow # Ever tried executing 'apt-get moo'?
fi
if [ "$userinput" != "$password" ]; then
    echo "Access denied! Wrong password!"
    exit 1 # Stops script execution right here
fi

Stringin uzunluğu 0’dan büyük mü?

if [ -n "$userinput" ]; then
    userinput=parse($userinput) # Only parse if the user actually gave some input.
fi

String boş string mi?

if [ -z $uninitializedvar ]; then
    uninitializedvar="initialized" # -z returns true on an uninitialized variable, so we initialize it here.
fi

String regex’e uygun mu?

if [[ "$email" =~ "\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}\b" ]]; then
    echo "\$email contains a valid e-mail address."
fi

Sayıları karşılaştırmak:

if [ $? -eq 0 ]; then # $? returns the exit status of the previous command
    echo "Previous command ran succesfully."
fi
if [ $(ps -p $pid -o ni=) -ne $(nice) ]; then
    echo "Process $pid is running with a non-default nice value"
fi
 
if [ $num -lt 0 ]; then
    echo "Negative numbers not allowed; exiting..."
    exit 1
fi
[ NUM1 -ne NUM2 ]
NUM1 is Not Equal to NUM2.
[ NUM1 -gt NUM2 ]
NUM1 is Greater Than NUM2.
[ NUM1 -ge NUM2 ]
NUM1 is Greater than or Equal to NUM2.
[ NUM1 -lt NUM2 ]
NUM1 is Less Than NUM2.
[ NUM1 -le NUM2 ]
NUM1 is Less than or Equal to NUM2.

Diğer kullanım örnekleri

if (( $? == 0 )); then # $? returns the exit status of the previous command
    echo "Previous command ran succesfully."
fi
 
if (( $(ps -p $pid -o ni=) != $(nice) )); then
    echo "Process $pid is running with a non-default nice value"
fi
 
if (( $num < 0 )); then
    echo "Negative numbers not allowed; exiting..."
    exit 1
fi
(( NUM1 != NUM2 )) NUM1 is not equal to NUM2.
(( NUM1 > NUM2 )) NUM1 is greater than NUM2.
(( NUM1 >= NUM2 )) NUM1 is greater than or equal to NUM2.
(( NUM1 < NUM2 )) NUM1 is less than NUM2.
(( NUM1 <= NUM2 )) NUM1 is less than or equal to NUM2.

history kullanımı

Ağustos 17, 2011 § Yorum yok § 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

gdb c debugger kullanımı

Ağustos 17, 2011 § 1 yorum § 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

for döngüsü örnekleri

Ağustos 17, 2011 § Yorum yok § 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.

tar kullanımı

Ağustos 17, 2011 § Yorum yok § 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

find ile dosya aramak

Ağustos 17, 2011 § Yorum yok § 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"

ffmpeg ile ekran görüntüsü yakalamak

Ağustos 16, 2011 § Yorum yok § 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