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

Ocak 2nd, 2014 § Yorum yok

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.

Bir cevap yazın

E-posta hesabınız yayımlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir

Ne yapıyorum ben!?

find ve xargs ile ” ” İçeren Dosyalarda Çalışmak başlıklı yazıyı okuyorsun.

Üst Veri