mirror of
https://github.com/LCTT/TranslateProject.git
synced 2025-01-13 22:30:37 +08:00
Merge pull request #12075 from MjSeven/20190114
翻译完成 20190114 How to move multiple...
This commit is contained in:
commit
693caa1726
@ -1,96 +0,0 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (MjSeven)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (How To Move Multiple File Types Simultaneously From Commandline)
|
||||
[#]: via: (https://www.ostechnix.com/how-to-move-multiple-file-types-simultaneously-from-commandline/)
|
||||
[#]: author: (SK https://www.ostechnix.com/author/sk/)
|
||||
|
||||
How To Move Multiple File Types Simultaneously From Commandline
|
||||
======
|
||||
|
||||
![](https://www.ostechnix.com/wp-content/uploads/2019/01/Move-Multiple-File-Types-720x340.png)
|
||||
|
||||
The other day I was wondering how can I move (not copy) multiple file types from directory to another. I already knew how to [**find and copy certain type of files from one directory to another**][1]. But, I don’t know how to move multiple file types simultaneously. If you’re ever in a situation like this, I know a easy way to do it from commandline in Unix-like systems.
|
||||
|
||||
### Move Multiple File Types Simultaneously
|
||||
|
||||
Picture this scenario.You have multiple type of files, for example .pdf, .doc, .mp3, .mp4, .txt etc., on a directory named **‘dir1’**. Let us take a look at the dir1 contents:
|
||||
|
||||
```
|
||||
$ ls dir1
|
||||
file.txt image.jpg mydoc.doc personal.pdf song.mp3 video.mp4
|
||||
```
|
||||
|
||||
You want to move some of the file types (not all of them) to different location. For example, let us say you want to move doc, pdf and txt files only to another directory named **‘dir2’** in one go.
|
||||
|
||||
To copy .doc, .pdf and .txt files from dir1 to dir2 simultaneously, the command would be:
|
||||
|
||||
```
|
||||
$ mv dir1/*.{doc,pdf,txt} dir2/
|
||||
```
|
||||
|
||||
It’s easy, isn’t it?
|
||||
|
||||
Now, let us check the contents of dir2:
|
||||
|
||||
```
|
||||
$ ls dir2/
|
||||
file.txt mydoc.doc personal.pdf
|
||||
```
|
||||
|
||||
See? Only the file types .doc, .pdf and .txt from dir1 have been moved to dir2.
|
||||
|
||||
![][3]
|
||||
|
||||
You can add as many file types as you want to inside curly braces in the above command to move them across different directories. The above command just works fine for me on Bash.
|
||||
|
||||
Another way to move multiple file types is go to the source directory i.e dir1 in our case:
|
||||
|
||||
```
|
||||
$ cd ~/dir1
|
||||
```
|
||||
|
||||
And, move file types of your choice to the destination (E.g dir2) as shown below.
|
||||
|
||||
```
|
||||
$ mv *.doc *.txt *.pdf /home/sk/dir2/
|
||||
```
|
||||
|
||||
To move all files having a particular extension, for example **.doc** only, run:
|
||||
|
||||
```
|
||||
$ mv dir1/*.doc dir2/
|
||||
```
|
||||
|
||||
For more details, refer man pages.
|
||||
|
||||
```
|
||||
$ man mv
|
||||
```
|
||||
|
||||
Moving a few number of same or different file types is easy! You could do this with couple mouse clicks in GUI mode or use a one-liner command in CLI mode. However, If you have thousands of different file types in a directory and wanted to move multiple file types to different directory in one go, it would be a cumbersome task. To me, the above method did the job easily! If you know any other one-liner commands to move multiple file types at a time, please share it in the comment section below. I will check and update the guide accordingly.
|
||||
|
||||
And, that’s all for now. Hope this was useful. More good stuffs to come. Stay tuned!
|
||||
|
||||
Cheers!
|
||||
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.ostechnix.com/how-to-move-multiple-file-types-simultaneously-from-commandline/
|
||||
|
||||
作者:[SK][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://www.ostechnix.com/author/sk/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://www.ostechnix.com/find-copy-certain-type-files-one-directory-another-linux/
|
||||
[2]: data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7
|
||||
[3]: http://www.ostechnix.com/wp-content/uploads/2019/01/mv-command.gif
|
@ -0,0 +1,93 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (MjSeven)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (How To Move Multiple File Types Simultaneously From Commandline)
|
||||
[#]: via: (https://www.ostechnix.com/how-to-move-multiple-file-types-simultaneously-from-commandline/)
|
||||
[#]: author: (SK https://www.ostechnix.com/author/sk/)
|
||||
|
||||
如何从命令行同时移动多种文件类型
|
||||
======
|
||||
|
||||
![](https://www.ostechnix.com/wp-content/uploads/2019/01/Move-Multiple-File-Types-720x340.png)
|
||||
|
||||
前几天,我想知道如何将多个文件类型从一个目录移动(不复制)到另一个目录。我已经知道如何[**查找并将某些类型的文件从一个目录复制到另一个目录**][1]。但是,我不知道如何同时移动多种文件类型。如果你曾遇到这样的情况,我知道在类 Unix 系统中从命令行执行该操作的一个简单方法。
|
||||
|
||||
### 同时移动多种文件类型
|
||||
|
||||
想象一下这种场景,你在名为 **‘dir1’** 的目录中有多种类型的文件,例如 .pdf, .doc, .mp3, .mp4, .txt 等等。我们来看看 dir1 的内容:
|
||||
|
||||
```
|
||||
$ ls dir1
|
||||
file.txt image.jpg mydoc.doc personal.pdf song.mp3 video.mp4
|
||||
```
|
||||
|
||||
你希望将某些文件类型(不是所有文件类型)移动到另一个位置。例如,假设你想将 doc, pdf 和 txt 文件一次性移动到名为 **‘dir2’** 的另一个目录中。
|
||||
|
||||
要同时将 .doc, .pdf 和 .txt 文件从 dir1 移动到 dir2,命令是:
|
||||
|
||||
```
|
||||
$ mv dir1/*.{doc,pdf,txt} dir2/
|
||||
```
|
||||
|
||||
很容易,不是吗?
|
||||
|
||||
现在让我们来查看一下 dir2 的内容:
|
||||
```
|
||||
$ ls dir2/
|
||||
file.txt mydoc.doc personal.pdf
|
||||
```
|
||||
|
||||
看到了吗?只有 .doc, .pdf 和 .txt 从 dir1 移到了 dir2。
|
||||
|
||||
![][3]
|
||||
|
||||
在上面的命令中,你可以在花括号内添加任意数量的文件类型,以将它们移动到不同的目录中。它在 Bash 上非常适合我。
|
||||
|
||||
另一种移动多种文件类型的方法是转到源目录,在我们的例子中即为 dir1:
|
||||
|
||||
```
|
||||
$ cd ~/dir1
|
||||
```
|
||||
|
||||
将你选择的文件类型移动到目的地(即 dir2),如下所示:
|
||||
|
||||
```
|
||||
$ mv *.doc *.txt *.pdf /home/sk/dir2/
|
||||
```
|
||||
|
||||
要移动具有特定扩展名的所有文件,例如 **.doc**,运行:
|
||||
|
||||
```
|
||||
$ mv dir1/*.doc dir2/
|
||||
```
|
||||
|
||||
更多细节,参考 man 页:
|
||||
|
||||
```
|
||||
$ man mv
|
||||
```
|
||||
|
||||
移动一些相同或不同的文件类型很容易!你可以在 GUI 模式下单击几下鼠标,或在 CLI 模式下使用一行命令来完成。但是,如果目录中有数千种不同的文件类型,并且希望一次将多种文件类型移动到不同的目录,这将是一项繁琐的任务。对我来说,上面的方法很容易完成工作!如果你知道任何其它一行命令可以一次移动多种文件类型,请在下面的评论部分与我们分享。我会核对并更新指南。
|
||||
|
||||
这些就是全部了,希望这很有用。更多好东西将要来了,敬请关注!
|
||||
|
||||
共勉!
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.ostechnix.com/how-to-move-multiple-file-types-simultaneously-from-commandline/
|
||||
|
||||
作者:[SK][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[MjSeven](https://github.com/MjSeven)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://www.ostechnix.com/author/sk/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://www.ostechnix.com/find-copy-certain-type-files-one-directory-another-linux/
|
||||
[2]: data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7
|
||||
[3]: http://www.ostechnix.com/wp-content/uploads/2019/01/mv-command.gif
|
Loading…
Reference in New Issue
Block a user