(Migrant Brother Technology Road) Analysis of command usage examples
From: Migrant Brother’s Technical Road
1. which command
We often want to search for a certain file in Linux, but we don’t know where to put it. You can use some of the following commands to search: The function of the which command is to search for a certain system command in the path specified by the PATH variable. location, but returns the first search result. That is to say, by using the which command, you can see whether a certain system command exists and where the command is executed. 1. Command format: which executable file name 2. Command function: The which command will search for the location of a system command in the path specified by the PATH variable, but return the first search result. 3. Command parameters: 4. Usage examples: Example 1: Find files and display command paths
命令:which lsmod 输出: [root@localhost ~]# which pwd /bin/pwd [root@localhost ~]# which adduser /usr/sbin/adduser [root@localhost ~]#
Explanation: which searches for executable files according to the directory in the PATH variable configured by the user! Therefore, the commands found by different PATH configuration contents are actually different! Example 2: Use which to find out which
Command: whichwhich
Output:
[root@localhost ~]# which whichalias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde' /usr/bin/which [root@localhost ~]#
Explanation: There are actually two which, one of which is alias. This is the so-called "command alias", which means that entering which will be equal to the previous string of commands! Example 3: Find the cd command
Command: whichcd
Output:
Explanation: The commonly used command cd cannot be found! Why? This is because cd is a built-in command in bash! And which by default looks for the directory specified in PATH, so it must not be found!
2. whereis command
The whereis command can only be used to search for program names, and only searches two's complement files (parameter -b), man description files (parameter -m) and source code files (parameter -s). If parameters are omitted, all information is returned. Compared with find, the search speed of whereis is very fast. This is because the Linux system will record all the files in the system in a database file. When using whereis and locate formally introduced below, the data will be searched from the database. Instead of searching by traversing the hard disk like the find command, the efficiency will naturally be very high. Moreover, the database file is not updated in real time. By default, it is updated once a week. Therefore, when we use whereis and locate to search for files, we sometimes find data that has been deleted, or it is difficult to find the file we just created. , the reason is that the database file has not been updated. 1. Command format: whereis[-bmsu][BMS directory name-f] file name 2. Command function: The whereis command locates the location of executable files, source code files, and help files in the file system. The attributes of those files should be original code, two's complement files, or help files. The whereis program also has the ability to search source code, specify alternative search paths, and search for unusual items. 3. Command parameters: 4. Usage example: Example 1: Find all files related to ** file
命令:whereis svn 输出: [root@localhost ~]# whereis tomcat tomcat: [root@localhost ~]# whereis svn svn: /usr/bin/svn /usr/local/svn /usr/share/man/man1/svn.1.gz
Explanation: Tomcat is not installed and cannot be found. The svn installation found many related files. Example 2: Only two's complement files are found
命令:whereis -b svn 输出: [root@localhost ~]# whereis -b svn svn: /usr/bin/svn /usr/local/svn [root@localhost ~]# whereis -m svn svn: /usr/share/man/man1/svn.1.gz [root@localhost ~]# whereis -s svn svn: [root@localhost ~]#
Description: Whereis-msvn finds the path to the documentation document The linux command locates the file , and whereis-ssvn finds the source file.
3. locate command
locate让使用者可以很快速的搜救档案系统内是否有指定的档案。其方式是先构建一个包括系统内所有档案名称及路径的数据库,然后当找寻时就只需查询这个数据库,而毋须实际深入档案系统之中了。在通常的distribution之中,数据库的构建都被置于crontab中手动执行。1.命令格式:Locate[选择参数][式样]2.命令功能:locate命令可以在搜救数据库时快速找到档案linux 命令定位文件,数据库由updatedb程序来更新,updatedb是由crondaemon周期性构建的,locate命令在搜救数据库时比由整个由硬碟资料来搜救资料来得快,但较差劲的是locate所找到的档案若是近来才完善或刚改名的linux串口驱动,可能会找不到,在内定值中,updatedb每晚会跑一次,可以由更改crontab来更新设定值。(etc/crontab)locate指定用在搜救符合条件的档案,它会去储藏档案与目录名称的数据库内,找寻合乎范本式样条件的档案或目录录,可以使用特殊字元(如”*”或”?”等)来指定范本式样,如指定范本为kcpa*ner,locate会找出所有起始字串为kcpa且结尾为ner的档案或目录,如名称为kcpartner若目录录名称为kcpa_ner则会列举该目录下包括子目录在内的所有档案。locate指令和find寻找档案的功能类似linux公社,但locate是透过update程序将硬碟中的所有档案和目录资料先构建一个索引数据库,在执行loacte时直接找该索引,查询速率会较快,索引数据库通常是由操作系统管理,但也可以直接下达update逼迫系统立刻更改索引数据库。3.命令参数:4.使用实例:实例1:查找和pwd相关的所有文件
命令:locate pwd 输出: peida-VirtualBox ~ # locate pwd /bin/pwd /etc/.pwd.lock /sbin/unix_chkpwd /usr/bin/pwdx /usr/include/pwd.h /usr/lib/python2.7/dist-packages/twisted/python/fakepwd.py /usr/lib/python2.7/dist-packages/twisted/python/fakepwd.pyc /usr/lib/python2.7/dist-packages/twisted/python/test/test_fakepwd.py /usr/lib/python2.7/dist-packages/twisted/python/test/test_fakepwd.pyc /usr/lib/syslinux/pwd.c32 /usr/share/help/C/empathy/irc-join-pwd.page /usr/share/help/ca/empathy/irc-join-pwd.page /usr/share/help/cs/empathy/irc-join-pwd.page /usr/share/help/de/empathy/irc-join-pwd.page /usr/share/help/el/empathy/irc-join-pwd.page
实例2:搜索etc目录下所有以sh开头的文件
命令:locate /etc/sh 输出: peida-VirtualBox ~ # locate /etc/sh /etc/shadow /etc/shadow-/etc/shells peida-VirtualBox ~ #
实例3:搜索etc目录下,所有以m开头的文件
命令:locate /etc/m 输出: peida-VirtualBox ~ # locate /etc/m /etc/magic /etc/magic.mime /etc/mailcap /etc/mailcap.order /etc/manpath.config /etc/mate-settings-daemon
想要学习Linux系统运维的同事们可以看一看《Linux系统运维手册从入门到企业实战》这本书,特别适宜Linux学习及工作必备的工具书。
end
良许个人陌陌
添加良许个人陌陌即送3套程序员必看资料
→精选技术资料共享
→高手如云交流社群
本公众号全部博文已整理成一个目录,请在公众号里回复「m」获取!
The above is the detailed content of (Migrant Brother Technology Road) Analysis of command usage examples. For more information, please follow other related articles on the PHP Chinese website!

