Basic CLI (Command Line Interface) Tools Pt. 1
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
This will display the contents of your current working directory, which should look something like this,
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:
the output from this command will look like this:
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:
this will show man information for the program apropos which will look something like this:
The info utility is used in the same way:
Here is the info file on apropos:
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.
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:
its output looks like this:
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:
. If you want to view just the end of a file use the command tail:
Redirection is an important part of the linux system: to redirect a file you can type this command:
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!
Code:
ls
Code:
bin Documents Music Public Templates Desktop Downloads Pictures public_html Videos
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
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
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
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
Code:
info 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.
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
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
Code:
grub: /usr/sbin/grub /etc/grub.d /usr/lib/grub /usr/share/man/man8/grub.8.gz
If you just want to view the top of the file use the command top:
Code:
top file name
Code:
tail file name
Code:
more /home/examplefile <example file .txt
This is just the tip of the ice berg when it comes to CLI commands. Keep attuned for Pt. 2 of the series!
Total Comments 2
Comments
-
Wow! Thanks for posting these!!!!
Posted 06-05-2013 at 09:20 AM by vmccord -
Posted 06-05-2013 at 07:07 PM by Nbiser