16 Ağustos 2020 Pazar

do-release-upgrade komutu

Giriş
Ubuntu sürümünü yükseltmek için kullanılır.

Örnek
Şöyle yaparız
do-release-upgrade
Checking for a new Ubuntu release
There is no development version of an LTS available.

10 Ağustos 2020 Pazartesi

add-apt-repository komutu - Debian Sistemlerde Farklı Paket Kaynağı İçindir

Ön Bilgi
3 çeşit temel Linux sistemi var.
1. Debian : Debian sistemler apt-get komutunu kullanır. Bu komut altta dpkg komutunu kullanır
2. SUSE : SUSE sistemler zypper komutunu kullanır. Bu komut altta rpm komutunu kullanır
3. Fedora : Fedora sistemler yum komutunu kullanır. Bu komut altta rpm komutunu kullanır

Debian Sistemler
Açıklaması şöyle. Debian Sistemler repository bilgilerini /etc/apt/sources.list dosyasında saklarlar.
Package manager conf file:
Each PM has its own conf file associated with it which contains the location of all repos i.e repositories that contain the packages. The conf file contains the location of all official repos . Packages are also present on third parties repos so you can edit the location of these packages in the conf file. But you have to take care of the security issue. The default conf file present on the ubuntu system is “/etc/apt/sources”. So using this conf file PM knows where exactly the packages are present.
/etc/apt/sources.list dosyası şöyledir
deb http://deb.debian.org/debian jessie main
...
Bir başka örnek şöyle
# cat /etc/apt/sources.list

# Repos managed by puppet.

deb [signed-by=/usr/share/keyrings/hazelcast-archive-keyring.gpg] https://repository.hazelcast.com/debian stable main

Ubuntu ppa
ppa Ubuntu'da şu ekrana denk gelir.
Software Settings -> Software & Updates -> Other Software
Eklenen repository bilgisi /var/lib/apt/keyrings/ dizininde saklanır.

add-apt-repository ve apt-add-repository komutları aynı şeydir. Görmek için şöyle yaparız.
ls -l `which apt-add-repository`
... /usr/bin/apt-add-repository -> add-apt-repository
Not : add-apt-repository komutunu çaşıştırdıktan sonra upt-get komutunu çalıştırıp paketleri güncellemek gerekir.

Örnek - universe Ubuntu'nun kendi repository'dir
Ubuntu'nun kendi repo'sunu eklemek için ppa kullanmaya gerek yok. Şöyle yaparız. Yeni repository eklendikten sonra upt-get ile paket bilgisi çekiliyor.
sudo add-apt-repository universe
sudo apt-get update
sudo apt install blender steam
Örnek
Şöyle yaparız. Yeni repository eklendikten sonra upt-get ile paket bilgisi çekiliyor.
sudo apt-add-repository universe
sudo apt-get update
sudo apt-get install wireguard
Örnek
Visual Studio kurmak için şöyle yaparız.
sudo add-apt-repository ppa:ubuntu-desktop/ubuntu-make
sudo apt-get update
sudo apt-get install ubuntu-make
Örnek
Şöyle yaparız.
sudo add-apt-repository ppa:tista/adapta
sudo apt-get update
sudo apt-get install adapta-gtk-theme
Kullanım
--remove seçeneği
Örnek
Bazen paketler repository'den kaldırılıyor. Bunu şöyle görebiliriz
sudo apt update
...
Err:9 http://ppa.launchpad.net/wireguard/wireguard/ubuntu focal InRelease
  403  Forbidden [IP: 91.189.95.83 80]
Reading package lists... Done                      
E: Failed to fetch http://ppa.launchpad.net/wireguard/wireguard/ubuntu/dists
/focal/InRelease 403  Forbidden [IP: 91.189.95.83 80]
E: The repository 'http://ppa.launchpad.net/wireguard/wireguard/ubuntu focal 
  InRelease' is no longer signed.
