12 Eylül 2019 Perşembe

parted komutu

Örnek
Şöyle yaparız.
root@irb00a ~]# parted /dev/sda1
GNU Parted 3.2
Using /dev/sda1
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print
Model: Unknown (unknown)
Disk /dev/sda1: 12.0TB
Sector size (logical/physical): 512B/512B
Partition Table: loop
Disk Flags:

Number  Start  End     Size    File system  Flags
 1      0.00B  12.0TB  12.0TB  xfs

locale komutu

Örnek
Değerleri görmek için locale komutunu kullanarak şöyle yaparız.
$ locale
LANG=en_GB.UTF-8
LANGUAGE=
LC_CTYPE="en_GB.UTF-8"
LC_NUMERIC="en_GB.UTF-8"
LC_TIME="en_GB.UTF-8"
LC_COLLATE="en_GB.UTF-8"
LC_MONETARY="en_GB.UTF-8"
LC_MESSAGES="en_GB.UTF-8"
LC_PAPER="en_GB.UTF-8"
LC_NAME="en_GB.UTF-8"
LC_ADDRESS="en_GB.UTF-8"
LC_TELEPHONE="en_GB.UTF-8"
LC_MEASUREMENT="en_GB.UTF-8"
LC_IDENTIFICATION="en_GB.UTF-8"
LC_ALL=
Örnek
Şöyle yaparız.
$ locale
LANG="en_GB.UTF-8"
LC_COLLATE="en_GB.UTF-8"
LC_CTYPE="en_GB.UTF-8"
LC_MESSAGES="en_GB.UTF-8"
LC_MONETARY="en_GB.UTF-8"
LC_NUMERIC="en_GB.UTF-8"
LC_TIME="en_GB.UTF-8"
LC_ALL=
decimal_point seçeneği
Şöyle yaparız.
locale decimal_point
thousands_sep seçeneği
Şöyle yaparız.
locale thousands_sep


getent komutu

Giriş
Açıklaması şöyle. Bu uygulama POSIX'te tanımlı değil ancak çoğu sistemde mevcut.
Many systems have a getent command to list or query the content of the Name Service databases like passwd, group, services, protocols...
hosts seçeneği
Açıklaması şöyle.
You can check to see which IP NSS resolves a hostname to using getent.
Şöyle yaparız.
getent hosts somename
passwd seçeneği
Örnek - Home dizin
Home dizinleri almak için şöyle yaparız.
getent passwd | cut -d: -f6
Örnek - Kullanıcı ismi
Kullanıcı isimlerini almak için şöyle yaparız.
getent passwd | cut -d: -f1
Kullanıcı ismini almak için id komutu da kullanılabilir.

9 Eylül 2019 Pazartesi

which komutu - type komutunu kullanın

Giriş
Not : Bu komut yerine type komutu tercih edilmeli

Açıklaması şöyle.
which searches for binaries in the $PATH, a.k.a. command-line tools. User applications are not such tools and not available in the command line.
Windows'taki "where" komutuna benzer. 

Örnek
Şöyle yaparız.
$ which python
/anaconda3/bin/python
Örnek
Şöyle yaparız.
$ which uname
/bin/uname
Örnek
Şöyle yaparız.
$ which ping
/usr/bin/ping 
Örnek - İki Parameter Birden
Şöyle yaparız.
$ which node postfix
/root/.nvm/versions/node/v14.15.1/bin/node
/usr/sbin/postfix

















6 Eylül 2019 Cuma

cut komutu

