博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
linux基本命令示例_Linux mv命令用法和示例
阅读量:2532 次
发布时间:2019-05-11

本文共 3368 字,大约阅读时间需要 11 分钟。

linux基本命令示例

In this guide, you will learn how to use the Linux/Unix mv command. Linux mv command has 2 distinct functionalities depending on how it’s used.

在本指南中,您将学习如何使用Linux / Unix mv命令。 Linux mv命令根据其用法有2种不同的功能。

  1. It can be used to rename a file or a folder

    可用于重命名文件或文件夹
  2. It can be used for moving a file or a folder from one location to another

    它可用于将文件或文件夹从一个位置移动到另一位置

使用mv命令重命名文件或目录 (Using mv command to rename a file or a directory)

To rename a file using mv, the 2 files (The original and renamed file) must be in the same location

The syntax for renaming a file or a directory is as follows

要使用mv重命名文件,两个文件(原始文件和重命名文件)必须位于同一位置

重命名文件或目录的语法如下

# mv file_name new_file_name

For example, I have a file called linux-for-beginners and I want to rename it to unix-for-beginners

例如,我有一个名为linux-for-beginners的文件,我想将其重命名为unix-for-beginners

# mv linux-for-beginners unix-for-beginners

You can further verify that the file has been renamed using the ls command. The output is shown below

您可以使用ls命令进一步验证文件是否已重命名。 输出如下所示

As observed, the original file has been renamed. The command and syntax remain the same for directories.

如图所示,原始文件已被重命名。 目录的命令和语法保持不变。

使用mv移动文件或目录 (Using mv to move a file or a directory)

Having looked at how to rename a file /directory, let’s see how you can move a file from one directory to another.

看了如何重命名文件/目录后,让我们看看如何将文件从一个目录移动到另一个目录。

The syntax for this is as follows

语法如下

# mv [option] file /path/to/destination/directory

For example , to move the file unix-for-beginners to the /opt directory, run

例如,要将文件unix-for-beginners移至/opt目录,请运行

$ mv unix-for-beginners /opt

The syntax remains the same for moving directories. In the example below , the directory tutorials is being moved to /opt directory

移动目录的语法相同。 在下面的示例中,目录tutorials被移至/opt目录

mv命令选项 (mv command options)

The mv command can be accompanied by a variety of options. Let’s have a look

mv命令可以带有多种选项。 我们来看一下

-i(交互式) (-i (Interactive))

This option prompts the user for confirmation before moving a file that would overwrite a pre-existing file with the same name. In this case, the user must press y to confirm or overwrite.

此选项会提示用户进行确认,然后再移动将覆盖同名现有文件的文件。 在这种情况下,用户必须按y确认或覆盖。

Sample output

样品输出

-n(无弹性) (-n (no-clobber))

The -n option prevents a file from being overwritten. That is , you can rename a file to match another file and still keep the contents of the pre-existing file. In this example, we have 2 files file1.txt and file2.txt. We are going to rename file1.txt to file2.txt using the -n attribute but still retain the contents of file2.txt

-n选项可防止文件被覆盖。 即,您可以重命名文件以匹配另一个文件,并且仍然保留先前存在的文件的内容。 在此示例中,我们有2个文件file1.txtfile2.txt 。 我们将使用-n属性将file1.txt重命名为file2.txt ,但仍保留file2.txt的内容

Sample output

样品输出

-v(详细) (-v (verbose))

the -v option displays the status of the activity taking place when mv is running. The output of the activity is printed on the terminal as shown

-v选项显示mv运行时活动的状态。 活动的输出显示在终端上,如图所示

Sample output

样品输出

-u(更新) (-u (update))

The -u option updates the destination file only if the source file has newer content or the destination file is missing.

-u选项仅在源文件具有较新内容或缺少目标文件时更新目标文件。

检查mv命令的版本 (Checking version of mv command)

To check the version of mv run the command

要检查mv的版本,请运行以下命令

$ mv --version

Sample output

样品输出

获得有关mv命令的帮助 (Getting help with mv command)

For more mv command options run the command

有关更多的mv命令选项,请运行命令

$ mv --help

Sample output

样品输出

翻译自:

linux基本命令示例

转载地址:http://onlzd.baihongyu.com/

你可能感兴趣的文章
mysql 日期时间运算函数(转)
查看>>
初识前端作业1
查看>>
ffmpeg格式转换命令
查看>>
万方数据知识平台 TFHpple +Xpath解析
查看>>
Hive实现oracle的Minus函数
查看>>
秒杀多线程第四篇 一个经典的多线程同步问题
查看>>
RocketMQ配置
查看>>
vs code调试console程序报错--preLaunchTask“build”
查看>>
蚂蚁金服井贤栋:用技术联手金融机构,形成服务小微的生态合力
查看>>
端口号大全
查看>>
机器学习基石笔记2——在何时可以使用机器学习(2)
查看>>
POJ 3740 Easy Finding (DLX模板)
查看>>
MySQL 处理重复数据
查看>>
关于typedef的用法总结(转)
查看>>
【strtok()】——分割字符串
查看>>
Linux下安装rabbitmq
查看>>
曹德旺
查看>>
【转】判断点在多边形内(matlab)
查看>>
java基础之集合:List Set Map的概述以及使用场景
查看>>
Python 线程 进程 协程
查看>>