一串命令的疑问

silentwins 2014-01-28 11:26:16
先是把/usr/src打包到/mnt的命令:
# tar cfC - /usr/src . | tar xpfC - /mnt

1. 命令中的-是什么意思?貌似在tar的help和man都没有找到解释。
2. 命令中为什么要有一个.符号?如果是表示当前目录的话,那它在命令中是什么作用?

使用上面一条命令之后,下面的命令应该是把新的硬盘挂接到/usr/src上:
# rm -rf /usr/src/*
# umount /mnt
# mount /usr/src

1. 不明白为什么把原来/usr/src/的内容清空了,卸载mnt,又安装/usr/src目录,这样子本来/mnt下的硬盘就挂接到/usr/src上面去了么?实在搞不明白原理。
2. 那如果我不把/usr/src下的内容清空了,又是如何的结果?总体来说这段命令实在理解不了。


我是看某本书一路看下来的,命令本身是没有问题的,这些是不理解的部分。多谢指教!
...全文
281 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
糊涂的小白 2014-01-28
  • 打赏
  • 举报
回复
引用 7 楼 lisa5001 的回复:
至于mount,我觉得应该只是一个示例用法,书只内容也没有说/mnt目录是怎么挂载的。
mount /usr/src
只是想表明把新硬盘挂载到这个目录而已。 [quote=引用 楼主 silentwins 的回复:] 2. 那如果我不把/usr/src下的内容清空了,又是如何的结果?总体来说这段命令实在理解不了。
不把/usr/src下的内容清空的话,这些内容依然会占用原有硬盘的空间,达不到释放老硬盘空间的目的。 不如不关心老硬盘的空间占用,那么没有影响。 在把新硬盘mount 到/usr/src之后,原有/usr/src下的内容是看不到的。[/quote] 打错字了,应该是“如果”
糊涂的小白 2014-01-28
  • 打赏
  • 举报
回复
至于mount,我觉得应该只是一个示例用法,书只内容也没有说/mnt目录是怎么挂载的。
mount /usr/src
只是想表明把新硬盘挂载到这个目录而已。
引用 楼主 silentwins 的回复:
2. 那如果我不把/usr/src下的内容清空了,又是如何的结果?总体来说这段命令实在理解不了。
不把/usr/src下的内容清空的话,这些内容依然会占用原有硬盘的空间,达不到释放老硬盘空间的目的。 不如不关心老硬盘的空间占用,那么没有影响。 在把新硬盘mount 到/usr/src之后,原有/usr/src下的内容是看不到的。
糊涂的小白 2014-01-28
  • 打赏
  • 举报
回复
引用 楼主 silentwins 的回复:
先是把/usr/src打包到/mnt的命令:
# tar cfC - /usr/src . | tar xpfC - /mnt
1. 命令中的-是什么意思?貌似在tar的help和man都没有找到解释。 2. 命令中为什么要有一个.符号?如果是表示当前目录的话,那它在命令中是什么作用?
- = stdout/stdin
tar cfC - /usr/src .
效果等价于
tar -cf temp.tar -C /usr/src . && cat temp.tar 
.表示工作目录,因为有-C /usr/src的限制,所以工作目录是/usr/src/.
silentwins 2014-01-28
  • 打赏
  • 举报
回复
Installing Existing Files onto New Disks Chances are that you intend your new disk to replace or subdivide an existing partition. You’ll need to mount your new partition on a temporary mount point, move files to the new disk, then remount the partition at the desired location. In our example above, we’ve mounted our new partition on /mnt. Now you just need to move the files from their current location to the new disk without changing their permissions. This is fairly simple with tar(1). You can simply tar up your existing data to a tape or a file and untar it in the new location, but that’s kind of clumsy. You can concatenate tar commands to avoid that middle step, however.
# tar cfC - /old/directory . | tar xpfC - /tempmount
If you don’t speak Unix at parties, this looks fairly stunning. Let’s dismantle it. First, we go to the old directory and tar up everything. Then pipe the output to a second command, which extracts the backup in the new directory. When this command finishes, your files are installed on their new disk. For example, to move /usr/src onto a new partition temporarily mounted at /mnt, you would do this:
# tar cfC - /usr/src . | tar xpfC - /mnt
Check the temporary mount point to be sure that your files are actually there. Once you’re confident that the files are properly moved, remove the files from the old directory and mount the disk in the new location. For example, after duplicating your files from /usr/src, you would run:
# rm -rf /usr/src/*
# umount /mnt
# mount /usr/src
应该没有,因为书中提到是新接了一个硬盘,然后把/usr/src的内容转移过去,如果在fstab有项的话,应该还得修改fstab吧?贴一下书中的内容,谢谢!
YTerrenceLau 2014-01-28
  • 打赏
  • 举报