Giriş
Kesilecek yeri belirtmek için
1. -c veya  -f kullanılır
2. -f kullanıyorsak ayracı belirtmek için gerekiyorsa -d kullanılır.
Açıklaması şöyle.
cut uses -d or --delimiter to specify the field delimiter and -f or --fields to specify fields.
UTF-8
cut komutu sadece byte bilir. UTF-8 ve diğer multi-byte encoding'leri bilmez. Açıklaması şöyle
The cut command in Ubuntu is not multi-byte character aware. Characters are the same as bytes for this version of the cut command.
Örnek
UTF-8 ile çalışmadığını görmek için şöyle yaparız
$ echo £ |cut -c 1
�
-c seçeneği
Select only these characters anlamına gelir. Belirtilen karakter aralığını döndürür
Örnek
UTF-8 ile çalışmak için şöyle yaparız
$ echo £ |cut -c 1-2
£
-d seçeneği
Kullanılacak ayracı belirtir.
Örnek
Şöyle yaparız. Çıktı stdout'a gönderilir.
cut -d: -f2-
-f seçeneği
Döndürülecek sütunları belirtir.
Örnek
Eğer döndürülecek sütun yoksa newline döndürülür. Görmek için şöyle yaparız.
echo "$versionfull" | cut -d. -f3 | od -c
0000000  \n
0000001
Örnek
İlk 3 alan için şöyle yaparız.
#!/bin/bash
FILES=/path/to/*
for f in $FILES
do
    # Do something for each file. In our case, just echo the first three fields:
    cut -f1-3 < "$f"
done

26 Ağustos 2019 Pazartesi

bash history expansion

Giriş
Otutum (session) kapandıktan sonra komutlar şu dosyaya yazılır.
~/.bash_history
!!
En son girilen komut ile yer değiştirir.
Örnek
Açıklaması şöyle
!! is a history command of bash, it gets replaced by the last command you‘ve executed. You can try ls followed by echo !!
Şöyle yaparız.
some command
echo !!
!komutu ismi yani event designator
Örnek
Şöyle yaparız
cp company-sso /usr/local/bin/company-sso ; sudo chmod +x !cp:$
Açıklaması şöyle
This is history expansion, introduced by !; the $ must be intepreted in that context. !cp:$ has two parts, separated by :. !cp is the event designator, it means “find the most recent command starting with cp”. $ is a word designator, it means “take the last word (argument) in the selected command”.

So, assuming the last command in the history (of previously-run commands) is also cp company-sso /usr/local/bin/company-sso, !cp:$ is replaced with /usr/local/bin/company-sso, and the command run is sudo chmod +x /usr/local/bin/company-sso.

!#:number
En çok kullanılan şeylerden birisi bu. history komutu ile tarihçe listelenir Her satırın yanında bir sayı vardır. "!Sayı" şeklinde kullanarak o komutu tekrar edebiliriz. Sayı olarak sondan geriye doğru gitmek için eksi bir sayı verilebilir.

Örnek
Açıklaması şöyle
!-n    Refer to the current command minus n
Sondan bir önceki komutu çalıştırmak için şöyle yaparız
!-2
Örnek
Şöyle yaparız.
echo "echo 'Hello World'" >script.sh&&chmod +x !#:3
Açıklaması şöyle.
History Expansion replaces !#:3 with the fourth word from the current command line, which in your case is the filename script.sh.

su komutu

Giriş
Açıklaması şöyle.
The general purpose of su is to open a new shell under another user's login account. That other user could be root (and perhaps most often is), but su can be used to assume any identity the local system can authenticate.
-l seçeneği
Yeni bir login shell başlatır. Açıklaması şöyle
If you only give a username as argument, su changes user without changing much else:

So su postgres stays in the same directory. However since HOME is set to the new 
user’s home directory, cd will take you to the right place.

To log in and start from the user’s default directory, you need to ask su to start 
a login shell set up appropriately:

su -l postgres
or its common synonym,

su - postgres
Örnek
Şöyle yaparız
13:27:20 /home/jim> su -l mike
Password:(I type mike's password (or have him type it) and press Enter)
13:27:22 /home/mike> id
uid=1004(mike) gid=1004(mike) groups=1004(mike)
13:27:25 /home/mike> exit  # this leaves mike's login shell and returns to jim's
13:27:29 /home/jim> id
uid=1001(jim) gid=1001(jim) groups=1001(jim),0(wheel),5(operator),...