Mencari file (lagi)

Tulisan saya tempo hari ternyata berlanjut. Perkenalan dengan perintah find mengantar saya mengenal tiga perintah lain yang hampir mirip.

find

Mencari file di direktori aktif (current directory)

Format:

find . -iname bla-bla-bla

Contoh:
Mencari file atau folder bernama data di dalam folder saat ini.

find . -iname data

Kalau muncul pesan find: xxxxx: Permission denied, tambahkan sudo sebelum perintah find seperti ini:

sudo find . -iname data

Contoh 2:
Mencari semua file dan folder yang namanya mengandung kata catatan

sudo find . -iname "*catatan*"

Mencari file di direktori lain

Format:

find /path/to/folder/ -iname bla-bla-bla

Contoh:
Mencari semua file atau folder yang namanya mengandung kata fox di direktori /usr/lib/firefox

$ find /usr/lib/firefox -iname "*fox*"
/usr/lib/firefox
/usr/lib/firefox/browser/features/firefox@getpocket.com.xpi
/usr/lib/firefox/browser/defaults/preferences/vendor-firefox.js
/usr/lib/firefox/firefox
/usr/lib/firefox/firefox.sh

locate

locate mencari file berdasarkan nama.

locate – find files by name.
locate reads one or more databases prepared by updatedb and writes file names matching at least one of the PATTERNs to standard output, one per line.
— from man locate

Format:

locate [OPTION]... PATTERN...
locate -b apa-yang-dicari

Contoh:
Mencari semua file yang namanya mengandung kata catatan

locate -b 'catatan'

locate memang mirip dengan find. Bedanya, locate jauh lebih cepat. Meski begitu, find punya banyak kelebihan dibanding locate (baca di sini).

locate has only one big advantage over find: speed. find, though, has many advantages over locate: …

which

Mencari lokasi program.

which – locate a command.
which returns the pathnames of the files (or links) which would be executed in the current environment, had its arguments been given as commands in a strictly POSIX-conformant shell. It does this by searching the PATH for executable files matching the names of the arguments. It does not follow symbolic links.
— from man which

Format:

which [-a] filename ...
which filename

Contoh:
Mencari lokasi program firefox

$ which firefox
/usr/bin/firefox

whereis

Mirip which tapi lebih lengkap.

whereis – locate the binary, source, and manual page files for a command.
whereis locates the binary, source and manual files for the specified command names. The supplied names are first stripped of leading pathname components and any (single) trailing extension of the form .ext (for example: .c) Prefixes of s. resulting from use of source code control are also dealt with. whereis then attempts to locate the desired program in the standard Linux places, and in the places specified by $PATH and $MANPATH.
— from man whereis

Format:

whereis [options] [-BMS directory... -f] name...
whereis nama-program

Contoh:
Mencari lokasi file dan program firefox

$ whereis firefox
firefox: /usr/bin/firefox /usr/lib/firefox /etc/firefox /usr/share/man/man1/firefox.1.gz

Selamat mencoba, semoga bermanfaat.

Baca juga:

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s