Sunday, 5 March 2017

10 funny and useful things you can do in Ubuntu command line


Ah, the command line! Refuge of a scoundrel, a proving ground for the expert, the tool selected advanced user.
The following 10 tips explain how to do cool and interesting things on the command line. They are not specific to Ubuntu, but were written with the expectation of it, and not tested on other distributions. However, all should work in most versions of Linux, and even Unix.

Use the mouse in the virtual console

It's a neat hack, which has given a rectangular cursor, so that the text can be easily copied and pasted into a virtual console. Simply use Synaptic, to install gpm. By installing the utility, open a terminal window and type "sudo /etc/init.d/gpm", to start the program. In the future, gpm will start automatically at boot time.
Then switch to a virtual console to see the fruits of their labor. Now you should have a rectangular cursor that moves across the screen. You can select text in the usual way. To paste it, click the middle mouse button (usually the scroll wheel mouse is, if your mouse has only two buttons, pressing the right insert text).
Some software that offers a text-based menu, such as responding to a mouse click (for example, text the Lynx web browser, see below). Check the help for the team, there is a special option is needed to support gpm.

See calendar

You probably already knew that pressing the panel with the clock in the upper right corner of the Ubuntu desktop will display a calendar. To see the same little thing on the command line, type cal. Without any command-line arguments, it will show the current month. If you want to turn the axis of the calendar (days to show up vertically, rather than horizontally), type ncal. To see the current month and the preceding with the following, type cal -3 (for some reason, this option does not work with ncal).
To view the calendar for the whole year, write the year immediately following commands: cal 2010. To see the calendar of December of any year, write and cal dec year (you can write jan, mar, etc.).
Both teams (cal and ncal) can be used to search for historical dates. To find the date of the signing of the Declaration of Independence print cal july 1776. If you seriously need to know the exact dates that go back millennia, then you may have problems with switching between the Julian and Gregorian calendars; for details, refer to the manual page cal.

Create text banners

Run Synaptic, look for and install figlet. Then type the following in the terminal:
figlet "Ubuntu Kung Fu"
Output consists of symbols, letters and other signs. Even different fonts available (see. / Usr / share / figlet). The file with the extension .flf contains the font. To use a different font, simply specify its name after the -f option in the command line (without the file extension):
figlet -f lean "Ubuntu Kung Fu"
Believe it or not, but figlet used very serious (well, in fact, his elder brother called banner). While net dot matrix printers and sheet of paper the team used to clearly identify who sent a document to the printer. Text banner appeared at the beginning of each printed document, so that it becomes clear where it was necessary to tear off the sheet.
I love to add figlet command at the end of my .bashrc file, so that the program runs every time I go to a virtual console or open a terminal window. Simply type "gedit ~ / .bashrc", to open the file in Gedit and add a team entirely new line. If you want to bring up a proposal and not a single word, be sure to take the proposal in quotes (like this: figlet -f small "Greetings Professor Falken").
Maybe you want to look at another tool, called unsuccessfully toilet, which does exactly the same thing, but it is possible to change the color. By installing it, try the following:
toilet -f mono12 -F gay "Ubuntu Kung Fu"

A visual representation of files / directories

