Unix移动复制mv cp

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 -i oldname 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 -i newhw/hw1 oldhw

If, in this last operation, you also wanted to give the file a new name, such as firsthw, you would enter:

mv -i newhw/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 -i oldfile 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 -i oldfile ~/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.


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值