我想这个问题已经在这里问过了,但我没有找到。
我在目录 var/并且我有一个文件夹 var/A 里面有一些文件,我想要的是将 A 中的这个文件移动到 var/。 所以我想做的是:
从:
var
├── A
| ├── file1.txt
| └── file2.txt
└── file3.txt
自:
var
├── file1.txt
├── file2.txt
└── file3.txt
在/var 中,我尝试了以下命令
sudo mv A /
sudo mv A/ ./
sudo mv A/ .
没有人工作过。提前谢谢你
我找到了答案:
mv A/* .
我希望它可以帮助另一个人
您必须指定正确的路径或匹配项 如果要移动整个文件或目录,则必须移动到某些内容 像这样使用 *(通配符(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'
我设法复制了你的情况。
.
└── 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
执行此操作,只需执行mv A/*.txt . && rm -rf A/
另外,假设您的目录中有以下结构。
.
├── A
│ ├── file3.txt
│ └── folder1
│ ├── file1.txt
│ └── file2.txt
└── file4.txt
如果你只想复制 var 中的*.txt
文件,你需要像这样使用 find:
find ./A/* -type f -exec mv {} ${PWD} ; && rm A
这将查看所有文件和文件夹并返回每个文件的路径(例如每个.txt(,然后在每一行上执行mv
并将文件移动到当前目录 (${PWD}
(。