Home System Tutorial LINUX (Migrant Brother Technology Road) Analysis of command usage examples

(Migrant Brother Technology Road) Analysis of command usage examples

Mar 03, 2024 am 08:19 AM
Command instance analysis

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 ~]#
Copy after login

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 ~]#
Copy after login

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

linux命令定位到指定位置_linux定位oom_linux 命令定位文件

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
Copy after login

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 ~]#
Copy after login

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
Copy after login

实例2:搜索etc目录下所有以sh开头的文件

命令:locate /etc/sh
输出:
peida-VirtualBox ~ # locate /etc/sh
/etc/shadow
/etc/shadow-/etc/shells
peida-VirtualBox ~ #
Copy after login

实例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
Copy after login

想要学习Linux系统运维的同事们可以看一看《Linux系统运维手册从入门到企业实战》这本书,特别适宜Linux学习及工作必备的工具书。

end

Copy after login

良许个人陌陌

添加良许个人陌陌即送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!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Will R.E.P.O. Have Crossplay?
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How To Count Files And Directories In Linux: A Beginner's Guide How To Count Files And Directories In Linux: A Beginner's Guide Mar 19, 2025 am 10:48 AM

Efficiently Counting Files and Folders in Linux: A Comprehensive Guide Knowing how to quickly count files and directories in Linux is crucial for system administrators and anyone managing large datasets. This guide demonstrates using simple command-l

How To Add A User To Multiple Groups In Linux How To Add A User To Multiple Groups In Linux Mar 18, 2025 am 11:44 AM

Efficiently managing user accounts and group memberships is crucial for Linux/Unix system administration. This ensures proper resource and data access control. This tutorial details how to add a user to multiple groups in Linux and Unix systems. We

How To List Or Check All Installed Linux Kernels From Commandline How To List Or Check All Installed Linux Kernels From Commandline Mar 23, 2025 am 10:43 AM

Linux Kernel is the core component of a GNU/Linux operating system. Developed by Linus Torvalds in 1991, it is a free, open-source, monolithic, modular, and multitasking Unix-like kernel. In Linux, it is possible to install multiple kernels on a sing

How To Easily Configure Flatpak Apps Permissions With Flatseal How To Easily Configure Flatpak Apps Permissions With Flatseal Mar 22, 2025 am 09:21 AM

Flatpak application permission management tool: Flatseal User Guide Flatpak is a tool designed to simplify Linux software distribution and use. It safely encapsulates applications in a virtual sandbox, allowing users to run applications without root permissions without affecting system security. Because Flatpak applications are located in this sandbox environment, they must request permissions to access other parts of the operating system, hardware devices (such as Bluetooth, network, etc.) and sockets (such as pulseaudio, ssh-auth, cups, etc.). This guide will guide you on how to easily configure Flatpak with Flatseal on Linux

How To Type Indian Rupee Symbol In Ubuntu Linux How To Type Indian Rupee Symbol In Ubuntu Linux Mar 22, 2025 am 10:39 AM

This brief guide explains how to type Indian Rupee symbol in Linux operating systems. The other day, I wanted to type "Indian Rupee Symbol (₹)" in a word document. My keyboard has a rupee symbol on it, but I don't know how to type it. After

Yt-dlp Commands: The Complete Tutorial For Beginners (2025) Yt-dlp Commands: The Complete Tutorial For Beginners (2025) Mar 21, 2025 am 11:00 AM

Have you ever wanted to save your favorite videos from the internet? Whether it's a funny cat video or a tutorial you want to watch later, Yt-dlp is here to help! In this comprehensive yt-dlp tutorial, we will explain what yt-dlp is, how to install i

What is the Linux best used for? What is the Linux best used for? Apr 03, 2025 am 12:11 AM

Linux is best used as server management, embedded systems and desktop environments. 1) In server management, Linux is used to host websites, databases, and applications, providing stability and reliability. 2) In embedded systems, Linux is widely used in smart home and automotive electronic systems because of its flexibility and stability. 3) In the desktop environment, Linux provides rich applications and efficient performance.

LocalSend - The Open-Source Airdrop Alternative For Secure File Sharing LocalSend - The Open-Source Airdrop Alternative For Secure File Sharing Mar 24, 2025 am 09:20 AM

If you're familiar with AirDrop, you know it's a popular feature developed by Apple Inc. that enables seamless file transfer between supported Macintosh computers and iOS devices using Wi-Fi and Bluetooth. However, if you're using Linux and missing o

See all articles