22 Ekim 2019 Salı

tac komutu

Giriş
Dosyayıs tersinden gösterir.

Örnek
Şöyle yaparız.
$ echo -e "Hello\nNew\nWorld\n!" > file
$ tac file
!
World
New
Hello
-b seçeneği
Açıklaması şöyle.
-b, --before
The separator is attached to the beginning of the record that it precedes in the file.
Örnek
Şöyle yaparız.
$ echo -e "Hello\nNew\nWorld\n!" > file
$ tac -b file


!
World
NewHello

20 Ekim 2019 Pazar

SIGINFO

Giriş
Standart bir LINUX sinyali değildir. Açıklaması şöyle.
On some Unix-style systems (BSDs and macOS), CtrlT sends SIGINFO to the running process. Some commands handle this directly; otherwise, it’s handled by the kernel, and that’s what produces the output you’re seeing.
Örnek
Şöyle yaparız. Kullanıcı Ctrl + T tuşlarına bastığı için fazladan çıktıyı görür.
$ ping -q -c 100 google.com
PING google.com (172.217.16.46): 56 data bytes
load: 2.39  cmd: ping 5374 running 0.00u 0.00s
2/2 packets received (100.0%) 33.914 min / 34.169 avg / 34.423 max

rsync komutu - Replicate Directory Structure

Giriş
Replicate Directory Structure anlamına gelir

1. Kurulum
Kurmak için şöyle yaparız
sudo apt install rsync 
2. Genel Kullanım
Şöyledir. Yani seçeneklerden sonra kaynak dizin daha sonra da hedef dizin belirtilir
rsync ...options... /full/path/src ./dst
Çok kullanılan seçenekler
-a 
--progress
--inplace

Örnek
Şöyle yaparız. -n ile prova yapılır yani ne işlem yapılacağı görülür. -v ile daha detaylı bilgi gösterilir. -f ile dosyalar seçilir.
rsync -nvr -f '+ *.odt' -f '+ **/' -f '- *' --prune-empty-dirs ~/Documents/ ~/copies/
3. Seçenekler

-a seçeneği
Açıklaması şöyle.
The -a option is a combination flag. It stands for "archive" and syncs recursively and preserves symbolic links, special and device files, modification times, group, owner, and permissions. It is more commonly used than -r and is usually what you want to use.
Örnek
Şöyle yaparız.
BACKUPPOINT=/mnt/user
MOUNTPOINT=/mnt/disks/REDBackup

rsync -a -v --delete $BACKUPPOINT/ $MOUNTPOINT/Daily/ 2>&1
Örnek
Şöyle yaparız. Bulunduğumuz dizini hedef dizine kopyalar
rsync -av ./ destination:destPath/
Örnek
Sadece dizin yapısını timestamp bilgisi de dahil olacak şekilde kopyalamak için şöyle yaparız.
rsync -a --include='*/' --exclude='*' /some/path/dir/ dir
Açıklaması şöyle.
This would recreate the directory structure of /some/path/dir as dir in the current directory, without copying any files.

Any directory encountered in the source path would be created at the target due to the inclusion pattern, but anything else would be excluded. As a side effect of using -a (--archive), you'll get the same timestamps on all subdirectories in the target as in the source. This also works for creating local directory structures from remote directories (and vice versa).
--append
restart vs gibi işlemlerde kaldığı yerden deva etmesi için kullanılır. --append seçeneğini kullanırken kaynak dosyanın değişmediğinden emin olmak gerekir.
Örnek
Şöyle yaparız
rsync -a -vi --append --inplace --partial --progress 
  /path/to/source/  
  /path/to/target
Açıklaması şöyle.
You could remove --progress if you didn't want to see a progress indicator, and -vi if you are less bothered about a more informational result (you'll still get told if it succeeds or fails). You may see -P used in other situations: this is the same as --partial --progress and can be used for that here too.

--append to continue after a restart without checking previously transferred data
--partial to keep partially transferred files
--inplace to force the update to be in-place
If you are in any doubt at all that the source might have changed since the first attempt at rsync, use the (much) slower --append-verify instead of --append. Or better still, remove the --append flag entirely and let rsync delete the target and start copying it again.

