LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Blogs > Nbiser
User Name
Password

Notices


Rate this Entry

Basic CLI (Command Line Interface) Tools Pt. 1

Posted 06-04-2013 at 04:11 PM by Nbiser
Updated 06-04-2013 at 04:16 PM by Nbiser

There are many tools in the command line interface that are good to know if you want to use Linux. But don't worry, they aren't all that hard to learn! First, you will need to open a terminal window (only if you are using a graphical user interface (GUI). Once you are in the terminal you can type
Code:
ls
This will display the contents of your current working directory, which should look something like this,
Code:
bin      Documents  Music     Public       Templates
Desktop  Downloads  Pictures  public_html  Videos
You can then view the various contents of your current working directory, in this case the home folder.

If you are looking for a program or file, you can use the command apropos. For this example we will look for a text editor:
Code:
apropos  editor
the output from this command will look like this:
Code:
atobm (1)            - bitmap editor and converter utilities for  the X Window...
bitmap (1)           - bitmap editor and converter utilities for the X Window...
bmtoa (1)            - bitmap editor and converter utilities for the X Window...
editres (1)          - a dynamic resource editor for X Toolkit applications
ex (1)               - Vi IMproved, a programmers text editor
gview (1)            - Vi IMproved, a programmers text editor
gvim (1)             - Vi IMproved, a programmers text editor
jfs_debugfs (8)      - shell-type JFS file system editor
mcedit (1)           - Internal file editor of GNU Midnight Commander.
nano (1)             - Nano's ANOther editor, an enhanced free Pico clone
rgview (1)           - Vi IMproved, a programmers text editor
rgvim (1)            - Vi IMproved, a programmers text editor
rnano (1)            - Restricted mode for Nano's ANOther editor, an enhanced...
rview (1)            - Vi IMproved, a programmers text editor
rvim (1)             - Vi IMproved, a programmers text editor
sed (1)              - stream editor for filtering and transforming text
vi (1)               - Vi IMproved, a programmers text editor
view (1)             - Vi IMproved, a programmers text editor
vim (1)              - Vi IMproved, a programmers text editor
xedit (1)            - simple text editor for X
Here you can see the various editors on this system, you then simply type in the name of the editor that you want to use, and it will launch.

If you want to find out more about a program or command you can use the man or info tools: the example will use the program apropos:
Code:
man  apropos
this will show man information for the program apropos which will look something like this:
Code:
APROPOS(1)                                                                           Manual pager utils                                                                            APROPOS(1)



NAME
       apropos - search the manual page names and descriptions

SYNOPSIS
       apropos [-dalhV] [-e|-w|-r] [-s section] [-m system[,...]] [-M path] [-L locale] [-C file] keyword ...

DESCRIPTION
       Each manual page has a short description available within it.   apropos searches the descriptions for instances of keyword.

       keyword  is  usually  a regular expression, as if (-r) was used,  or may contain wildcards (-w), or match the exact keyword (-e).  Using  these options, it may be necessary to quote
       the keyword or escape (\) the special characters to stop the shell from interpreting them.

       The standard matching rules allow matches to be made against the page name and word boundaries in the description.

       The database searched by apropos is updated by the mandb program.   Depending on your installation, this may be run by a periodic cron  job, or may need to be run manually after new
       manual pages have been installed.

OPTIONS
       -d, --debug
              Print debugging information.

       -v, --verbose
              Print verbose warning messages.

       -r, --regex
              Interpret each keyword as a regular expression.  This is  the default behaviour.  Each keyword will be matched against the page  names and the descriptions independently.  It
              can match any part of either.  The match is not limited to word boundaries.

       -w, --wildcard
              Interpret each keyword as a pattern containing shell style  wildcards.  Each keyword will be matched against the page names and the  descriptions independently.   If  --exact
              is  also  used, a match will only be found if an expanded  keyword matches an entire description or page name.  Otherwise the  keyword is also allowed to match on word bound-
              aries in the description.

       -e, --exact
              Each keyword will be exactly matched against the page names and the descriptions.

       -a, --and
              Only display items that match all the supplied keywords.  The default is to display items that match any keyword.

       -l, --long
              Do not trim output to the terminal width.  Normally,  output will be truncated to the terminal width to avoid ugly results  from poorly-written NAME sections.

       -s section, --section section
The info utility is used in the same way:

Code:
info apropos
Here is the info file on apropos:

Code:
ile: *manpages*,  Node: apropos,  Up: (dir)

APROPOS(1)                                                                           Manual pager utils                                                                           APROPOS(1)



NAME
       apropos - search the manual page names and descriptions

SYNOPSIS
       apropos [-dalhV] [-e|-w|-r] [-s section] [-m system[,...]] [-M path] [-L locale] [-C file] keyword ...

DESCRIPTION
       Each manual page has a short description available within it.   apropos searches the descriptions for instances of keyword.

       keyword  is  usually  a regular expression, as if (-r) was used,  or may contain wildcards (-w), or match the exact keyword (-e).  Using  these options, it may be necessary to quote
       the keyword or escape (\) the special characters to stop the shell from interpreting them.

       The standard matching rules allow matches to be made against the page name and word boundaries in the description.

       The database searched by apropos is updated by the mandb program.   Depending on your installation, this may be run by a periodic cron  job, or may need to be run manually after new
       manual pages have been installed.

OPTIONS
       -d, --debug
              Print debugging information.

       -v, --verbose
              Print verbose warning messages.

       -r, --regex
              Interpret each keyword as a regular expression.  This is  the default behaviour.  Each keyword will be matched against the page  names and the descriptions independently.  It
              can match any part of either.  The match is not limited to word boundaries.

       -w, --wildcard
              Interpret each keyword as a pattern containing shell style  wildcards.  Each keyword will be matched against the page names and the  descriptions independently.   If  --exact
              is  also  used, a match will only be found if an expanded  keyword matches an entire description or page name.  Otherwise the  keyword is also allowed to match on word bound-
              aries in the description.

       -e, --exact
              Each keyword will be exactly matched against the page names and the descriptions.

       -a, --and
              Only display items that match all the supplied keywords.  The default is to display items that match any keyword.

       -l, --long
-----Info: (*manpages*)apropos, 119 lines  --Top------------------------------------------------------------------------------------------------------------------------------------------------
Welcome to Info version 4.13. Type h for help, m for menu item.
You can see that the use of the program at the top, and options that can be used in conjunction with the program. Man and info are pretty easy to use, you just have to get used to using them.

The cat command is used to output the contents of a text file: however, I prefer to use the more and less commands. There use is pretty simple.

Code:
more file name
Code:
less file name
The output will be the displayed and you can then page through it.

whereis is used to search for a file name, file, or program, after the search is completed it will display the location of what you were searching for. Here is an example:
Code:
whereis  grub
its output looks like this:
Code:
grub: /usr/sbin/grub  /etc/grub.d /usr/lib/grub /usr/share/man/man8/grub.8.gz
You can then navigate to the location of the file with ls.

If you just want to view the top of the file use the command top:
Code:
top file name
. If you want to view just the end of a file use the command tail:
Code:
tail file name
Redirection is an important part of the linux system: to redirect a file you can type this command:
Code:
 more /home/examplefile <example file .txt
you can then open the .txt file with a text editor or with more and less.

This is just the tip of the ice berg when it comes to CLI commands. Keep attuned for Pt. 2 of the series!
Posted in Uncategorized
Views 8913 Comments 2
« Prev     Main     Next »
Total Comments 2

Comments

  1. Old Comment
    Wow! Thanks for posting these!!!!
    Posted 06-05-2013 at 09:20 AM by vmccord vmccord is offline
  2. Old Comment
    Quote:
    Originally Posted by vmccord View Comment
    Wow! Thanks for posting these!!!!
    No problem!
    Posted 06-05-2013 at 07:07 PM by Nbiser Nbiser is offline
 

  



All times are GMT -5. The time now is 10:43 PM.

Main Menu
Advertisement
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration