4 Nisan 2019 Perşembe

mv komutu - Dosya taşır

Giriş
move anlamına gelir. copy komutu taşıma yerine kopyalama için kullanılabilir.

Söz dizimi şöyledir.
mv filedestination_dir
Açıklaması şöyle.
mv is a standard utility to move one or more files to a given target. It can be used to rename a file, if there's only one file to move. If there are several, mv only works if the target is directory, and moves the files there.

So mv foo bar will either move the file foo to the directory bar (if it exists), or rename foo to bar (if bar doesn't exist or isn't a directory). mv foo1 foo2 bar will just move both files to directory bar, or complain if bar isn't a directory.

mv will call the rename() C library function to move the files, and if that doesn't work (they're being moved to another filesystem), it will copy the files and remove the originals.
Neden mv Komutunda -r (recursive) seçeneği Yok?
Bir soru şöyle. Yani mv komutu tek bir şeyi taşır. Dolayısıyla recursive olmasına gerek yok
Q : Why does 'mv' not need '-r' to work with directories, but 'rm' and 'cp' do?
A : 
 rm has to recurse into the directory ...
 cp has to recurse into the directory ...
 mv just has to do a single call 
Örnek - rename
.txt dosyalarını .txt.old olarak yeniden ismlendirmek için şöyle yaparız.
mv dir1/dir2/dir3/file.{txt,txt.old}
-- seçeneği
Bu özel bir seçenek. Şu anlama geliyor. Eğer dosya isimlerinde de "-" karakteri varsa bu isimler seçenek gibi algılanabiliyor. "--" seçeneğiyle artık yeni seçeneklerin kabul edilmemesi sağlanıyor. Açıklaması şöyle
Most command-line utilities have a provision to separate options from arguments.

That prevents a multitude of problems with "special" file names that look like options.

The most common separator indication the end of the options is two hyphens -- or -- which is also supported by mv.
Örnek
Soru şöyle
Here is my problem :
i have a file with -r in the name :
-r.jpg

when i tried to do a :
mv *.jpg old/

i have a :
mv: invalid option -- 'r'
Cevabı şöyle
mv -- *.jpg old/
-t seçeneği
target directory anlamına gelir. Şeklen şöyledir.
mv -t destination_dir  file
Örnek
Tüm dosyaları farklı bir dizine taşımak için şöyle yaparız
printf '%s\0' files/* | xargs -0 mv -t new_files_dir
Örnek
mp3 dosyalarını bir üst dizine taşımak için şöyle yaparız.
find . -path "*/flac/*" -name '*.mp3' -execdir mv -t ../ {} +

Hiç yorum yok:

Yorum Gönder