-c seçeneği - MD5 comparison yapar
Açıklaması şöyle.
-c causes rsync to compare files by MD5 checksum (without it, it normally uses only the timestamp and size for quicker comparisons).
--delete seçeneği
Açıklaması şöyle.
Add the --delete flag to to completely overwrite the target directory tree each time. If you want to see what's going on, add -v.
Şöyle yaparız.
rsync -avz -H --delete /etc /bin (...and so on) destserver:/mnt/yourrootfs/
--exclude seçeneği
Bazı dosya veya dizinleri hariç bırakır
Örnek
Şöyle yaparız
rsync -av --exclude '*.txt' dir1/ dir2/
Örnek
Şöyle yaparız. logs dizini hariç bırakılır
rsync --archive --exclude /logs /home/user/glassfish/domains/domain1 /home/user/backup
-H seçeneği
Örnek
Açıklaması şöyle
if you don't use -H, hardlinks are lost.
if you don't use -S, sparse files may have been expanded
Şöyle yaparız, hard link'ler kaybolur, sparse dosyalar genişletilir.
sudo rsync --progress -au --delete --rsync-path="sudo rsync" /u/ henry@enceladus:/u
--ignore-existing seçeneği
Açıklaması şöyle.
A temporary file is O_EXCL created by default (only disabled if you use --inplace) and then renamed over the target file. Use --ignore-existing to not overwrite B if it exists.
Örnek
Şöyle yaparız. B'de bulunan ancak A'da eksik olanları kopyalar
rsync -a --ignore-existing B A
--inplace seçeneği
Açıklaması şöyle.
With standard options, rsync will copy the new file assigning it a semi-random name, then it will rename the new file with the original name. In this process, no writes are directed at the original file, preserving its hadlinks.

On the other side, using the non-default--inplace option will overwrite the original file and its hardlinks.

Anyway, I strongly suggest to give a look at --link-dest option, which is extremely useful for deduplicated backups.
-i seçeneği
Açıklaması şöyle. Normalde rsync farklı gördüğü dosyaları karşı tarafa kopyalar.
To avoid that, you can also use -n and -i. The former ensures that rsync doesn't do any change and only compares, and the latter causes it to display the differences that it sees.
Örnek
Şöyle yaparız.
$ rsync -rcni dir1/ dir2/
>f+++++++++ c
>fc.T...... d/b
Açıklaması şöyle.
Tells me, by way of all those +s, that file c does not exist in dir2, and file d/b does, but is different (indicated by the c in the first column). The T says that it's time would be updated (had we not used -n).

The format of -i's output is described in the manpage for rsync. You can man rsync and get to the part that explains that output by typing /--itemize-changes$ (and hitting Enter).
-P seçeneği
--partial veya --progress seçenekleri ile aynıdır. progress gösterir. Dosya göndermek için şöyle yaparız.
rsync -chavzP dump.sql user@ip-address:~
--partial seçeneği
Açıklaması şöyle
--partial                keep partially transferred files
--progress seçeneği
Şöyle yaparız.
rsync -av --progress file.txt user@host:
--prune-empty-dirs seçeneği
Şöyle yaparız. Eğer dizin altında istenilen dosya yoksa boş dizini oluşturmaz.
rsync -zarv  --prune-empty-dirs --include "*/"  --include="*.sh" --exclude="*"
  "$from" "$to"
-R/--relative seçeneği
Açıklaması şöyle. Full path'i muhafaza eder.
-R, --relative Use relative paths. This means that the full path names specified on the command line are sent to the server rather than just the last parts of the filenames. This is particularly useful when you want to send several different directories at the same time. For example, if you used this command: rsync -av /foo/bar/baz.c remote:/tmp/ ... this would create a file named baz.c in /tmp/ on the remote machine. If instead you used rsync -avR /foo/bar/baz.c remote:/tmp/ then a file named /tmp/foo/bar/baz.c would be created on the remote machine, preserving its full path. These extra path elements are called “implied directories” (i.e. the “foo” and the “foo/bar” directories in the above example).
-v/--version seçeneği
Şöyle yaparız
rsync ---version
-z seçeneği
Sanırım sıkıştırarak gönderiyor.
Örnek
Şöyle yaparız
rsync -az ~/Documents/projects/myproject/dist/ root@13.21.13.12:public_html/

unzip komutu

Giriş
.zip uzantılı dosyası oluşturup açmak içindir. .gz uzantılı dosyalar için gunzip komutu kullanılır. Eğer unzip komutu kurulu değilse, alternatif olarak şöyle yapabiliriz
jar xvf file.zip 
-o seçeneği
Zip dosyasının açılacağı dizini belirtir.

Örnek
Şöyle yaparız
PACKAGE_PATH="/opt/installtools/"
PACKAGE_FILE="foo.zip"

unzip -o $PACKAGE_FILE -d $PACKAGE_PATH; 
-q seçeneği
Açıklaması şöyle. Açma işlemini gerçekleştirirken dosya isimlerini ekrana yazmaz
-q     perform  operations  quietly  (-qq  = even quieter).  Ordinarily
       unzip prints the names of the files it's extracting or  testing,
       the extraction methods, any file or zipfile comments that may be
       stored in the archive, and possibly a summary when finished with
       each  archive.   The -q[q] options suppress the printing of some
       or all of these messages.
Şöyle yaparız.
unzip -q filename.zip

