linux下 mv /usr/bin/python /usr/bin/python_old是什么意思?
时间: 2023-08-24 10:09:24 浏览: 244
这个命令 `mv /usr/bin/python /usr/bin/python_old` 是在 Linux 系统中将 `/usr/bin/python` 文件重命名为 `/usr/bin/python_old` 的意思。
在 Linux 系统中,`/usr/bin/python` 是指向系统默认的 Python 解释器的符号链接。通过执行这个命令,你将原始的 `/usr/bin/python` 文件重命名为 `/usr/bin/python_old`,这样系统就无法使用旧的 Python 解释器了。
需要注意的是,如果你执行这个命令而没有安装新的 Python 解释器,并且没有及时修复符号链接,可能会导致一些 Python 相关的命令和脚本无法正常工作。因此,在执行这个命令之前,请确保你已经安装了新的 Python 解释器,并将符号链接正确地指向新的解释器路径。
相关问题
用python2将下面的shell实现 ``` getenforce#查看SELinux 安全机制 setenforce 0#将 SELinux 的执行模式从强制模式(Enforcing)切换为宽松模式(Permissive) cp /usr/lib/systemd/system/sshd.service /usr/lib/systemd/system/sshd.old.service sed -i -e 's/^Type=.*/Type=simple/g' -e '/ExecStart=/{s/\/usr\/sbin\/sshd/\/usr\/local\/sbin\/sshd/g}' /usr/lib/systemd/system/sshd.service#将文件中以"Type="开头的行替换为"Type=simple";包含"ExecStart="的行中,将"/usr/sbin/sshd"替换为"/usr/local/sbin/sshd" sed -i "s/GSSAPIAuthentication/#GSSAPIAuthentication/" /etc/ssh/sshd_config#将/etc/ssh/sshd_config文件中的"GSSAPIAuthentication"替换为"#GSSAPIAuthentication" sed -i "s/GSSAPICleanupCredentials/#GSSAPICleanupCredentials/" /etc/ssh/sshd_config sed -i "s/#PermitRootLogin yes/PermitRootLogin yes/" /etc/ssh/sshd_config sed -i "s/#UsePAM yes/UsePAM yes/" /etc/ssh/sshd_config chmod 600 /etc/ssh/ssh_host_rsa_key chmod 600 /etc/ssh/ssh_host_ecdsa_key chmod 600 /etc/ssh/ssh_host_ed25519_key mv /usr/local/sbin/sshd /usr/local/sbin/sshd.old202211 mv /lib64/libcrypto.so.1.1 /lib64/libcrypto.so.1.1.old202211 mv /srv/libcrypto.so.1.1 /lib64/ mv /srv/sshd /usr/local/sbin/ chmod 755 /usr/local/sbin/sshd chmod 755 /lib64/libcrypto.so.1.1 systemctl daemon-reload systemctl restart sshd.service source /etc/profile sshd -V useradd secure echo 'Ofm#6%3%fm0IWH'|passwd --stdin secure echo "secure ALL=(ALL) ALL" >> /etc/sudoers sed -i "s/PermitRootLogin yes/PermitRootLogin no/" /etc/ssh/sshd_config service sshd restart systemctl daemon-reload systemctl restart sshd.service sed -i "s/secure ALL=(ALL) ALL/secure ALL=(ALL) NOPASSWD: ALL/" /etc/sudoers chage -M 99999 secure sleep 2 useradd aqassoc echo 'dAxgDt^7LT' | passwd --stdin aqassoc mkdir /batshell chown -R aqassoc:aqassoc /batshell echo 'aqassoc ALL=(ALL) NOPASSWD:ALL,!/bin/su,!/sbin/init,!/sbin/shutdown,!/sbin/halt,!/sbin/reboot,!/usr/sbin/visudo,!/usr/bin/passwd' >> /etc/sudoers sh /srv/script.sh sleep 2 tar -xvf /srv/ssl-1.1.1o* -C /srv/ mv /usr/bin/openssl /usr/bin/openssl.old mv /usr/include/openssl /usr/include/openssl.old cp /etc/ld.so.conf /etc/ld.so.conf.old ln -s /srv/ssl-1.1.1o/bin/openssl /usr/bin/openssl ln -s /srv/ssl-1.1.1o/include/openssl /usr/include/openssl srvlib=`cat /etc/ld.so.conf | grep '/srv/ssl-1.1.1o/lib/' | wc -l` if [ $srvlib -eq 0 ];then sed -i 's/\/srv/#\/srv/'g /etc/ld.so.conf echo '/srv/ssl-1.1.1o/lib/' >> /etc/ld.so.conf else echo 'ssl-1.1.1n is ok!' fi ldconfig -v |grep ssl openssl version rm -rf /srv/root_password.sh rm -rf /srv/ssl-1.1.1o_7.tar.gz curl --connect-timeout 10 -# http://133.64.86.246/iso/shell/initialization.sh -o /tmp/initialization.sh # 只有两个参数 dcn/dmz netbond/netskip baseline/baseskip sh /tmp/initialization.sh dcn netbond/netskip baseline/baseskip ```
以下是使用 Python 2 实现上述 Shell 脚本的示例:
```python
import os
import subprocess
# 查看 SELinux 安全机制
subprocess.call(['getenforce'])
# 将 SELinux 的执行模式从强制模式(Enforcing)切换为宽松模式(Permissive)
subprocess.call(['setenforce', '0'])
# 备份 sshd.service 文件
subprocess.call(['cp', '/usr/lib/systemd/system/sshd.service', '/usr/lib/systemd/system/sshd.old.service'])
# 修改 sshd.service 文件内容
subprocess.call(['sed', '-i', '-e', 's/^Type=.*/Type=simple/g', '-e', '/ExecStart=/{s/\/usr\/sbin\/sshd/\/usr\/local\/sbin\/sshd/g}', '/usr/lib/systemd/system/sshd.service'])
# 修改 sshd_config 文件内容
subprocess.call(['sed', '-i', 's/GSSAPIAuthentication/#GSSAPIAuthentication/', '/etc/ssh/sshd_config'])
subprocess.call(['sed', '-i', 's/GSSAPICleanupCredentials/#GSSAPICleanupCredentials/', '/etc/ssh/sshd_config'])
subprocess.call(['sed', '-i', 's/#PermitRootLogin yes/PermitRootLogin yes/', '/etc/ssh/sshd_config'])
subprocess.call(['sed', '-i', 's/#UsePAM yes/UsePAM yes/', '/etc/ssh/sshd_config'])
# 修改文件权限
subprocess.call(['chmod', '600', '/etc/ssh/ssh_host_rsa_key'])
subprocess.call(['chmod', '600', '/etc/ssh/ssh_host_ecdsa_key'])
subprocess.call(['chmod', '600', '/etc/ssh/ssh_host_ed25519_key'])
# 移动文件和更改权限
subprocess.call(['mv', '/usr/local/sbin/sshd', '/usr/local/sbin/sshd.old202211'])
subprocess.call(['mv', '/lib64/libcrypto.so.1.1', '/lib64/libcrypto.so.1.1.old202211'])
subprocess.call(['mv', '/srv/libcrypto.so.1.1', '/lib64/'])
subprocess.call(['mv', '/srv/sshd', '/usr/local/sbin/'])
subprocess.call(['chmod', '755', '/usr/local/sbin/sshd'])
subprocess.call(['chmod', '755', '/lib64/libcrypto.so.1.1'])
subprocess.call(['systemctl', 'daemon-reload'])
subprocess.call(['systemctl', 'restart', 'sshd.service'])
subprocess.call(['source', '/etc/profile'])
subprocess.call(['sshd', '-V'])
# 创建用户 secure,并设置密码,配置 sudo 权限
subprocess.call(['useradd', 'secure'])
subprocess.call("echo 'Ofm#6%3%fm0IWH'|passwd --stdin secure", shell=True)
with open('/etc/sudoers', 'a') as sudoers_file:
sudoers_file.write("secure ALL=(ALL) ALL\n")
subprocess.call(['sed', '-i', 's/PermitRootLogin yes/PermitRootLogin no/', '/etc/ssh/sshd_config'])
subprocess.call(['service', 'sshd', 'restart'])
subprocess.call(['systemctl', 'daemon-reload'])
subprocess.call(['systemctl', 'restart', 'sshd.service'])
subprocess.call(['sed', '-i', 's/secure ALL=(ALL) ALL/secure ALL=(ALL) NOPASSWD: ALL/', '/etc/sudoers'])
subprocess.call(['chage', '-M', '99999', 'secure'])
subprocess.call(['sleep', '2'])
# 创建用户 aqassoc,并设置密码,创建目录并设置权限,配置 sudo 权限,执行脚本
subprocess.call(['useradd', 'aqassoc'])
subprocess.call("echo 'dAxgDt^7LT' | passwd --stdin aqassoc", shell=True)
subprocess.call(['mkdir', '/batshell'])
subprocess.call(['chown', '-R', 'aqassoc:aqassoc', '/batshell'])
with open('/etc/sudoers', 'a') as sudoers_file:
sudoers_file.write("aqassoc ALL=(ALL) NOPASSWD:ALL,!/bin/su,!/sbin/init,!/sbin/shutdown,!/sbin/halt,!/sbin/reboot,!/usr/sbin/visudo,!/usr/bin/passwd\n")
subprocess.call(['sh', '/srv/script.sh'])
subprocess.call(['sleep', '2'])
# 解压 ssl-1.1.1o.tar.gz 文件,并设置软链接,配置 ld.so.conf
subprocess.call(['tar', '-xvf', '/srv/ssl-1.1.1o*', '-C', '/srv/'])
subprocess.call(['mv', '/usr/bin/openssl', '/usr/bin/openssl.old'])
subprocess.call(['mv', '/usr/include/openssl', '/usr/include/openssl.old'])
subprocess.call(['cp', '/etc/ld.so.conf', '/etc/ld.so.conf.old'])
subprocess.call(['ln', '-s', '/srv/ssl-1.1.1o/bin/openssl', '/usr/bin/openssl'])
subprocess.call(['ln', '-s', '/srv/ssl-1.1.1o/include/openssl', '/usr/include/openssl'])
srvlib = subprocess.check_output("cat /etc/ld.so.conf | grep '/srv/ssl-1.1.1o/lib/' | wc -l", shell=True)
if int(srvlib) == 0:
subprocess.call(['sed', '-i', "s/\/srv/#\/srv/g", "/etc/ld.so.conf"])
subprocess.call(['echo', "'/srv/ssl-1.1.1o/lib/' >> /etc/ld.so.conf"])
else:
print('ssl-1.1.1n is ok!')
subprocess.call(['ldconfig', '-v', '|grep', 'ssl'])
subprocess.call(['openssl', 'version'])
# 清理临时文件
subprocess.call(['rm', '-rf', '/srv/root_password.sh'])
subprocess.call(['rm', '-rf', '/srv/ssl-1.1.1o_7.tar.gz'])
subprocess.call(['curl', '--connect-timeout', '10', '-#', 'http://133.64.86.246/iso/shell/initialization.sh', '-o', '/tmp/initialization.sh'])
# 执行 initialization.sh 脚本,传递参数
subprocess.call(['sh', '/tmp/initialization.sh', 'dcn', 'netbond/netskip', 'baseline/baseskip'])
```
这是一个使用`subprocess`模块调用Shell命令的示例。请确保你在执行这段代码之前对每个操作和命令的含义和可能的影响有充分的了解,并在适当的环境中运行它。
/var/lib/dpkg/info/python3.prerm: 5: /var/lib/dpkg/info/python3.prerm: py3clean: not found dpkg: warning: subprocess old pre-removal script returned error exit status 127 dpkg: trying script from the new package instead ... /var/lib/dpkg/tmp.ci/prerm: 5: /var/lib/dpkg/tmp.ci/prerm: py3clean: not found dpkg: error processing archive /var/cache/apt/archives/python3_3.5.1-3_amd64.deb (--unpack): subprocess new pre-removal script returned error exit status 127 /var/lib/dpkg/info/python3.postinst: 47: /var/lib/dpkg/info/python3.postinst: py3compile: not found dpkg: error while cleaning up: subprocess installed post-installation script returned error exit status 127 Errors were encountered while processing: /var/cache/apt/archives/python3_3.5.1-3_amd64.deb E: Sub-process /usr/bin/dpkg returned an error code (1)
这个错误提示是因为在卸载python3时出现了问题,可能是由于安装或升级时出错导致的。为了解决这个问题,你可以尝试使用以下命令:
```
sudo dpkg --configure -a
sudo apt-get install -f
sudo apt-get clean
sudo apt-get update
sudo apt-get upgrade
```
这些命令将重新配置所有已安装的软件包、安装或修复缺失的依赖项、清理APT缓存并更新软件包列表,最后进行系统升级。如果这些命令不能解决问题,你可以尝试手动删除Python3:
```
sudo dpkg -P python3
sudo apt-get install python3
```
这将强制删除Python3并重新安装它。请注意,这可能会删除与Python3相关的数据,所以请确保备份重要文件。
阅读全文