您的位置:首页 > 其它

Unix移动复制mv cp

2011-07-25 20:28 323 查看

mv

This command will move a file. You can use
mv
not only to change the directory location of a file, but also to rename files. Unlike the
cp
command,
mv
will not preserve the original file.
Note: As with the
cp
command, you should always use
-i
to make sure you do not overwrite an existing file.
To rename a file named
oldname
in the current directory to the new name
newname
, enter:
mv-ioldname newname To move a file named
hw1
from a subdirectory named
newhw
to another subdirectory named
oldhw
(both subdirectories of the current directory), enter:
mv-inewhw/hw1 oldhwIf, in this last operation, you also wanted to give the file a new name, such as
firsthw
, you would enter:
mv-inewhw/hw1 oldhw/firsthw

cp

This command copies a file, preserving the original and creating an identical copy. If you already have a file with the new name,
cp
will overwrite and destroy the duplicate. For this reason, it's safest to always add
-i
after the
cp
command, to force the system to ask for your approval before it destroys any files. The general syntax for
cp
is:
cp-ioldfile newfile To copy a file named
meeting1
in the directory
/home/dvader/notes
to your current directory, enter:
cp-i/home/dvader/notes/meeting1.The
.
(period) indicates the current directory as destination, and the
-i
ensures that if there is another file named
meeting1
in the current directory, you will not overwrite it by accident.
To copy a file named
oldfile
in the current directory to the new name
newfile
in the
mystuff
subdirectory of your home directory, enter:
cp-ioldfile ~/mystuff/newfile The
~
character (tilde) is interpreted as the path of your home directory.
Note: You must have permission to read a file in order to copy it.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: