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

样品输出

翻译自: https://www.journaldev.com/28520/linux-mv-command-usage-with-examples

linux基本命令示例

linux基本命令示例_Linux mv命令用法和示例相关推荐

  1. 超详细linux基本命令学习以及hdfs命令详解

    前言: 本人刚接触linux不久但是就是这不久的接触使我爱上了linux的脚本 linux脚本就几十个基本命令但是就是这几十个基本命令经过简单的组合后可以创造出实现各种功能的强大命令如:同样是处理数据 ...

  2. Linux之cp和mv命令选项

    Linux之cp和mv命令选项 1. cp命令选项 命令选项 说明 -i 交互式提示 -r 递归拷贝目录及其内容 -v 显示拷贝后的路径描述 -a 保留文件的原有权限 cp -i命令选项效果图: cp ...

  3. 为Linux的cp和mv命令添加进度条

    为Linux的cp和mv命令添加进度条 cp和mv可能是大家日常中使用最多的Linux命令之一.但是有一个突出的问题是这两个命令都不会有任何提示信息,这在操作大文件时候只能干等.可能大家对此已经习以为 ...

  4. linux基本命令示例_Linux ps命令– 20个真实示例

    linux基本命令示例 The ps command, short for Process Status, is a command line utility that is used to disp ...

  5. linux的yum命令无法使用在哪里下载_Linux 知识分享:为Linux的cp和mv命令添加进度条...

    cp和mv可能是大家日常中使用最多的Linux命令之一.但是有一个突出的问题是这两个命令都不会有任何提示信息,这在操作大文件时候只能干等.可能大家对此已经习以为常,但是其实上也有解决解决方法,本文我们 ...

  6. linux mv 非空文件夹,Linux基本命令——cp、mv、rm、tree、mkdir、rmdir

    cp:复制文件和目录 语法: cp [OPTION]... [-T] SOURCE DEST cp [OPTION]... SOURCE... DIRECTORY cp [OPTION]... -t ...

  7. find linux 指定后缀_Linux终端命令入坑必备知识与技巧

    才接触Linux系统,一些概念简直是一头雾水,那么本文的目的就是在Linux中使用终端输入命令时,常见的一些概念及技巧. 1 什么是主目录(home directory)?Linux是一个典型的多用户 ...

  8. linux cp源码_为Linux的cp和mv命令添加进度条

    cp和mv可能是大家日常中使用最多的Linux命令之一.但是有一个突出的问题是这两个命令都不会有任何提示信息,这在操作大文件时候只能干等.可能大家对此已经习以为常,但是其实上也有解决解决方法,本文我们 ...

  9. linux 修改文件名_Linux常用命令

    Linux下一切皆文件 查看型 ls 查看当前文件夹内容 选项 -a 查看隐藏文件 -l 查看文件详细信息 pwd 查看当前所在路径 su 切换用户 cat /etc/passwd 查看当前系统的用户 ...

最新文章

  1. dos下命令行执行程序时候注意程序所使用文件的路径问题
  2. oracle中before,Oracle中Before和After触发器的例子
  3. 计算机视觉进展二十年 (1995~2015)
  4. windows server 2003 安装显卡驱动
  5. leetcode(3)——414. 第三大的数(C++中的 set,::作用符号,迭代器),628 三个数的最大乘积(sort函数的用法)
  6. Java学习笔记之:Java String类
  7. “约见”面试官系列之常见面试题之第八十二篇之MVC(建议收藏)
  8. Docker容器硬盘热扩容-centos6
  9. 字典排序什么意思_字典排序问题
  10. matlab中ahp方法,AHP及matlab程序.doc
  11. VC++六种Runtime Library
  12. 如何利用视频做动图?视频转gif动图
  13. 解读《大话西游之大圣娶亲》
  14. 移动 APP 的测试方法,以及移动专项测试的思路与方法
  15. Civil 3d-快速转换C3D图形为CAD图形
  16. python实现采样函数_PR Sampling Ⅰ: 蒙特卡洛采样、重要性采样及python实现
  17. 共探万物智联新模式,第二届中国通信业物联网大会成功召开
  18. python 词云图 WordCloud
  19. TABLE functions
  20. Android界面刷新

热门文章

  1. linux命令存放 bash: xxx command not found
  2. 【接口测试】FitNesse中文指南
  3. Perl 学习笔记-输入输出
  4. MyEclipse常用设置方法
  5. [转载] Python集合取交集intersection()函数和intersection_update()函数
  6. [转载] Python图结构(复杂网络)可视化模块——networkx
  7. [转载] 如何使用 Python 生成酷炫的二维码?
  8. [转载] Java获取嵌套的json串里的返回结果
  9. [转载] java调用c++的dll及java.lang.UnsatisfiedLinkError解决方法
  10. JavaScript错误和异常