28 Eylül 2020 Pazartesi

/var/log Dizini

Giriş
/var/log dizinindeki sistem logları bulunur. Açıklaması şöyle. sistem loglarını görmek için journalctl komutu da kullanılabilir.
Here, you’ll see filenames like syslog, messages, auth.log, secure, cron, kern.log, apache2, mysql and more.
The Linux Log Format
Açıklaması şöyle.
The format of these logs is customizable. For example, you can log additional information by specifying extra fields in log configuration files. By default, however, log file entries are in a format close to this:

Timestamp, Hostname, Application name, Priority, Message

While Hostname is the server in the system where the message originated, Application name refers to the name of the application that generated the event, and Priority denotes how urgent or severe an event is. 
Uygulama Dosyaları
Açıklaması şöyle.
User applications often store their logs in this directory, as well. Notable examples are Apache and MySQL. They store their application logs in the apache2 and mysql files, respectively. Some applications can write directly into the syslog file as well.
auth.log ve secure Dosyaları
Açıklaması şöyle.
auth.log or secure stores authentication logs, including all successful and failed login attempts.
Açıklaması şöyle.
The sudo command also creates log entries in auth.log. Any failed or successful commands executed via sudo are logged.
cron Dosyası
Açıklaması şöyle.
cron stores cron job-related messages, such as cron initiations and failures
kern Dosyası
Açıklaması şöyle.
kern is for kernel logs and related warning messages.
syslog ve messages Dosyaları
Açıklaması şöyle.
The syslog or messages file contains general messages that log activities across the entire system.
syslog Servisi yazısına bakabilirsiniz.

nl komutu

Giriş
Kullanmak için şöyle yaparız
wolf@linux:~$ ls -lh | nl
     1  total 24
     2  -rw-rw-r-- 1 wolf wolf  186 Sep  24 22:18 01.py
     3  -rw-rw-r-- 1 wolf wolf  585 Sep  24 22:21 02.py
     4  -rw-rw-r-- 1 wolf wolf  933 Sep  24 22:26 03.py
-v seçeneği
Normalde nl komutu saymaya 1 sayısından başlar. Başka bir sayıdan başlasın istersek bu seçeneği kullanırız.

Örnek
Şöyle yaparız
$ ls -lh | nl -v 0
   0  total 24
   1  -rw-rw-r-- 1 wolf wolf  186 Sep  24 22:18 01.py
   2  -rw-rw-r-- 1 wolf wolf  585 Sep  24 22:21 02.py
   3  -rw-rw-r-- 1 wolf wolf  933 Sep  24 22:26 03.py

27 Eylül 2020 Pazar

rename komutu

-n seçeneği
İkinci "_" karakterinden sonrasını kesmek için şöyle yaparız
rename -n 's/[^_]*[_][^_]*[_]//' *

25 Eylül 2020 Cuma

TTY

Giriş
TTY açmak için şöyle yaparız. Aslında Ctrl + Alt + F4 ve diğer F tuşları da farklı TTY'ler açar.
Open TTY with CTRL + ALT + F3.
Login by typing your username and then your password. Note, while typing your password, nothing will appear on the screen.
Komutu çalıştırıp tekrar masaüstüne dönmek için Alt + sağ ok'a basarız
Repeatedly press ALT + ⇒ (right arrow) until you return to your desktop ...

23 Eylül 2020 Çarşamba

nanosleep metodu

Giriş 
Bu metod bir POSIX çağrısı. C diline ait değil

Örnek
Şöyle yaparız
#include <time.h>
struct timespec ts;
ts.tv_sec = 3;
ts.tv_nsec = 0;
nanosleep(&ts, NULL);

16 Eylül 2020 Çarşamba

bash kodlama - : (No Effect) built-in komutu. Subprocess Açılmasını Engeller

Giriş
Açıklaması şöyle.
: [arguments]
          No effect; the command does nothing beyond  expanding  arguments
          and  performing any specified redirections.  A zero exit code is
          returned.
Yani true döner.  Bu komutun esas kullanıldığı yer bash içinde echo, touch gibi çağrılarda yaratılan subprocess'lerin çalışmasını engellemesi. Bu komut yerine direkt > "..." şeklinde de kullanabiliriz.

Örnek
Elimizde şöyle bir kod olsun. Bu komut her alt dizin altında 500 tane fileX isimlide dosya oluşturur. Ancak bu komut yavaştır
for dir in /xfs/*/; do seq 1 1000000 | xargs -n1 -I% bash -c 'touch '$dir/file%' ; done;
Daha hızlı olsun diye şöyle yaparız.
for dir in /xfs/*/; do
    for ((i=1; i <= 1000000; i++)); do
        : > "$dir/file$i"
    done
done
Açıklaması şöyle
touch is an external program that you are having to start 5,000,000,000 times. You are also running seq 5,000 times. Don't run either of them.
Ya da şöyle yaparız.
> "$dir/file$i"
Örnek - Dosya Truncate
Açıklaması şöyle.
: is a "do nothing command" that will exit with success and produce no output, so it's simply a short method to empty a file. In most shells, you could simply do >file.txt to get the same result. It also could be marginally faster than other methods such as echo >file.txt as echo could potentially be an external command.
Şöyle yaparız. Dosyayı truncate eder.
root$ :>file.txt
Örnek - for Koşulu
Şöyle yaparız
$ time for i in $(seq 1000); do :; done

real    0m0,007s
user    0m0,002s
sys     0m0,004s
$ time for i in $(seq 1000); do /bin/true; done

real    0m0,686s
user    0m0,462s
sys     0m0,217s
Örnek - Sonsuz Döngü
Sonsuz döngü kurmada kullanılır. Şöyle yaparız.
while :
do
  something
done
Açıklaması şöyle.
This is perhaps best known for use in a while statement (while :; do break; done)

15 Eylül 2020 Salı

dconf komutu

Giriş
Bu komut yerine dconf-editor kullanılabilir.

Örnek
Şöyle yaparız
dconf write /org/gnome/desktop/wm/keybindings/switch-to-workspace-5 "['<Primary>F5']"