Dosya sahipliklerini ve izinlerini koruyarak taşımak

Ocak 15, 2014 § Yorum yok § Kalıcı bağlantı

rsync komutunun -a parametresi ile kullanımı bu iş için uygun görünüyor.
Not1: -a kullanılmadığında izinler korunmamaktadir.
Not2: -a kullanıldığında recursive için -r’ye ihtiyaç yoktur. -a zaten recursivedir.
Genel olarak parametreler:
-v : verbose
-r : recursive copyalama sağlar fakat izinler korunmaz
-a : arşiv modu. Recursive çalışır ve izinleri, sahiplikleri vs korur
-z : dosyaları sıkıştırarak gönderir
-h : human-readable formatta çıktı verir
Örnek:

[root@fatihoz ~]# rsync -azvh --progress /home/fatih/1G.file  /tmp/
sending incremental file list
1G.file
       1.02G 100%   38.46MB/s    0:00:25 (xfer#1, to-check=0/1)

sent 995.86K bytes  received 31 bytes  33.76K bytes/sec
total size is 1.02G  speedup is 1028.22
[root@fatihoz ~]# ls -l /tmp/1G.file 
-rw-rw-r--. 1 fatih fatih 1024000000 Jan 15 05:59 /tmp/1G.file

Not3:recursive kopyalama da eğer dizinide kopyalamak istiyorsak dizin adından sonra “/” konmamalıdır.

Dizin içeriğini taşımak için:

[root@fatihoz ~]# rsync -azvh --progress deneme/  /tmp/
sending incremental file list
./
1.txt
           0 100%    0.00kB/s    0:00:00 (xfer#1, to-check=3/5)
12233434543.txt
           0 100%    0.00kB/s    0:00:00 (xfer#2, to-check=2/5)
122343.txt
           0 100%    0.00kB/s    0:00:00 (xfer#3, to-check=1/5)
123.txt
           0 100%    0.00kB/s    0:00:00 (xfer#4, to-check=0/5)

sent 246 bytes  received 91 bytes  674.00 bytes/sec
total size is 0  speedup is 0.00
[root@fatihoz ~]# ls /tmp/
12233434543.txt       .ICE-unix/            .vbox-root-ipc/
122343.txt            keyring-laEwp7/       virtual-fatih.1zDlF2/
123.txt               orbit-fatih/          virtual-fatih.VRdNGR/
1G.file               orbit-gdm/            virtual-fatih.XuZfls/
1.txt                 pulse-Z1C3D8mISpLD/   .X0-lock
.esd-500/             .vbox-fatih-ipc/      .X11-unix/

Dizini de taşımak için

 
[root@fatihoz ~]# rsync -azvh --progress deneme  /tmp/
sending incremental file list
deneme/
deneme/1.txt
           0 100%    0.00kB/s    0:00:00 (xfer#1, to-check=3/5)
deneme/12233434543.txt
           0 100%    0.00kB/s    0:00:00 (xfer#2, to-check=2/5)
deneme/122343.txt
           0 100%    0.00kB/s    0:00:00 (xfer#3, to-check=1/5)
deneme/123.txt
           0 100%    0.00kB/s    0:00:00 (xfer#4, to-check=0/5)

sent 261 bytes  received 92 bytes  706.00 bytes/sec
total size is 0  speedup is 0.00
[root@fatihoz ~]# ls /tmp/deneme/
12233434543.txt  122343.txt  123.txt  1.txt

Uzakdaki bilgisayara dosya göndermek için:

[root@fatihoz ~]# rsync -avh --progress /home/fatih/1G.file  root@localhost:/tmp/
The authenticity of host 'localhost (::1)' can't be established.
RSA key fingerprint is a8:6a:b1:43:9b:33:e4:78:cc:d0:ee:9d:e0:c2:0e:fe.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'localhost' (RSA) to the list of known hosts.
root@localhost's password: 
sending incremental file list
1G.file
       1.02G 100%   23.49MB/s    0:00:41 (xfer#1, to-check=0/1)

sent 1.02G bytes  received 31 bytes  21.12M bytes/sec
total size is 1.02G  speedup is 1.00

find İle Dosya Adi Yakalama

Ocak 2, 2014 § Yorum yok § Kalıcı bağlantı

“{}” veya “-I” ya girilen parametre

[fatih@fatihoz deneme]$ find . -iname "*.txt" -print0 | xargs -0 -I {} cat {}

veya

[fatih@fatihoz deneme]$ find . -iname "*.txt" -print0 | xargs -0 -I match_file mv match_file ./yeni_klasor/

[fatih@fatihoz deneme]$ ls -laR
.:
total 12
drwxrwxr-x.  3 fatih fatih 4096 Jan  2 06:58 .
drwx------. 46 fatih fatih 4096 Jan  2 06:42 ..
drwxrwxr-x.  2 fatih fatih 4096 Jan  2 06:58 yeni_klasor

./yeni_klasor:
total 24
drwxrwxr-x. 2 fatih fatih 4096 Jan  2 06:58 .
drwxrwxr-x. 3 fatih fatih 4096 Jan  2 06:58 ..
-rw-rw-r--. 1 fatih fatih   13 Jan  2 06:42 112.txt
-rw-rw-r--. 1 fatih fatih   18 Jan  2 06:42 1345.txt
-rw-rw-r--. 1 fatih fatih   25 Jan  2 06:42 1.txt
-rw-rw-r--. 1 fatih fatih   29 Jan  2 06:42 456.txt

find ve xargs ile ” ” İçeren Dosyalarda Çalışmak

Ocak 2, 2014 § Yorum yok § Kalıcı bağlantı

Boşluk karakteri içeren dosya isimlerini yakalayabilmek için
find’da “-print0”, xargs’de “-0” parametreleri kullanılmalıdır.

[fatih@fatihoz deneme]$ ls -la
total 12
drwxrwxr-x.  2 fatih fatih 4096 Jan  2 06:25 .
drwx------. 46 fatih fatih 4096 Jan  2 06:13 ..
-rw-rw-r--.  1 fatih fatih    0 Jan  2 06:25 123123123.txt
-rw-rw-r--.  1 fatih fatih    0 Jan  2 06:25 123.txt
-rw-rw-r--.  1 fatih fatih    9 Jan  2 06:11 ali veli.txt
-rw-rw-r--.  1 fatih fatih    0 Jan  2 06:25 asdasd.txt

find "print" ile boşluk karakterli dosyaları yakalasa da çalışmaya olanak vermiyor
[fatih@fatihoz deneme]$ find . -name "*.txt" -print| cat
./ali veli.txt
./123.txt
./asdasd.txt
./123123123.txt
[fatih@fatihoz deneme]$ find . -name "*.txt" -print| xargs cat
cat: ./ali: No such file or directory
cat: veli.txt: No such file or directory

[fatih@fatihoz deneme]$ find . -name "*.txt" -print| xargs rm -rf
[fatih@fatihoz deneme]$ ls -la
total 12
drwxrwxr-x.  2 fatih fatih 4096 Jan  2 06:28 .
drwx------. 46 fatih fatih 4096 Jan  2 06:13 ..
-rw-rw-r--.  1 fatih fatih    9 Jan  2 06:11 ali veli.txt

Doğru kullanımı:
[fatih@fatihoz deneme]$ find . -name "*.txt" -print0 | xargs -0 rm -rf
[fatih@fatihoz deneme]$ ls
[fatih@fatihoz deneme]$ 



-print0’ın açıklamasi

-print0
True; print the full file name on the standard output, followed by a null character (instead of
the newline character that -print uses). This allows file names that contain newlines or other
types of white space to be correctly interpreted by programs that process the find output. This
option corresponds to the -0 option of xargs.

Xargs Kullanımı

Ocak 2, 2014 § Yorum yok § Kalıcı bağlantı

Xargs stdin’den input alıp bunu stdout’a echo ile basar.
ctrl-d ile stdout’a sonuc basılabilir.
xargs komutunun newline karakterlerini gözardı etmesine dikkat edelim.

[fatih@fatihoz ~]$ xargs 
deneme1
deneme2
yeni satır1
deneme1 deneme2 yeni satır1

“-t” parametresi ile xargs’in echo çağırdığı görülebilir:

[fatih@fatihoz ~]$ xargs -t
deneme satırı
/bin/echo deneme satırı 
deneme satırı

find ile xargs kullanımı

find ile bulduğumuz dosya isimlerini xargs’e input girip echo dışında iş yürütebiliriz.
Örn:


xargs’nin stdinden input alması ile ilgili bir diğer örnek:

[fatih@fatihoz ~]$ echo a b c d e | xargs
a b c d e

xargs’nin stdout’a bastığı çıktının bir satırda kaç adet olacağı “-n” parametresi ile verilebilir:

[fatih@fatihoz ~]$ echo 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | xargs -n 3
1 2 3
4 5 6
7 8 9
10 11 12
13 14 15
16 17
[fatih@fatihoz ~]$ echo 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | xargs -n 4
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
17

“-p” parametresi ile kullanicinin doğrulaması sağlanabilir:

[fatih@fatihoz ~]$ echo 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | xargs -p -n 4
/bin/echo 1 2 3 4 ?...y
/bin/echo 5 6 7 8 ?...1 2 3 4
y
/bin/echo 9 10 11 12 ?...5 6 7 8
y
/bin/echo 13 14 15 16 ?...9 10 11 12
y
/bin/echo 17 ?...13 14 15 16
y
17

find ile bulduğumuz dosya isimlerini xargs’ye sokabiliriz
Örn:

Dosya içeriklerine bakalım
[fatih@fatihoz deneme]$ grep . *
1.txt:Birinci dosyanin baslangici
1.txt:123123123123 123 12 3 12 31 23 1 2312 3 123 
1.txt:123
1.txt:12
1.txt:3
1.txt:12
1.txt:3
1.txt:12312312432454
1.txt:5
1.txt:3
1.txt:45
1.txt:34
1.txt:5
2.txt:İkinci dosyanin baslangici
2.txt:12312  5345 anan3 12312345
2.txt:34
2.txt:5

txt dosyalarda "dosyanin" metnini arayalim
[fatih@fatihoz deneme]$ find . -name "*.txt"| xargs grep "dosyanin"
./2.txt:İkinci dosyanin baslangici
./1.txt:Birinci dosyanin baslangici

txt dosyalarini silelim
[fatih@fatihoz deneme]$ find . -name "*.txt"| xargs rm -rf  

Neredeyim ben!?

Ocak, 2014 arşivinde geziniyorsun.