The main tasks of Linux system administrators include system monitoring and performance tuning, user management, software package management, security management and backup, troubleshooting and resolution, performance optimization and best practices. 1. Use top, htop and other tools to monitor system performance and tune it. 2. Manage user accounts and permissions through useradd commands and other commands. 3. Use apt and yum to manage software packages to ensure system updates and security. 4. Configure a firewall, monitor logs, and perform data backup to ensure system security. 5. Troubleshoot and resolve through log analysis and tool use. 6. Optimize kernel parameters and application configuration, and follow best practices to improve system performance and stability.

Learning Linux is not difficult. 1.Linux is an open source operating system based on Unix and is widely used in servers, embedded systems and personal computers. 2. Understanding file system and permission management is the key. The file system is hierarchical, and permissions include reading, writing and execution. 3. Package management systems such as apt and dnf make software management convenient. 4. Process management is implemented through ps and top commands. 5. Start learning from basic commands such as mkdir, cd, touch and nano, and then try advanced usage such as shell scripts and text processing. 6. Common errors such as permission problems can be solved through sudo and chmod. 7. Performance optimization suggestions include using htop to monitor resources, cleaning unnecessary files, and using sy

The average annual salary of Linux administrators is $75,000 to $95,000 in the United States and €40,000 to €60,000 in Europe. To increase salary, you can: 1. Continuously learn new technologies, such as cloud computing and container technology; 2. Accumulate project experience and establish Portfolio; 3. Establish a professional network and expand your network.

The main uses of Linux include: 1. Server operating system, 2. Embedded system, 3. Desktop operating system, 4. Development and testing environment. Linux excels in these areas, providing stability, security and efficient development tools.

The Internet does not rely on a single operating system, but Linux plays an important role in it. Linux is widely used in servers and network devices and is popular for its stability, security and scalability.

The core of the Linux operating system is its command line interface, which can perform various operations through the command line. 1. File and directory operations use ls, cd, mkdir, rm and other commands to manage files and directories. 2. User and permission management ensures system security and resource allocation through useradd, passwd, chmod and other commands. 3. Process management uses ps, kill and other commands to monitor and control system processes. 4. Network operations include ping, ifconfig, ssh and other commands to configure and manage network connections. 5. System monitoring and maintenance use commands such as top, df, du to understand the system's operating status and resource usage.

Introduction Linux is a powerful operating system favored by developers, system administrators, and power users due to its flexibility and efficiency. However, frequently using long and complex commands can be tedious and er

Linux is suitable for servers, development environments, and embedded systems. 1. As a server operating system, Linux is stable and efficient, and is often used to deploy high-concurrency applications. 2. As a development environment, Linux provides efficient command line tools and package management systems to improve development efficiency. 3. In embedded systems, Linux is lightweight and customizable, suitable for environments with limited resources.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 Mac version
God-level code editing software (SublimeText3)

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Atom editor mac version download
The most popular open source editor