If you do not know (and even if they are familiar), you can easily get lost while browsing the file system. You can use the pwd for a quick reminder of the current directory, but you can use the tree command. To begin, you must install it using Synaptic - look for and install tree. Then simply type "tree" in the command prompt. That's what I saw in my test system, when introduced this command in your home directory:
.
| - Desktop
| | - Gnome-terminal.desktop
| `- Synaptic.desktop
| - Documents
| | - Accounts08.ods
| `- Brochure.pdf
| - Examples -> / usr / share / example-content
| - Music
| `- Tom gold-magic.mp3
| - Pictures
| | - Barbecue.jpg
| `- Disneyland.jpg
| - Public
| - Templates
`- Videos

It should be apparent that there is. Directories (Desktop, Documents, Music, etc.) are presented as a virtual branch of the tree and the files (or a subdirectory) - a branch of the second level. Here it is not visible, but very useful is the fact that everything is painted in the colors used in the standard console. Thus, a light-blue folder, image files and mp3-files, green, etc. To see only the files directory without them (perhaps it is more useful), use the -d option: tree -d. To filter the results for specific types of files or files with a certain name, use the -P option. For example, to search for .doc files, you need to type the following:
tree -P * .doc
Or to search for files that contain in its name "disneyland", you need to type the following:
tree -P * disneyland *
And since all this is not enough, at the tree has a trump card in his sleeve: it can output everything as html-file. This can be useful if you need to quickly create the output directory with the files on the network. Suppose you have a web site called http://www.example.com and local directory that contains the local copy of the site, - / home / keir / website . The following command will show the index.html file called, which contains a visual representation of the tree of files that make up the website, including hyperlinks to the files:
$ Tree -H <a href="http://www.example.com"> http://www.example.com </a> -T "Click a file to download" / home / keir / website /> index.html
First of all, we provide URL, which will be preceded by reference. This may be part of the path on the server (for example, www.example.com/files ; note that you should not include a terminal slash). Then we specify the -T option page title - it can be anything, but stay away from the type of characters that have a specific command-line tool "!". Then we specify the location of files. And finally, we redirect the output to a file index.html.

View PDF on the command line

If you want to view the PDF, just use Evince program: evince filename.pdf - so you run the Viewer PDF. If you really want to view a PDF in a terminal window (or, perhaps, in the virtual console), first you need to convert it into text. To do this, use the program pdftotext: pdftotext filename.pdf - this will create a .txt with the contents of a PDF file. For its display, use less command: less filename.txt. To extract images from PDF, use the command pdfimages. You need to specify the file name for the image and use the -j option to make sure that images are displayed as a JPEG. For example, here it is:
pdfimages -j filename-pdf pictures
will extract images as JPEG and give them names beginning with "pictures". So, the first to be called pictures-001.jpg, second - puctures-002.jpg, etc
Reflect commands and output to different terminal windows
In order to obtain the contents of a single terminal to another, to start a session, run screen in it. Screen allows you to create a command-line session that is independent of any other existing terminal or virtual console (so that if the window is closed, the session will still run in the background).
To run it, just type screen. Then, open a new terminal window and add it to the current session by typing "screen -x". Now try to print something, to see what effect. To disconnect from the session (in one or both terminals), press Ctrl + A and then d. Remember that if you disconnect both terminals, the session screen will still run in the background. To complete it, you need to reconnect to the screen (print "screen -r") and then press Ctrl + d (or just type "exit" at the prompt).
This trick works in the virtual console: you can run a screen session in the terminal, and it is "mirror your" at the invitation of the virtual console after you connect it using screen -x command.
By combining this technique with a remote connection for SSH, you can not only create a session (using the screen), which will remain on the remote computer, even if the SSH-connection is lost (this is useful if you run the command, which takes some time to complete the task, or if you have an unstable connection), but you can also create a scheme whereby everything that you enter will be displayed in the remote computer terminal window (just ask the user sitting at the remote computer, open a terminal and type screen -x, after you run the screen in the SSH session). This is an excellent opportunity for distance learning.

Place the console output and files to the clipboard

It would be very useful to quickly send the configuration file or the output of a console command to the clipboard for pasting it to a web page or online for something like that, is not it? In general, this is what made xclip utility. It can be installed using Synaptic. After installation, you can redirect files in xclip, so that they become the clipboard contents. Command
xclip </ etc / fstab
add the contents of the configuration file / etc / fstab to the clipboard. Or you can apply the output of the conveyor:
dmesg | xclip
put the output of dmesg to the clipboard (dmesg shows the output of the system log, and can be useful in diagnosing problems). There is one caveat. Files transferred by the conveyor are placed in a buffer of choice, which is different from the standard clipboard ( "cut and paste") from the menu "Edit" most applications. Content xclip can be inserted by placing the cursor in the appropriate place and pressing the middle mouse button (which means pressing the scroll wheel, if it is in your mouse, if it does not, simultaneously press the left and right buttons). Theoretically, the use xclip -selection option must be to allow the user to add new data to the original clipboard, but does not look like it works - perhaps because, as the configured desktop in Ubuntu. To be honest, I think this is more a feature, not a bug: xclip leave untouched any existing buffer exchange.

Let Ubuntu speaks to you

Ubuntu has a built-in speech synthesizer called espeak. It works in conjunction with a program to read the Orca screen that provides support for those who have difficulty seeing. It may be invoked from the command line, as in the following case:
espeak "Ubuntu Kung Fu"
As they say, it's not the most perfect in the world of speech synthesizer (a feeling that "Speak & Spell" just about it), but it can be fun to play with him. Just print "espeak", press "Enter" - and everything that you write after that will be uttered. To exit, press Ctrl + d. To switch voices, use the -v option. But first you need to find the available voices, it can be done by typing "espeak --voices = en" (note that before the "voices" two hyphens). For example, to the phrase "How about a nice game of chess?" Pronunciation Jamaican voice type is:
140 espeak -s -v en-westindies "How about a nice game of chess?"
In this example, I added the -s option by which you can determine the speed of speech, expressed as the number of words per minute. The default value is 170 words per minute, which is a bit fast, especially for long sentences.

Get rid of legal templates in a virtual console

Whenever you were in the virtual console, you will see a few paragraphs of legal information, reminding you that Ubuntu is free software and comes without warranty. Once, after reading this, you're unlikely to forget, so to stop the emergence of the information in each session, you can start typing in the terminal the following:
sudo rm / etc / motd
sudo touch / etc / motd
that will remove the contents of the file "Council of the day" (message of the day, motd - prim.per), which is responsible for the message.
Of course, instead of removing the contents of the file, you could replace the text in it to anything else - it is a simple text file. Open it in Gedit, typing "gksu gedit / etc / motd", and change the contents of what you want.

See Internet sites from the command line

Call it a form of reassurance, but I like to use the console in a web browser when something is wrong with Firefox or entire graphics system. I can look for help and solutions from a virtual console or just check the news, waiting for bug fixes.
Console browsers are very primitive. They have no images, for example, or even color. Their design is always iskorĐĹzhen. In other words, they are not designed for continuous use, if you're not a masochist. Or fanatic console.
There are two competing text browser - links and lynx. Links, perhaps the best of them, because he understands the frames, and therefore page template a little more correct, but they are both just download via Synaptic from you (a download away, both in the common phrase "a step away" ( "in the step from ... ", that is very close) - prim.per)..
After running any of the programs, press g, to enter the URL (in the lynx you will also need to write http: //, if the address does not begin with www.). When the page loads, use the Page Up and Page Down keys to scroll. Use the arrow keys "up" / "down" to take place on the links until you find the desired, then press "Enter" to go on it. To return to the previous page, press the arrow key "left". To upload a file, for which there is a link, select it and press d. You can search for words on a page using a slash (/), as well as in the manual pages for Linux.
Clicking links in Ecs cause basic menu; Use the arrow keys to navigate through it, and press "Enter" to select. When you are finished, press q to exit the program. If links running in a terminal window, you can use the mouse to click on the link.
If gpm is installed (see above), you will be able unpretentious mouse control in a browser, and you will be able to click on the links to the virtual console.

1 comment:

  1. You need to be careful with your spaces "sudo rm / etc / motd"?? Really??

    ReplyDelete