About Linux FAQ

Browse More FAQs:

Linux command - finding and running commands

Posted by Vivek Gite [Last updated: January 9, 2007]

Q. I am new to Linux. How do I find and run commands under Linux?

A. Linux comes with lots of commands. But don't worry it offers commands to find them. Try following commands
which
apropos
locate
find
ls -l

Task: locate the binary, source, and manual page files for a command

whereis locates source/binary and manuals sections for specified files. 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 a list of standard Linux places. For example find out where is ls command?
$ whereis ls
Output:

ls: /bin/ls /usr/share/man/man1/ls.1.gz

Task: Display short descriptions about command

Each manual page has a short description available within it. whatis searches the manual page names and displays the manual page descriptions of any name matched.
$ whatis ls
Output:

ls (1)               - list directory contents

Task: Locate a command with which command

which command returns the pathnames of the files 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.
$ which ls
$ which -a date

Task: search the manual page names and descriptions for commands using apropos command

Each manual page has a short description available within it. apropos searches the descriptions for instances of keyword. This is useful to find out command according to task. For example display command that deletes a user, use
$ apropos 'delete a user'
Output:

userdel (8)          - Delete a user account and related files

Other examples
$ apropos 'delete'
$ apropos 'icmp'

Task: list files in databases using locate command

Use to find out location of file. If you forget location of file called httpd, use locate as follows:
$ locate httpd.conf
Output:

/etc/apache2/httpd.conf
/etc/lighttpd/lighttpd.conf
/etc/lighttpd/lighttpd.conf.BAK
/home/vivek/etc/apache2/httpd.conf
/home/vivek/etc/lighttpd/lighttpd.conf
/home/vivek/etc/lighttpd/lighttpd.conf.BAK
/usr/share/doc/lighttpd/examples/lighttpd.conf.gz
/var/lib/dpkg/info/lighttpd.conffiles

Task: find command & files using 'find' command

=> See this previous article about find command examples.

Task: ls -l command

ls -l command provides detailed information about file. See this article [Find out information about my file - explaining ls command] for more information.

E-mail this to a friend      Printable version

Related Other Helpful FAQs:

Leave a Reply

We encourage your comments, and suggestions. But please stay on topic, be polite, and avoid spam. Thank you very much for stopping by our site!

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word

Copyright © 2006-2008 nixCraft. All rights reserved - TOS/Disclaimer - Privacy policy - Sitemap - Powered by Open source software.