使用linux系统难免会忘记文件所在的位置,可以使用以下命令对系统中的文件进行搜索。搜索文件的命令为”find“;”locate“;”whereis“;”which“;”type“
方法/步骤
find
linux下最强大的搜索命令为”find“。它的格式为”find <指定目录> <指定条件> <指定动作>“;比如使用find命令搜索在根目录下的所有interfaces文件所在位置,命令格式为”find / -name 'interfaces'“
[root]# find /mnt -name "install"
/mnt/install
locate
使用locate搜索linux系统中的文件,它比find命令快。因为它查询的是数据库(/var/lib/locatedb),数据库包含本地所有的文件信息。使用locate命令在根目录下搜索interfaces文件的命令为”locate interfaces“
[root]
# locate install
/
var/lib/docker/overlay/
40ed1898b3d4a445a2b565a2df2ac3aebc48e64c1985827d55f4e8a974ff5a5e
/root/usr/share/icons/Adwaita/
96x96/apps/system-software-install-symbolic.symbolic.png
/
var/lib/docker/overlay/
40ed1898b3d4a445a2b565a2df2ac3aebc48e64c1985827d55f4e8a974ff5a5e
/root/usr/share/icons/Adwaita/scalable/apps/system-software-install-symbolic.svg
/
var/lib/docker/overlay/
40ed1898b3d4a445a2b565a2df2ac3aebc48e64c1985827d55f4e8a974ff5a5e
/root/usr/share/icons/gnome/
16x16/apps/system-software-install.png
.....
没有找到命令参见如下解决方案:
yum
install mlocate
sudo updatedb
locate
install
具体执行结果:
[root]
-bash: locate: command
not found
[root]
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.cloud.aliyuncs.com
* extras: mirrors.cloud.aliyuncs.com
* epel: mirrors.cloud.aliyuncs.com
--> Running transaction check
* updates: mirrors.cloud.aliyuncs.com Resolving Dependencies
---> Package mlocate.x86_64
0:
0.
26-
6.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
=========================================================================================================
Package Arch Version Repository Size
mlocate x86_64
0.
26-
6.el7 base
113 k
========================================================================================================= Installing:
Transaction Summary
=========================================================================================================
Install
1
Package
Total download size:
113
k
Installed size:
378
k
Is this ok [
y/d/N]: y
Downloading packages:
mlocate-0.26-6.el7.x86_64.rpm | 113 kB 00:00:02
Running transaction check Running transaction test Transaction test succeeded Running transaction
Installing : mlocate-0.26-6.el7.x86_64 1/
1
Verifying : mlocate-
0
.
26
-
6
.el7.x86_64
1
/
1
Installed:
mlocate.x86_64
0
:
0
.
26
-
6
.el7
Complete!
[root]
[root]
/var/lib/docker/overlay/
40
ed1898b3d4a445a2b565a2df2ac3aebc48e64c1985827d55f4e8a974ff5a5e
/root/usr/share/icons/Adwaita/
96
x96/apps/
system
-software-install-symbolic.symbolic.png
/var/lib/docker/overlay/
40
ed1898b3d4a445a2b565a2df2ac3aebc48e64c1985827d55f4e8a974ff5a5e
/root/usr/share/icons/Adwaita/scalable/apps/
system
-software-install-symbolic.svg
/var/lib/docker/overlay/
40
ed1898b3d4a445a2b565a2df2ac3aebc48e64c1985827d55f4e8a974ff5a5e
/root/usr/share/icons/gnome/
16
x16/apps/
system
-software-install.png
.....
whereis
使用”whereis“命令可以搜索linux系统中的所有可执行文件即二进制文件。使用whereis命令搜索grep二进制文件的命令为”whereis grep“。
[root]
grep
:
/usr/bin
/grep /usr
/share/man
/man1/grep
.
1
.gz
which
使用which命令查看系统命令是否存在,并返回系统命令所在的位置。使用which命令查看grep命令是否存在以及存在的目录的命令为”which grep“。
[root]
alias
grep=
'grep --color=auto'
/usr/bin/
grep
type
使用type命令查看系统中的某个命令是否为系统自带的命令。使用type命令查看cd命令是否为系统自带的命令;查看grep 是否为系统自带的命令。
[root]
grep
is aliased to `
grep --color=auto'
Linux下按两下Tab键可以显示所有的命令:
[root]
Display all
1322 possibilities? (
y
or n)
: iconvconfig psfgettable
! iconvconfig.i686 psfstriptable
./ iconvconfig.x86_64 psfxtable
[[ idiag-
socket-details pstree.x11
[ id pstree
]] idlj pstruct
{ idn ptaskset
}
if ptx
a2p ifcfg pushd
accessdb ifconfig pwck
addgnupghome ifdown pwconv
addpart ifenslave pwd addr2line ifnames pwdx
agetty ifup pwmake
adduser ifstat pwhistory_helper alias igawk pwscore
appletviewer infokey python2
aliyun-service in pwunconv alternatives info pydoc anacron infocmp python
applygnupgdefaults infotocap python2.
7
apropos init ranlib
ar insmod raw
arp install-info rdma-ndd
arch install/ rdisc
arpd installkernel
read
arping intel-microcode2ucode readarray
as ionice readelf
aserver iostat
readlink
at ip readonly
atd ip6tables readprofile
atq ip6tables-restore realpath
atrun ipcalc recode-sr-latin
atrm ip6tables-save reboot audispd ipcmk red
audit2why ipcs redis-benchmark
audit2allow ipcrm redhat_lsb_trigger.x86_64 auditctl ipmaddr redis-check-aof
auditd iprconfig redis-check-
dump
augenrules iprdbg redis-cli
aulast iprdump redis-sentinel
aulastlog iprinit redis-server
aureport iprsos
rename
ausearch iprupdate renice
ausyscall ipset repoclosure
authconfig iptables repodiff
autoconf iptables-save repomanage
authconfig-tui iptables-restore repo-graph
autoreconf irqbalance reposync
autoheader iptables-xml repoquery autom4te iptunnel repo-rss
autoupdate jar
reset
autoscan isosize repotrack
autrace jarsigner resize2fs
auvirt java resizecons
avcstat javac resizepart
badblocks javafxpackager
return
awk javadoc restorecon
base64 javah rev
basename javap rm
bash javapackager rmail
bashbug java-rmi.cgi rmail.postfix
bashbug-
64 javaws
rmdir
batch jcmd rmic
bc jconsole rmid
bg jcontrol rmiregistry
bind
jdb rmmod
biosdecode jdeps route
biosdevname jhat routef
blkdeactivate jinfo routel
blkid jmap rpm
blkdiscard jjs rpcgen
bond2team jmc.ini rpmdb
blockdev jmc rpm2cpio
break
join rpmquery
bootctl jobs rpmkeys bridge journalctl rpmverify
btrfsck jrunscript rsyslog-recover-qi.pl
btrfs jps rsyslogd btrfs-convert jsadebugd rtacct
btrfs-image jsonpointer rtpr
btrfs-debug-tree jsondiff rtcwake btrfs-find-root jsonpatch rtmon
btrfs-
map-logical jstack rtstat
btrfs-
select-super jstat runcon
btrfstune jstatd runlevel
btrfs-zero-
log jvisualvm run-parts
build-locale-archive kbdinfo runuser
builtin kbd_mode rvi
c2ph kdump rvim
busctl kbdrate rview c89 kdumpctl rz
cal keytool sandbox
c99 kernel-install s2p cacertdir_rehash kexec sadf
ca-legacy
kill sar
caller
killall sasldblistusers2
cancel killall5 saslpasswd2
cancel.cups kmod schemagen
captoinfo l. screen
capsh kpartx scp
case
last script
cat lastb scriptreplay
catchsegv lastlog sdiff
cbq lchfn sed
catman lchage secon
cd ld sedispol
cc lchsh sedismod
certutil ld.bfd selabel_digest
centrino-decode ldattach sefcontext_compile
c++filt ldd selabel_lookup_best_match
cfdisk ldconfig selabel_lookup
chage less
select
chacl ld.gold selabel_partial_match
chardetect lessecho selinuxconlist
chat lesskey selinuxdefcon
chcat let selinuxexeccon
chattr lesspipe.sh selinuxenabled
checkmodule lgroupdel semodule
chcon lexgrog selinux_restorecon chcpu lgroupadd semanage
cheetah-analyze
link sendmail.postfix
checkpolicy lgroupmod semodule_package cheetah lid sendmail
cheetah-compile linux32 seq
chfn linux64 serialver
chgrp linux-boot-prober servertool
chkconfig ll service
chmod ln sestatus
chown
lnewusers set
chpasswd lnstat setarch
chronyc loadkeys setcap
chronyd load_policy setenforce
chroot
loadunimap setfacl
chrt
local setfiles
chsh locale setfont
chvt localectl setkeycodes
cifsiostat localedef setleds
clear login setpci
cksum logger setmetamode clock loginctl setpriv
cloud-init-per logrotate setterm
clockdiff logname setsebool cloud-init logout setsid
cmsutil losetup setvtrgb
cloud-init-upgrade logsave setup-nsssysinit cmp look setup-nsssysinit.sh
column lpc.cups sg
col lp sexp-conv colcrt lpasswd sfdisk colrm lpc sftp
complete lpq sha256sum
comm lp.cups sh command lpoptions sha1sum compgen lppasswd sha224sum
continue lpr.cups
shift
compopt lpq.cups sha384sum consoletype lpr sha512sum
ControlPanel lprm shopt
coproc lprm.cups show-changed-rco
coredumpctl lpstat showconsolefont
cpio lrb showkey
cp lpstat.cups show-installed cpp lrx shred
cracklib-check ls
shutdown
cpupower lrz shuf
cracklib-
format lsattr signtool
cracklib-packer lsb signver
cracklib-unpacker lsblk size
crlutil lscpu slabtop
create-cracklib-dict lsb_release skill
crontab lsipc
sleep
crond lsinitrd slattach
csplit lslocks sln
csslint-
0.
6 lslogins slogin
ctrlaltdel lsmod smtp-sink
ctstat lsns smtp-source
curl lsof snice
date lsscsi
sort
cut lspci soelim
db_archive lsx sotruss
db_checkpoint lsz source
db_dump luac splain
db_deadlock lua spax
db_dump185 luseradd
split
db_hotbackup luserdel sprof
db_load lusermod sqlite3
db_log_verify m4 ss
db_recover mail ssh-add
db_printlog machinectl ssh
db_stat mailq ssh-copy-id
db_replicate Mail ssh-agent
db_upgrade mailx sshd-keygen
db_tuner mailq.postfix sshd
dbus-cleanup-sockets makedb ssh-keyscan
dbus-binding-tool make ssh-keygen
dbus-monitor man
stat
dbus-daemon makedumpfile ssltap
dbus-
send mandb stdbuf
dbus-uuidgen manpath strace
db_verify mapfile strace-
log-merge
dc mapscrn strings
dd markdown_py strip
debugfs mcookie su
deallocvt matchpathcon stty debuginfo-install md5sum sudo
delpart mii-diag sudoreplay
declare mesg sudoedit depmod mii-tool sulogin
dgawk
mkdir suspend
devlink mixartloader sum df mkdict sushell
dhclient mkdumprd swaplabel
dhclient-script mke2fs swapoff
diff3 mkfs switch_root
diff mkfifo swapon dir mkfs.btrfs sync
dirname mkfs.ext2 systemctl
dircolors mkfs.cramfs sysctl dirs mkfs.ext3 systemd-analyze
dmfilemapd mkfs.xfs systemd-cgls
disown mkfs.ext4 systemd-ask-password dmesg mkfs.minix systemd-cat
dmstats mklost+found systemd-delta
dmidecode mkhomedir_helper systemd-cgtop dmsetup mkinitrd systemd-coredumpctl
do mktemp systemd-firstboot
dnsdomainname mknod systemd-detect-virt dnsmasq mkswap systemd-escape
docker modinfo systemd-hwdb
docker-containerd modprobe systemd-inhibit
docker-containerd-ctr modutil systemd-loginctl
docker-containerd-shim more systemd-machine-id-setup
dockerd mount systemd-notify
docker-proxy mpstat systemd-path
docker-init mountpoint systemd-nspawn docker-runc msgattrib systemd-run
done msgcmp systemd-sysv-convert
domainname msgcat systemd-stdio-bridge dracut msgcomm systemd-tmpfiles
dwp msgfilter tabs
du msgconv systemd-tty-ask-password-agent dumpe2fs msgen sys-unconfig dumpkeys msgexec sz
e2label msginit tapestat
e2freefrag msgfmt tac e2fsck msggrep tail e2image msghack tailf e2undo msgmerge tar
easy_install-
2.7 nail tcpdump
e4defrag msgunfmt taskset eapol_test msguniq tbl easy_install mv tc
ebtables namei tcpslice
ebtables-restore nameif tcsd
echo ndptool teamdctl
ebtables-save native2ascii teamd
egrep netreport telinit
ecs_mq_rps_rfs needs-restarting teamnl ed neqn tee
elfedit nettle-hash testgdbm
eject netstat test elif nettle-lfib-stream then
else NetworkManager tic
enable newaliases tickadj
eni-ifscan newaliases.postfix
time
eni-version newgrp timedatectl
env new-kernel-pkg timeout
envsubst newusers
times
eqn nf-ct-add tload
esac nf-ct-list tmon
ether-wake nf-
exp-add tnameserv
ethtool nf-
exp-
delete toe
eval
nf-
exp
-list top
ex nf-
log touch
exec
nf-monitor tput
exit
nf-queue
tr
expand nfsiostat-sysstat tracepath
export ngettext tracepath6
expr nice trap
factor nl true
extcheck nisdomainname troff
faillock nl-addr-add
truncate
fallocate nl-addr-
delete trust
false nl-addr-list tset
fc nl-class-add tsort
fdformat nl-class-
delete tty
fdisk nl-classid-lookup tune2fs
fg nl-class-list tuned
fgconsole nl-cls-add tuned-adm
fgrep nl-cls-
delete turbostat
fi nl-cls-list type
file nl-fib-lookup typeset
filefrag nl-
link-enslave tzselect
find nl-
link-ifindex2name udevadm
find2perl nl-
link-list ul
findfs nl-
link-name2ifindex ulimit
findmnt nl-
link-release
umask
find-repos-of-install nl-
link-set umount
fipscheck nl-
link-stats unalias
fipshmac nl-list-caches uname
firewall-cmd nl-list-sockets unexpand
firewalld nl-monitor unicode_start
firewall-offline-cmd nl-neigh-add unicode_stop
fixfiles nl-neigh-
delete uniq
flock
nl-neigh-list unix_chkpwd
fmt nl-neightbl-list unix_update
fold nl-pktloc-lookup
unlink
for
nl-qdisc-add unpack20
0
free nl-qdisc-
delete unset
fsck nl-qdisc-list unshare
fsck.btrfs nl-route-add
until
fsck.cramfs nl-route-
delete unxz
fsck.ext2 nl-route-get unzip
fsck.ext3 nl-route-list unzipsfx
fsck.ext4 nl-rule-list update-alternatives
fsck.minix nl-tctree-list update-ca-trust
fsck.xfs nl-util-addr update-mime-database
fsfreeze nm update-pciids fstrim nmcli uptime
fuser nmtui-
connect userdel
function nm-online urlgrabber funzip nmtui useradd
fxload nmtui-edit usermod
gapplication nmtui-hostname usernetctl
gawk nohup users
gcc-ar nproc usx2yloader
gcc nologin usleep
gcc-ranlib nscd uuidgen
gcc-nm nroff utmpdump gcov nsenter vdir
genhomedircon ntpdate view
gdbus nstat verifytree gencat ntpd vi genhostid ntpdc vigr
geoiplookup6 ntptime vipw
genl ntp-keygen vim genl-ctrl-list ntpq vimdiff geoiplookup ntpstat vimtutor
getconf od vlock
geoipupdate numfmt virt-what geqn objcopy virt-what-cpuid-helper getcap objdump visudo
getent
open vmstat
getenforce oldfind vmcore-dmesg
getfacl openssl vpddecode
getkeycodes openvt vxloader
getopts os-prober
wait
getopt orbd w
getpcaps ownership wall
getsebool p11-kit watch
gettext pack20
0 watchgnupg
gettext.sh
package-cleanup wc
gio packer wdctl
gio-querymodules-
64 pam_console_apply weak-modules
glib-compile-schemas pam_tally2 wget
glibc_post_upgrade.i686 pam_timestamp_check whatis
glibc_post_upgrade.x86_64 parted whereis
gmake partprobe which
gneqn partx
while
gnroff passwd whiptail
gpasswd paste who
gpg2 pathchk wipefs
gpg patch whoami
gpgconf pchrt wpa_passphrase
gpg-agent pax wpa_cli
gpg-
connect-agent peekfd wpa_supplicant
gpg-error perl
write
gpgparsemail perl5.
16.3 wsgen
gpgsplit perlbug wsimport
gpgv perldoc x86_64
gpgv2 perlthanks x86_64-redhat-linux-gcc
gpg-zip pflags x86_energy_perf_policy gpic pgawk xargs
grep pic xfs_bmap
gprof pgrep xfs_admin groff piconv xfs_copy
grotty pidstat xfs_estimate
grops pidof xfs_db
groupdel pinentry-curses xfs_fsr
groupadd pinentry xfs_freeze
groupmod ping6 xfs_info
groupmems ping xfs_growfs groups pinky xfs_io
grpconv pip2 xfs_mdrestore
grpck pip xfs_logprint
grpunconv pip2.
7 xfs_metadump
grub2-bios-setup pivot_root xfs_mkfile
grub2-editenv pk12util xfs_ncheck
grub2-fstest pkcheck xfs_repair
grub2-file pkaction xfs_quota grub2-get-kernel-settings pkcs1-conv xfs_rtcp
grub2-kbdcomp pkill xmlcatalog
grub2-glue-efi pkexec xgettext grub2-install pkg-config xjc grub2-macbless pkla-admin-identities xmllint
grub2-mkimage pldd xz
grub2-menulst2cfg pkla-check-authorization xmlwf grub2-mkconfig pkttyagent xtables-multi grub2-mkfont pl2pm xxd
grub2-mkrescue pmap xzegrep
grub2-mklayout plipconfig xzcat grub2-mknetdir plymouth xzcmp grub2-mkpasswd-pbkdf2 plymouthd xzdec grub2-mkrelpath plymouth-set-default-theme xzdiff
grub2-render-label policytool yes
grub2-mkstandalone pod2html xzfgrep grub2-ofpathname pod2man xzgrep grub2-probe pod2text xzless grub2-reboot pod2usage xzmore
grub2-rpm-
sort popd ypdomainname
grub2-script-check postalias yum
grub2-set-default postcat yum-builddep
grub2-setpassword postconf yum-complete-transaction
grub2-sparc64-setup postdrop yum-config-manager
grubby post-grohtml yum-debug-
dump
grub2-syslinux2cfg postfix yumdb
gsettings postkick yum-debug-restore
gshelld postlock yumdownloader
gsoelim postlog yum-groups-manager
gtar postmap zcat gtbl postmulti zcmp
gzexe powernow-k8-decode zegrep
gtroff postqueue zdiff gunzip postsuper zdump
halt pppdump zgrep
gzip poweroff zfgrep h2ph pppd zforce hardlink pppoe-discovery zic
head pr zipgrep
hash pppstats zip hdsploader ppp-watch zipcloak help preconv zipinfo
hostid
printf zless
hexdump pre-grohtml zipnote history printenv zipsplit
hostname prlimit zmore
hostnamectl prtstat znew
hwclock ps zramctl
i386 psed zsoelim
iconv psfaddtable
所有评论(0)