软链接构成的同命令不同结果释疑

本文探讨了在Ubuntu系统中使用halt命令时遇到的权限和认证问题,揭示了halt实际上链接到systemctl的事实,并展示了如何通过systemctl进行系统控制操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

ubuntu@shanghai:~ $ ls -l /sbin/halt
lrwxrwxrwx 1 root root 14 Feb  5  2020 /sbin/halt -> /bin/systemctl
ubuntu@shanghai:~ $ halt
Failed to set wall message, ignoring: Interactive authentication required.
Failed to halt system via logind: Interactive authentication required.
Failed to open /dev/initctl: Permission denied
Failed to talk to init daemon.
ubuntu@shanghai:~ $ systemctl
  UNIT                                                                                LOAD   ACTIVE SUB       DESCRIPTION
  proc-sys-fs-binfmt_misc.automount                                                   loaded active waiting   Arbitrary Executable File Forma
  sys-devices-pci0000:00-0000:00:01.1-ata1-host0-target0:0:1-0:0:1:0-block-sr0.device loaded active plugged   QEMU_DVD-ROM config-2
  sys-devices-pci0000:00-0000:00:05.0-virtio0-net-eth0.device                         loaded active plugged   Virtio network device
ubuntu@shanghai:~ $ whereis halt
halt: /sbin/halt /usr/share/man/man8/halt.8.gz
ubuntu@shanghai:~ $ /sbin/halt
Failed to set wall message, ignoring: Interactive authentication required.
Failed to halt system via logind: Interactive authentication required.
Failed to open /dev/initctl: Permission denied
Failed to talk to init daemon.
ubuntu@shanghai:~ $ ls -l /sbin/halt
lrwxrwxrwx 1 root root 14 Feb  5  2020 /sbin/halt -> /bin/systemctl
ubuntu@shanghai:~ $ whereis systemctl
systemctl: /bin/systemctl /usr/share/man/man1/systemctl.1.gz
ubuntu@shanghai:~ $ which systemctl
/bin/systemctl
ubuntu@shanghai:~ $ cat hello.sh
echo Hello World
echo $0
ubuntu@shanghai:~ $ bash hello.sh
Hello World
hello.sh
ubuntu@shanghai:~ $ ln -sf hello.sh world
ubuntu@shanghai:~ $ bash world
Hello World
world

这个 里面是针对$0来再进行一次判断执行的命令是什么,至于在ubuntu中把sh指向bash会出现不一样的情况应该也是这个原因导致的。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值