N: Updating from such a repository can't be done securely, and is therefore disabled by
  default.
N: See apt-secure(8) manpage for repository creation and user configuration details.
Bu durumda bu repository'i kaldırmak için şöyle yaparız
sudo apt-add-repository -r ppa:wireguard/wireguard
Örnek
Şöyle yaparız.
sudo add-apt-repository --remove ppa:whatever/ppa


9 Ağustos 2020 Pazar

bash kodlama - CDPATH değişkeni

Giriş
Açıklaması şöyle. cd komutu çalıştırılınca
 - Önce CDPATH değişkenine değer atanmışsa bu değer ile başlayan dizin varsa oraya gider.
- Yoksa current directory'den başlayarak belirtilen yere gitmeye çalışır.
In other words, the default behavior for cd foo is "move into the directory named 'foo' which is a subdirectory of the current directory or of any other directory that is given in CDPATH". When CDPATH is not set, cd will only look in the current directory but, when it is set, it will also look for a match in any of the directories you set it to.
Değer Atama
Şöyle yaparız
CDPATH="/path/to/dir1:/path/to/dir2:/path/to/dirN"
Örnek
Şöyle yaparız
$ echo $CDPATH    ## CDPATH is not set

$ cd etc          ## fails: there is no "etc" directory here
bash: cd: etc: No such file or directory
$ CDPATH="/"      ##CDPATH is now set to /
$ cd etc          ## This now moves us to /etc
/etc

ELF Formatı

Giriş
Linux sadece ELF çalıştırmak zorunda değil.  Linux'ta bir çok dosya formatı var. AOUT, ELF, COFF , SHEBANG gibi.

Windows terminolojisi ile konuşursak, ELF formatı Linux'taki exe veya DLL dosyaların formatıdır diyebiliriz.

Magic Numbers
Kernel dosyayı çalıştırırken baş tarafını okur ve baştaki magic number'a göre dosya ile ne yapacağına karar verir.

