Linux命令将所有文件从var/A移动到var/
我猜这里有人问过这个问题,但我没找到 我在目录var/上,我有一个文件夹var/a,里面有一些文件,我想要的是将a中的这些文件移动到var/。所以我想做的是: 发件人: 致: 在/var中,我尝试了以下命令Linux命令将所有文件从var/A移动到var/,linux,ubuntu,command-line,path,mv,Linux,Ubuntu,Command Line,Path,Mv,我猜这里有人问过这个问题,但我没找到 我在目录var/上,我有一个文件夹var/a,里面有一些文件,我想要的是将a中的这些文件移动到var/。所以我想做的是: 发件人: 致: 在/var中,我尝试了以下命令 sudo mv A/ sudo mv A/ sudo mv A/ 没有人工作过。提前谢谢你我设法复制了你的情况 . └── var ├── A │ ├── file1.txt │ └── file2.txt └── file3.txt 2 direc
sudo mv A/
sudo mv A/
sudo mv A/
没有人工作过。提前谢谢你我设法复制了你的情况
.
└── var
├── A
│ ├── file1.txt
│ └── file2.txt
└── file3.txt
2 directories, 3 files
user@host:~/soQ$ mv var/A/*.txt var/ && rm -rf var/A/
user@host:~/soQ$ tree
.
└── var
├── file1.txt
├── file2.txt
└── file3.txt
希望这有帮助
如果您想从var
执行此操作,只需执行mva/*.txt.&&rm-射频A/
另外,假设您的目录中有以下结构
.
├── A
│ ├── file3.txt
│ └── folder1
│ ├── file1.txt
│ └── file2.txt
└── file4.txt
如果您只想复制var中的*.txt
文件,则需要使用如下查找:
find./A/*-type f-exec mv{}${PWD}\;&&rm A
这将查看所有文件和文件夹并返回每个文件(例如每个.txt)的路径,然后在每行上执行
mv
,并将文件移动到当前目录(${PWD}
) 我找到了答案:
mva/*。
我希望它能帮助其他人您必须指定正确的路径或匹配 如果你想移动整个文件或目录,你必须做些什么 像这样使用*(通配符)
user@akuma:~/var$mv./A/*./
您可以在终端中键入mv--help
,了解更多信息,以查看下面的更多选项
user@akuma:~/WORKSPACE/Trash$ mv --help
Usage: mv [OPTION]... [-T] SOURCE DEST
or: mv [OPTION]... SOURCE... DIRECTORY
or: mv [OPTION]... -t DIRECTORY SOURCE...
Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORY.
Mandatory arguments to long options are mandatory for short options too.
--backup[=CONTROL] make a backup of each existing destination file
-b like --backup but does not accept an argument
-f, --force do not prompt before overwriting
-i, --interactive prompt before overwrite
-n, --no-clobber do not overwrite an existing file
If you specify more than one of -i, -f, -n, only the final one takes effect.
--strip-trailing-slashes remove any trailing slashes from each SOURCE
argument
-S, --suffix=SUFFIX override the usual backup suffix
-t, --target-directory=DIRECTORY move all SOURCE arguments into DIRECTORY
-T, --no-target-directory treat DEST as a normal file
-u, --update move only when the SOURCE file is newer
than the destination file or when the
destination file is missing
-v, --verbose explain what is being done
-Z, --context set SELinux security context of destination
file to default type
--help display this help and exit
--version output version information and exit
The backup suffix is '~', unless set with --suffix or SIMPLE_BACKUP_SUFFIX.
The version control method may be selected via the --backup option or through
the VERSION_CONTROL environment variable. Here are the values:
none, off never make backups (even if --backup is given)
numbered, t make numbered backups
existing, nil numbered if numbered backups exist, simple otherwise
simple, never always make simple backups
GNU coreutils online help: <http://www.gnu.org/software/coreutils/>
Full documentation at: <http://www.gnu.org/software/coreutils/mv>
or available locally via: info '(coreutils) mv invocation'
user@akuma:~/WORKSPACE/Trash$mv--帮助
用法:mv[选项]。。。[-T]源目标
或:mv[选项]。。。来源。。。目录
或:mv[选项]-t目录源。。。
将源重命名为DEST,或将源移动到目录。
长选项的强制性参数对于短选项也是强制性的。
--备份[=控制]对每个现有目标文件进行备份
-b喜欢--backup,但不接受参数
-f、 --强制在覆盖前不提示
-i、 --覆盖前的交互式提示
-n、 --无clobber不覆盖现有文件
如果指定了-i、-f、-n中的多个,则只有最后一个生效。
--去除尾部斜线从每个源中删除任何尾部斜线
论点
-S、 --suffix=后缀覆盖通常的备份后缀
-t、 --target directory=目录将所有源参数移动到目录中
-T、 --没有目标目录将DEST视为普通文件
-u、 --仅当源文件较新时更新移动
而不是目标文件,或者
缺少目标文件
-v、 ——详细解释正在做的事情
-Z、 --上下文设置目标的SELinux安全上下文
文件设置为默认类型
--帮助显示此帮助并退出
--版本输出版本信息并退出
除非使用--suffix或SIMPLE\u backup\u后缀设置,否则备份后缀为“~”。
版本控制方法可以通过--backup选项或通过
版本控制环境变量。以下是数值:
无,关闭从不进行备份(即使提供了--backup)
有编号的,不做有编号的备份
现有,如果存在编号备份,则编号为零,否则为简单
简单,永远不要做简单的备份
GNU coreutils联机帮助:
完整文档位于:
或通过:info'(coreutils)mv调用本地提供
这是一个小例子,在一个“我有更多的文件和文件夹”中,无论有多少文件,您都应用相同的逻辑。另外,我假设您的所有文件都是.txt
类型。如果要复制所有内容,只需将*.txt
替换为*
。我看到你说你也有文件夹。让我试试看它是否能像我认为的那样工作。你想复制文件夹还是只复制每个文件夹中的文件?如果你也有文件夹,mv也能工作(它会复制文件夹)。如果只想复制文件,请尝试此操作<代码>查找./A/*-type f-exec mv{}${PWD}\代码>堆栈溢出是一个关于编程和开发问题的网站。这个问题似乎离题了,因为它与编程或开发无关。请参见帮助中心中的。也许或者会是一个更好的提问的地方。
.
├── A
│ ├── file3.txt
│ └── folder1
│ ├── file1.txt
│ └── file2.txt
└── file4.txt
user@akuma:~/WORKSPACE/Trash$ mv --help
Usage: mv [OPTION]... [-T] SOURCE DEST
or: mv [OPTION]... SOURCE... DIRECTORY
or: mv [OPTION]... -t DIRECTORY SOURCE...
Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORY.
Mandatory arguments to long options are mandatory for short options too.
--backup[=CONTROL] make a backup of each existing destination file
-b like --backup but does not accept an argument
-f, --force do not prompt before overwriting
-i, --interactive prompt before overwrite
-n, --no-clobber do not overwrite an existing file
If you specify more than one of -i, -f, -n, only the final one takes effect.
--strip-trailing-slashes remove any trailing slashes from each SOURCE
argument
-S, --suffix=SUFFIX override the usual backup suffix
-t, --target-directory=DIRECTORY move all SOURCE arguments into DIRECTORY
-T, --no-target-directory treat DEST as a normal file
-u, --update move only when the SOURCE file is newer
than the destination file or when the
destination file is missing
-v, --verbose explain what is being done
-Z, --context set SELinux security context of destination
file to default type
--help display this help and exit
--version output version information and exit
The backup suffix is '~', unless set with --suffix or SIMPLE_BACKUP_SUFFIX.
The version control method may be selected via the --backup option or through
the VERSION_CONTROL environment variable. Here are the values:
none, off never make backups (even if --backup is given)
numbered, t make numbered backups
existing, nil numbered if numbered backups exist, simple otherwise
simple, never always make simple backups
GNU coreutils online help: <http://www.gnu.org/software/coreutils/>
Full documentation at: <http://www.gnu.org/software/coreutils/mv>
or available locally via: info '(coreutils) mv invocation'