16 Ekim 2019 Çarşamba

nmap komutu

Giriş
Açıklaması şöyle.
Nmap provides a number of features for probing computer networks, including host discovery and service and operating system detection. These features are extensible by scripts that provide more advanced service detection, vulnerability detection, and other features.
Kullanım
Şöyle yaparız
$ nmap server.lan
Starting Nmap 7.80 ( https://nmap.org ) at 2020-10-11 22:55 AEDT
Nmap scan report for server.lan (192.168.0.15)
Host is up (0.00024s latency).
Not shown: 997 closed ports
PORT     STATE SERVICE
22/tcp   open  ssh
5432/tcp open  postgresql
9090/tcp open  zeus-admin

Nmap done: 1 IP address (1 host up) scanned in 0.05 seconds
-p seçeneği - Açık portları arar
Örnek
ssh portlarını taramak için şöyle yaparız. -oG ile grep yapılabilecek çıktı verir.
nmap -oG - -p 22 192.168.1.0/24  | grep /open/
-PR seçeneği - ARP Discovery
ARP Ping (arping) yapar. Böylece sadece ARP'a cevap veren makineler bulunabilir.
Örnek
Şöyle yaparız
nmap -SP -PR 192.168.3.*
-sL seçeneği - List Scan Yani IP Aralığı İle Çalışmak
Açıklaması şöyle
By default, Nmap does host discovery and then performs a port scan against each host it determines is online.
...
The list scan is a degenerate form of host discovery that simply lists each host of the network(s) specified, without sending any packets to the target hosts. By default, Nmap still does reverse-DNS resolution on the hosts to learn their names.
Örnek
Maalesef nmap iki tane IP aralığını açıkça yazılınca kabul etmiyor. Eğer yaparsak şu hatayı alırız
$ nmap -sL 10.1.1.1-10.1.1.3
Starting Nmap
Failed to resolve "10.1.1.1-10.1.1.3".
WARNING: No targets were specified, so 0 hosts scanned.
Nmap done: 0 IP addresses (0 hosts up) scanned in 0.04 seconds
Sadece bitiş IP adresinin son kısmını vermek gerekiyor. Yani şöyle yaparız
$ nmap -sL 10.1.1.1-3

-sC seçeneği
Örnek
Şöyle yaparız
$ nmap --top-ports 1000 -T4 -sC http://example.com
Nmap scan report for example.com {redacted}
Host is up (0.077s latency).
rDNS record for {redacted}: {redacted}
Not shown: 972 filtered ports
PORT      STATE  SERVICE
21/tcp    open   ftp
22/tcp    open   ssh
| ssh-hostkey: 
|   {redacted}
80/tcp    open   http
| http-methods: 
|_  Potentially risky methods: TRACE
|_http-title: Victim Site
139/tcp   open   netbios-ssn
443/tcp   open   https
| http-methods: 
|_  Potentially risky methods: TRACE
|_http-title: Site doesn't have a title (text/html; charset=UTF-8).
|_{redacted}
445/tcp   open   microsoft-ds
5901/tcp  open   vnc-1
| vnc-info: 
|   Protocol version: 3.8
|   Security types: 
|_    VNC Authentication (2)
8080/tcp  open   http-proxy
|_http-title: 400 Bad Request
8081/tcp  open   blackice-icecap

Açıklaması şöyle
--top-ports 1000: This option tells Nmap to only scan the top 1000 most common ports. This can save time if you are scanning a large network.
-T4: This option tells Nmap to use a more aggressive scanning technique. This will increase the speed of the scan, but it may also make it more noticeable to the target.
-sC: This option tells Nmap to perform a comprehensive scan of the target host. This includes scanning for open ports, services, and operating system information.

-sn seçeneği - no port scan (Disable port scanning. Host discovery only)
Ping'leyerek scan yapar.
Örnek
Şöyle yaparız.
nmap -oG - -sn 192.168.3.2-254
Örnek
Şöyle yaparız
nmap -sn 192.168.1.0/24  # Ping scan
-sP seçeneği - no port scan
Sadece "up" olan bilgisayarları görmek için kullanılır. Yeni sürümde -sn seçeneği oldu
Şöyle yaparız.
nmap -sP 192.168.3.0/24
-sS seçeneği - stealth syn scan (TCP SYN port scan (Default))
stealth syn scan anlamına gelir.

-sT seçeneği - standart TCP scan
standart tcp scan anlamına gelir. Bu seçenek eğer root değilsek kullanılır. Şöyle yaparız.
nmap -sT google.com
-sV seçeneği
Açıklaması şöyle.
-sV will probe open ports to determine service/version info
-T4 seçeneği
Açıklaması şöyle.
-T4 this setting is required to set up scan speed (T5 is the maximum, most aggressive scan)