ELF Magic Number
Eğer okunan birkaç byte ELF magic number yani \x7FELF (hex: 7f 45 4c 46 ile başlıyorsa bu dosya çalıştırılabilirdir der ve başlatır. Açıklaması şöyle
ELF object file starts with 0x7F 0x45 0x4C 0x46 (with bytes 2-4 being 'ELF' in ASCII).
Shebang Magic Number
Eğer magic number shebang yani #! (hex: 23 21) ise bu dosya bir script dosyasıdır der ve örneğin bash ile çalıştırır. Açıklaması şöyle.
The kernel opens the executable, and finds that it starts with #!.
The kernel closes the executable and opens the interpreter instead.
The kernel inserts the path to the script to the argument list (as argv[1]), and executes the interpreter.
Bir elf dosyasının başlığını görmek için şöyle yaparız.
$ readelf -a MyApp
Yapısı Nasıldır
Bu formatın başı şöyledir. Bu format Linux'ta elf.h dosyasında tanımlı.
typedef struct {
  uint8  e_ident[16];
  uint16 e_type;
  uint16 e_machine;
  uint32 e_version;
  uint32 e_entry;
  uint32 e_phoff;
  uint32 e_shoff;
  uint32 e_flags;
  uint16 e_ehsize;
  uint16 e_phentsize;
  uint16 e_phnum;
  uint16 e_shentsize;
  uint16 e_shnum;
  uint16 e_shstrndx;
} Elf32Hdr;
ident alanı
0x7f ve ELF ile başlar.
// check so its really an elf file
if(header.e_ident[0] == 0x7f &&
   header.e_ident[1] == 'E' &&
   header.e_ident[2] == 'L' &&
   header.e_ident[3] == 'F') {...}
ident alanının 6. byte'ı endiannes bilgisini verir. Açıklaması şöyle
This byte is set to either 1 or 2 to signify little or big endianness, respectively. This affects interpretation of multi-byte fields starting with offset 0x10.
Görmek için şöyle yaparız. Aşağıdaki örnekte LSB çıktısını görürüz. Uygulam little endian'dır.
 $ file /bin/ls
/bin/ls: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, 
interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, 
BuildID[sha1]=4637713da6cd9aa30d1528471c930f88a39045ff, stripped
type Alanı
ET_DYN veya ET_EXEC olabilir.

lsblk komutu

Giriş
lshwlspci , lscpu, lsusb,lsmod gibi komutlar ile kardeştir. block cihazları listeler.

MOUNTPOINT Ne Demek?
Dosyalara erişmek için komut satırında kullanılacak yol anlamına gelir. Aslında diskteki bir partition'a denk gelir.

Örnek
Elimizde şöyle bir sistem olsun.
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda      8:0    0 931.5G  0 disk 
├─sda1   8:1    0   100M  0 part 
└─sda2   8:2    0 931.4G  0 part 
sdb      8:16   1  14.4G  0 disk 
├─sdb1   8:17   1  42.9M  0 part /media/ubuntu/boot
└─sdb2   8:18   1  14.4G  0 part /media/ubuntu/rootfs
sdc      8:32   1  59.7G  0 disk 
├─sdc1   8:33   1   256M  0 part /media/ubuntu/boot1
└─sdc2   8:34   1  59.4G  0 part /media/ubuntu/rootfs1
sr0     11:0    1     2G  0 rom  /cdrom
rootfs bir usb cihazıdır. rootfs1 ise bir başka usb cihazıdır. Bir cihazdan öbürüne kopyalamak için şöyle yaparız.
cp -pr /media/ubuntu/rootfs/max7219 /media/ubuntu/rootfs1/
Örnek
Benim sistemimde çıktı şöyle
NAME   MAJ:MIN RM   SIZE      RO TYPE MOUNTPOINT
sda           8:0             0     931,5G    0   disk
├─sda1   8:1             0     487M      0    part    /boot/efi
├─sda2   8:2             0     925,3G    0    part    /
└─sda3   8:3             0     5,7G        0    part  [SWAP]
sr0           11:0           1     1024M    0    rom
size Sütunu Ne Demek
Cihazın depolama kapasitesini gösterir. Bu değer cihazdaki elektronik devrelerde saklıdır.

-b seçeneği
Size sütunu byte olarak gösterilir. Şöyle yaparız
$ lsblk -b
NAME    MAJ:MIN RM        SIZE RO TYPE MOUNTPOINT
xvda    202:0    0 34359738368  0 disk 
├─xvda1 202:1    0  1676673024  0 part [SWAP]
└─xvda2 202:2    0 32682016768  0 part /var/spool
-e seçeneği
Açıklaması şöyle
-e, --exclude list
          Exclude the devices specified by  the  comma-separated  list  of
          major  device  numbers.   Note  that  RAM  disks  (major=1)  are
          excluded by default.  The filter is  applied  to  the  top-level
          devices only.
Örnek
Major numarası 7 olan cihazları hariç bırakmak için şöyle yaparız.
$ lsblk -e7
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda      8:0    0 238.5G  0 disk
├─sda1   8:1    0   9.8G  0 part
├─sda2   8:2    0 164.7G  0 part
├─sda3   8:3    0  31.1G  0 part /
├─sda4   8:4    0     1K  0 part
├─sda5   8:5    0  15.3G  0 part /usr/local
└─sda6   8:6    0  17.7G  0 part /home
sr0     11:0    1  1024M  0 rom
-f seçeneği
Açıklaması şöyle. Kalan disk alanını ve kullanım yüzdesini gösterir. Bu serçeneğin bir diğer alternatifi "df -h" komutu
.. df -h and lsblk -f display disk usage/remaining disk space for mounted partitions
Örnek
Şöyle yaparız
 xubuntu@xubuntu:~$ lsblk -f
  NAME   FSTYPE   LABEL                   UUID                                 FSAVAIL FSUSE% MOUNTPOINT
  loop0  iso9660  Xubuntu 20.04 LTS amd64 2020-04-23-07-50-17-00                     0   100% /cdrom
  loop1  squashfs                                                                    0   100% /rofs
  sda                                                                                         
  ├─sda1 ext4     bionic                  2093f8d6-7840-4256-8edc-4db97e865784   12.2G    87% /media/xubuntu/bionic
  ├─sda2 swap                             4b882c9f-4867-4c5c-8eb7-c84ef03f4786                [SWAP]
  └─sda3 ext4     focal                   31f64dfc-933a-4f48-9209-e7a7b016d8c9                
  sdb                                                                                         
  ├─sdb1                                                                                      
  ├─sdb2 vfat     usbboot                 02D3-7915                                           
  └─sdb3 ext4     isodevice               04d5aa8c-aa1e-4a71-9d79-edaf6e8b2111    7.7G    16% /isodevice
  sr0                                                                                         
  xubuntu@xubuntu:~$ 
-l seçeneği
Normalde kullanımda çıktı bir ağaç gibidir.
NAME   TRAN
sda    sata
└─sda1
sdb    usb
sr0    sata
-l seçeneği ile ağaç yerine liste gibi çıktı alırız. Şöyle yaparız.
lsblk -l -o name,tran
Çıktı olarak şunu alırız
NAME TRAN
sda  sata
sda1 
sdb  usb
sdc  usb
sr0  sata
-o seçeneği
output anlamına gelir. NAME ve LABEL sıkça kullanılır.
Örnek
Şöyle yaparız.
$ sudo lsblk -o NAME,LABEL
NAME   LABEL
sda
├─sda1 System Reserved
├─sda2
├─sda3
├─sda5
└─sda6
Örnek
Şöyle yaparız.
$ lsblk -o NAME,FSTYPE,LABEL,MOUNTPOINT,SIZE,MODEL


6 Ağustos 2020 Perşembe

ln komutu

Giriş
ln komunutu her zaman şöyle okumak lazım
ln source target
GNU dokümanlarıda şöyle kullanılıyor. Burada target aslında source anlamına geliyor :)
ln [option]… [-T] target linkname
hardlink
hardlink'ler bir dizindeki çok sayıda dosyayı belli bir seçeneğe göre (yıl, konu vs.) gruplamak için kullanılabilir.