回复
引用 2 楼 silentwins 的回复:
[quote=引用 1 楼 YTerrenceLau 的回复:] 好复杂,- 是不是代表刚才的目录,比如: :~$ pwd /home/name :~$ cd .. :/home$ cd - /home/name :~$ pwd /home/name
那这样的话第一个命令的第一个部分总共有3个目录啊,好像不太符合合格命令的逻辑吧~[/quote] 是啊,所以我也没看懂,最开始分析跟命令行中的C有关,总之随后我大脑的栈溢出了,就不纠结了,你继续演技研究看吧。
糊涂的小白 2014-01-28
  • 打赏
  • 举报
回复
mount /usr/src
可能是在fstab里面已经有指定/usr/src对应的项了
silentwins 2014-01-28
  • 打赏
  • 举报
回复
引用 1 楼 YTerrenceLau 的回复:
好复杂,- 是不是代表刚才的目录,比如: :~$ pwd /home/name :~$ cd .. :/home$ cd - /home/name :~$ pwd /home/name
那这样的话第一个命令的第一个部分总共有3个目录啊,好像不太符合合格命令的逻辑吧~
YTerrenceLau 2014-01-28
  • 打赏
  • 举报
回复
好复杂,- 是不是代表刚才的目录,比如: :~$ pwd /home/name :~$ cd .. :/home$ cd - /home/name :~$ pwd /home/name
糊涂的小白 2014-01-28
  • 打赏
  • 举报
回复
假设你挂载/mnt这是么操作的: mount /dev/sdc1 /mnt 那么,在umount /mnt之后挂载/usr/src就这么操作: mount /dev/sdc1 /usr/src "muont /usr/src"领会精神就行了。。。不纠结
silentwins 2014-01-28
  • 打赏
  • 举报
回复
挂载/mnt是我根据书中的说明,连接新硬盘盘后用sysintall的config fdisk和Label挂载的,这部分我操作过,而且是手工操作的,选取了硬盘,所以能理解。 哎呀,刚才重启了试了一下,/mnt不能挂载了…… 但是mount /usr/src命令还是没有被操作的设备啊,进去sysinstall操作的时候已经设定了?这部分很混乱啊,比Windows的硬盘分区难理解多了……
糊涂的小白 2014-01-28
  • 打赏
  • 举报
回复
引用 9 楼 silentwins 的回复:
mount /usr/src 只是想表明把新硬盘挂载到这个目录而已。 lisa5001 你好, 想请教一下这里怎样确认被操作的是新硬盘?因为这个命令中看不到有/da1之类的设备名称。谢谢!
意思就是,你需要自己找到新硬盘的设备名称,才有可能挂载到/mnt,然后挂载到/usr/src。 你对/mnt目录是怎么挂载的没有疑问么?
silentwins 2014-01-28
  • 打赏
  • 举报
回复
mount /usr/src 只是想表明把新硬盘挂载到这个目录而已。 lisa5001 你好, 想请教一下这里怎样确认被操作的是新硬盘?因为这个命令中看不到有/da1之类的设备名称。谢谢!

19,613

社区成员

发帖
与我相关
我的任务
社区描述
系统使用、管理、维护问题。可以是Ubuntu, Fedora, Unix等等
社区管理员
  • 系统维护与使用区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