tmp 文件包含:
database_1 database_2 database_3我想为上述文件中的每一行运行一个类似mysqldump DATABASE > database.sql && gzip database.sql"的命令.
I want to run a command like "mysqldump DATABASE > database.sql && gzip database.sql" for each line in the above file.
我已经知道了 cat/tmp/database-list |xargs -L 1 mysqldump -u root -p
I've got as far as cat /tmp/database-list | xargs -L 1 mysqldump -u root -p
我想我想知道如何将传递给 xargs 的数据多次放入(而不只是放在最后)
I guess I want to know how to put the data passed to xargs in more than once (and not just on the end)
以下命令会将每个数据库转储到其自己的 .sql 文件中,然后对其进行 gzip.
the following command will dump each database into its own .sql file, then gzip them.
mysql -u root -pPASSWORD -B -e 'show databases' | sed -e '$!N; s/Database\n//' | xargs -L1 -I db mysqldump -u root -pPASSWORD -r db.backup.sql db; gzip *.sql 推荐答案在您自己的示例中,您使用 &&在一行上使用两个命令 - 那么为什么不这样做
In your own example you use && to use two commands on one line - so why not do
cat file | xargs -L1 -I db mysqldump db > db.sql && cat file | xargs -L1 -I db gzip database.sql如果您真的想仅使用 xargs 在一行中完成所有操作.虽然我相信
if you really want to do it all in one line using xargs only. Though I believe that
cat file | xargs -L1 -I db mysqldump db > db.sql && cat file; gzip *.sql会更有意义.
更多推荐
将传递给 xargs 的数据放在一行中两次
发布评论