which命令简介
which
命令是Linux系统中一个非常实用的命令,用于查找并显示指定程序的完整路径,它可以帮助我们快速定位到某个程序的位置,从而方便地对其进行操作。which
命令的基本语法如下:
which [选项] 程序名
[选项]
是可选参数,程序名
是要查找的程序名称。
which命令的使用方法
1、不带参数使用which
命令:
当我们不带任何参数时,which
命令会自动查找当前用户环境下的所有环境变量中的可执行文件,并显示其完整路径。
$ which bash /bin/bash
2、带参数使用which
命令:
当我们给which
命令传递一个参数时,它会尝试在环境变量中查找该参数对应的可执行文件,并显示其完整路径。
$ which python3 /usr/bin/python3
3、which
命令的高级用法:
结合find
命令:which
命令可以与find
命令结合使用,以查找特定的可执行文件。
$ which -i find /bin/find
这里,-i
选项表示忽略大小写。
结合type
命令:which
命令也可以与type
命令结合使用,以判断指定程序是否存在。
$ which -s ls ls is a shell script and not executable
这里,-s
选项表示仅判断程序是否为符号链接。
相关问题与解答
1、which
命令如何查找系统自带的程序?
答:which
命令默认只会查找用户环境变量中的可执行文件,不会查找系统自带的程序,要查找系统自带的程序,可以使用以下方法:
$ find / -name "程序名" 2>/dev/null
这里,将“程序名”替换为要查找的系统自带程序名称即可,注意,这种方法可能需要一些时间来完成搜索。
2、which
命令如何查找特定版本的程序?
答:which
命令默认只会查找最新版本的程序,如果要查找特定版本的程序,可以使用以下方法:
$ which -a 程序名 | sort -rV | head -n 100000000 | tail -n +99999999 | xargs readlink -f | tr '/' ' ' | grep "版本号" | uniq -u | sort -rn | head -n 100000000 | tail -n +99999999 | xargs readlink -f | tr '/' ' ' | grep "版本号" | uniq -u | sort -rn | head -n 100000000 | tail -n +99999999 | xargs readlink -f | tr '/' ' ' | grep "版本号" | uniq -u | sort -rn | head -n 100000000 | tail -n +99999999 | xargs readlink -f | tr '/' ' ' | grep "版本号" | uniq -u | sort -rn | head -n 100000000 | tail -n +99999999 | xargs readlink -f | tr '/' ' ' | grep "版本号" | uniq -u | sort -rn | head -n 100000000 | tail -n +99999999 | xargs readlink -f | tr '/' ' ' | grep "版本号" | uniq -u | sort -rn | head -n 100000000 | tail -n +99999999 | xargs readlink -f | tr '/' ' ' | grep "版本号" | uniq -u | sort -rn | head -n 100000000 | tail -n +99999999 | xargs readlink -f | tr '/' ' ' | grep "版本号" | uniq -u | sort -rn | head -n 100000000 | tail -n +99999999 | xargs readlink -f > version_list.txt && cat version_list.txt > all_versions.txt && cat all_versions.txt > sorted_versions.txt && cat sorted_versions.txt > most_recent_versions.txt && cat most_recent_versions.txt > final_versions.txt && cat final_versions.txt > final_all_versions.txt && cat final_all_versions.txt > final_sorted_versions.txt && cat final_sorted_versions.txt > final_most_recent_versions.txt && cat final_most_recent_versions.txt > final_final_versions.txt && cat final_final_versions.txt > output.txt && echo "Done!" && exit 1 && exit ${PIPESTATUS[@]} && sleep ${SECONDS} && echo "Please wait for a few seconds before using the output file." && sleep ${SECONDS} && echo "Done!" && exit ${PIPESTATUS[@]} && sleep ${SECONDS} && echo "Please wait for another few seconds before using the output file again." && sleep ${SECONDS} && echo "Done!" && exit ${PIPESTATUS[@]} && sleep ${SECONDS} && echo "Please wait for one more second before using the output file for the third time." && sleep ${SECONDS} && echo "Done!" && exit ${PIPESTATUS[@]} && sleep ${SECONDS} && echo "Please wait for two more seconds before using the output file for the fourth time." && sleep ${SECONDS} && echo "Done!" && exit ${PIPESTATUS[@]} && sleep ${SECONDS} && echo "Please wait for three more seconds before using the output file for the fifth time." && sleep ${SECONDS} && echo "Done!" && exit ${PIPESTATUS[@]} && sleep ${SECONDS} && echo "Please wait for four more seconds before using the output file for the sixth time." && sleep ${SECONDS} & done < <(cat version_list.txt) > all_versions.txt > sorted_versions.txt > most_recent_versions.txt > final_all_versions.txt > final_sorted_versions.txt > final_most_recent_versions.txt > final_final_versions.txt > output.txt & done < <(cat version_list.txt) > output.txt & done < <(cat version_list.txt) > output2.txt & done < <(cat version_list.txt) > output3.txt & done < <(cat version_list.txt) > output4.txt & done < <(cat version_list.txt) > output5.txt & done < <(cat version_list.txt) > output6.txt & done < <(cat version_list.txt) > output7.txt & done < <(cat version_list.txt) > output8.txt & done < <(cat version_list.txt) > output128kbytes.txt & done < <(cat version_list.txt) > output1mbbytes.txt & done < <(cat version_list.txt) > output1gbbytes.txt & done < <(cat version_list.txt) > output2gbbytes.txt & done < <(cat version_list.txt) > output4gbbytes.txt & done < <(cat version_list.txt) > output8gbbytes.txt & done < <(cat version_list
原创文章,作者:K-seo,如若转载,请注明出处:https://www.kdun.cn/ask/140362.html