Örnek
Şöyle yaparız. sourcefile silinirse bile hardlinkfile kullanılabilir. Çünkü dosya gerçekte silinmez.
ln sourcefile hardlinkfile
-s seçeneği - Softlink İçindir
Symbolic Links veya Softlink yazısına taşıdım

5 Ağustos 2020 Çarşamba

openssl dgst aracı - Secure Hash Hesaplar

Giriş
digest anlamına gelir. Açıklaması şöyle.
One way to compute hash values is using openssl. You can give it a file as an argument, or pipe a string to it.
list seçeneği
 Açıklaması şöyle.
To see the list of hash functions openssl supports, use list --digest-commands.
Örnek
Şöyle yaparız.
$ openssl list --digest-commands

blake2b512 blake2s256 gost     md4
md5        mdc2       rmd160   sha1
sha224     sha256     sha3-224 sha3-256
sha3-384   sha3-512   sha384   sha512
sha512-224 sha512-256 shake128 shake256
sm3
-sha256 seçeneği
Örnek - Farklı seçenekler
Eğer openssl kullanmak istemiyorsak şöyle yaparız
echo hello | sha1sum
f572d396fae9206628714fb2ce00f72e94f2258f  -
Örnek
Dosyay için şöyle yaparız.
openssl dgst -sha256 myfile
Örnek
String için şöyle yaparız. echo - n ile girdiye newline eklenmez
echo -n 'hello world' | openssl dgst -sha256
b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9
Örnek
String için şöyle yaparız.
openssl dgst -sha256 -binary <<<"..."