28 Nisan 2019 Pazar

rfkill komutu

Giriş
Açıklaması şöyle.
rfkill is a small userspace tool to query the state of the rfkill switches, buttons and subsystem interfaces. Some devices come with a hard switch that lets you kill different types of RF radios: 802.11 / Bluetooth / NFC / UWB / WAN / WIMAX / FM. Some times these buttons may kill more than one RF type. The Linux kernel rfkill subsystem exposes these hardware buttons and lets userspace query its status and set its status through a /dev/rfkill. Given that at times some RF devices do not have hardware rfkill buttons rfkill the Linux kernel also exposes software rfkill capabilities that allows userspace to mimic a hardware rfkill event and turn on or off RF.
list seçeneği
Şöyle yaparız
rfkill list
Cihaz tipi olarak Wireless LAN,Bluetooth,WiMAX görebiliriz.
Örnek
Çıktı olarak şuna benzer bir çıktı alırız.
0: phy0: Wireless LAN
  Soft blocked: no
  Hard blocked: yes
1: i2400m-usb:1-1.6:1.0: WiMAX
  Soft blocked: yes
  Hard blocked: no
Örnek
Şuna benzer bir çıktı alırız.
0: ideapad_wlan: Wireless LAN
  Soft blocked: no
  Hard blocked: no
1: ideapad_bluetooth: Bluetooth
  Soft blocked: no
  Hard blocked: no
2: hci0: Bluetooth
  Soft blocked: no
  Hard blocked: no
unblock seçeneği
Şöyle yaparız
rfkill unblock all
Şöyle yaparız
rfkill unblock 0

4 Nisan 2019 Perşembe

mv komutu - Dosya taşır

Giriş
move anlamına gelir. copy komutu taşıma yerine kopyalama için kullanılabilir.

Söz dizimi şöyledir.
mv filedestination_dir
Açıklaması şöyle.
mv is a standard utility to move one or more files to a given target. It can be used to rename a file, if there's only one file to move. If there are several, mv only works if the target is directory, and moves the files there.

So mv foo bar will either move the file foo to the directory bar (if it exists), or rename foo to bar (if bar doesn't exist or isn't a directory). mv foo1 foo2 bar will just move both files to directory bar, or complain if bar isn't a directory.

mv will call the rename() C library function to move the files, and if that doesn't work (they're being moved to another filesystem), it will copy the files and remove the originals.
Neden mv Komutunda -r (recursive) seçeneği Yok?
Bir soru şöyle. Yani mv komutu tek bir şeyi taşır. Dolayısıyla recursive olmasına gerek yok
Q : Why does 'mv' not need '-r' to work with directories, but 'rm' and 'cp' do?
A : 
 rm has to recurse into the directory ...
 cp has to recurse into the directory ...
 mv just has to do a single call 
Örnek - rename
.txt dosyalarını .txt.old olarak yeniden ismlendirmek için şöyle yaparız.
mv dir1/dir2/dir3/file.{txt,txt.old}
-- seçeneği
Bu özel bir seçenek. Şu anlama geliyor. Eğer dosya isimlerinde de "-" karakteri varsa bu isimler seçenek gibi algılanabiliyor. "--" seçeneğiyle artık yeni seçeneklerin kabul edilmemesi sağlanıyor. Açıklaması şöyle
Most command-line utilities have a provision to separate options from arguments.

That prevents a multitude of problems with "special" file names that look like options.

The most common separator indication the end of the options is two hyphens -- or -- which is also supported by mv.
Örnek
Soru şöyle
Here is my problem :
i have a file with -r in the name :
-r.jpg

when i tried to do a :
mv *.jpg old/

i have a :
mv: invalid option -- 'r'
Cevabı şöyle
mv -- *.jpg old/
-t seçeneği
target directory anlamına gelir. Şeklen şöyledir.
mv -t destination_dir  file
Örnek
Tüm dosyaları farklı bir dizine taşımak için şöyle yaparız
printf '%s\0' files/* | xargs -0 mv -t new_files_dir
Örnek
mp3 dosyalarını bir üst dizine taşımak için şöyle yaparız.
find . -path "*/flac/*" -name '*.mp3' -execdir mv -t ../ {} +

3 Nisan 2019 Çarşamba

fnotifystat komutu

-i seçeneği
Şöyle yaparız.
$ sudo fnotifystat -i /tmp

2 Nisan 2019 Salı

bash kodlama - while döngüsü

Giriş
Açıklaması şöyle. [ ...] test işlemi sadece değişkenler için kullanılır.
[ .. ] is not part of shell syntax like if statements. It is not equivalent to parentheses in C-like languages, if (foo) { bar; }, and should not be wrapped around commands to test.
[ is just regular command, like whoami or grep, but with a funny name (see ls -l /bin/[). It's a shorthand for test.
If you want to check the exit status of a certain command, use that command directly.
If you want to check the output of a command, use "$(..)" to get its output, and then use test or [/[[ to do a string comparison:
Örnek 
Değişken kullanmak için şöyle yaparız.
#!/bin/bash
COUNTER=0

while [ "$COUNTER" -lt 10 ] && ps aux | grep -q "[r]elayevent.sh"   ; do

  sleep 3

  let COUNTER+=1

done
Örnek
Şu kod, ps alt komutu [...] içinde kullandığı için hata verir.
COUNTER=0
while [ ps aux | grep "[r]elayevent.sh" ] && [ "$COUNTER" -lt 10 ]; do
    sleep 3
    let COUNTER+=1
done
Örnek
Aynı değişkeni iki farklı değerler karşılaştırmak için şöyle yaparız
while [  "$choice" != "yes" ] && [ "$choice" != "no" ]
Örnek
Sonsuz döngü kurmak için şöyle yaparız.
#!/bin/bash

while true; do
  echo "something" >> bash.txt
done
Örnek
Sonsuz döngü kurmak için şöyle yaparız. Bu sefer true yerine built-in command olan ":" kullanılıyor.
while :
do
  something
done
Şöyle yaparız.
while :
do
  sleep 10
done
Örnek
Komutun exit kodunu kullanarak dosyanın tüm satırlarını okumak için şöyle yaparız.
#!/bin/bash
while IFS='' read -r line || [[ -n "$line" ]]; do
  echo "Text read from file: $line"
done < "$1"
Aynı satırları silmek için buradaki kod kullanılabilir.
Örnek
Break ile çıkmak için şöyle yaparız.
#!/bin/bash

while true
do
    echo "Please input anything here: "
    read INPUT

    if [ `expr $INPUT % 5` -eq 0 ]; then
        echo "you entered wrong"
        break
    else
        echo "you entered right"
    fi
done
Örnek
Script'e verilen parametreleri parse etmek için şöyle yaparız.
while getopts ":d:f:p:e:" o; do
  case "${o}" in
        d)
            SDOMAIN=${OPTARG}
            ;;
        f)
            FROM=${OPTARG}
            ;;
        p)
            PAGER=${OPTARG}
            ;; 
        e)
            DESTEXT=${OPTARG}
            ;;                       
        *)
            show_usage
            ;;          
    esac
done