Ekim 25, 2011 § § Kalıcı bağlantı
Örnekler:
$ MYDIR=`dirname /usr/local/share/doc/foo/foo.txt`
$ echo $MYDIR
/usr/local/share/doc/foo
veya
$ MYDIR=$(dirname /usr/local/share/doc/foo/foo.txt)
$ echo $MYDIR
/usr/local/share/doc/foo
veya
MYFILES=$(ls /etc | grep pa)
bash-2.03$ echo $MYFILES
pam.d passwd
Ekim 25, 2011 § § Kalıcı bağlantı
2 dosyayı birleştirebilmek için ortak bir alanın olması gerekmektedir.
Ortak alan Yoksa yaratalım:
file1:
Jack Wallen
Jessica Wallen
Johnny Wallen
Jeri Wallen
file2:
123-45-6789
234-56-7890
345-67-8901
456-78-9012
$nl file1 > fileA ; nl file2 > fileB
$join fileA fileB
Başka bir örnek
$ cat m1.txt
Jincy 500
Amit 300
Saurab 100
Jobi 400
Kumar 200
$ cat m2.txt
Amit Monitoring
Jincy Marketing
Jobi Accounts
Kumar Sales
Saurab Maintenence
$ sort m1.txt | join - m2.txt
Amit 300 Monitoring
Jincy 500 Marketing
Jobi 400 Accounts
Kumar 200 Sales
Saurab 100 Maintenence
$
Ekim 25, 2011 § § Kalıcı bağlantı
sda için her saniyede çalışır. Toplam 3 çıktı ver:
iostat -p sda 1 3
Daha detaylı bilgi için
iostat -x
Ekim 24, 2011 § § Kalıcı bağlantı
Grep ile OR yapmak
grep 'pattern1\|pattern2' filename
veya
grep -E 'pattern1|pattern2' filename
Örnek:
$ grep 'Tech\|Sales' employee.txt
100 Thomas Manager Sales $5,000
200 Jason Developer Technology $5,500
300 Raj Sysadmin Technology $7,000
500 Randy Manager Sales $6,000
Grep ile AND yapmak
Önce pattern1 sonra pattern2 gelecekse:
grep -E 'pattern1.*pattern2' filename
Pattern1 ve 2 herhangi bir sırada gelecekse
grep -E 'pattern1.*pattern2|pattern2.*pattern1' filename
veya
grep -E 'pattern1' filename | grep -E 'pattern2'
Grep ile NOT yapmak
grep -v 'pattern1' filename
Ağustos 25, 2011 § § Kalıcı bağlantı
1-xterm penceresi içinde top koşmak
ve xterm penceresi içinde echo ile mesaj göndermek
xterm -e "top -c; sleep 10"
xterm -e "watch echo 'Bu bir mesajdır'"
SSH ile birlikte kullanmak için
ssh -Y fatih@localhost 'export DISPLAY=:0 && xterm -e watch echo "Bu bir mesajdır"'
2-notify-send yazılı ile
notify-send "welcome to Linux message box"
SSh ile birlikte kullanımı
ssh -Y fatih@localhost 'export DISPLAY=:0 && notify-send "welcome to Linux message box"'
3-zenity kullanmak
zenity --info --title='Message' --text='Linux redhat '
SSH ile kullanmak
ssh -Y fatih@localhost 'export DISPLAY=:0 && zenity --info --title='Message' -text='Linux redhat '"
4-kdialog kullanmak
kdialog --title "New Mail Has Arrived" --passivepopup "it will terminate withing 5 minutes" 5
SSH ile kullanmak
ssh -Y fatih@localhost 'export DISPLAY=:0 && kdialog --title "New Mail Has Arrived" --passivepopup "it will terminate withing 5 minutes" 5'
5-En güzel yol:
$ who
jdoe pts/0 2014-03-09 16:19 (10.3.2.98)
mary pts/1 2014-03-09 14:10 (10.3.2.123
$ echo "Bu sesaj jdoeya" > /dev/pts/0
$ echo "Bu da sevgili Marrye" > /dev/pts/1
SSh ile yapılması
$ ssh root@hedef 'who'
$ ssh root@hedef 'echo "Bu da sevgili Marrye" > /dev/pts/1'
Ağustos 22, 2011 § § Kalıcı bağlantı
Konsoldan ses ayarı yapabilmek icin “alsamixer” kullanılabilir.
Bunun için
sudo apt-get install alsa alsa-tools
sudo adduser yourusername audio
alsamixer
Ağustos 19, 2011 § § Kalıcı bağlantı
netstat -lantp | grep ESTABLISHED |awk '{print $5}' | awk -F: '{print $1}' | sort -u
Bilgisayara bağlanmış kullanıcının bütün processlerini öldürmek(login shell dahil)
pkill -KILL -u username
Ağustos 18, 2011 § § 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
Ağustos 17, 2011 § § 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"
Ağustos 17, 2011 § § 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.