User:Shenlebantongying/deleted

From Wikibooks, open books for an open world
Jump to navigation Jump to search

What i deleted:

From Ruby_Programming/Installing_Ruby[edit | edit source]

Terminal emulators[edit | edit source]

Knowing how to use a terminal emulator is very useful if you are programming. Usually it will provide the most straightforward access to commands and applications instead of hiding it behind graphical interfaces. On the other hand they are often daunting to beginners since they are often perceived to require a deep understanding of a computer when in fact often only knowing the very basics is already enough to get started.

Unix-like operating systems[edit | edit source]

Screenshot of xterm running Bash

One of the most commonly used shells in the Unix-like operating systems (i.e. macOS, GNU/Linux, BSD) is the Bash shell, in fact it is very often the default shell. To start a session you will often use a terminal emulator, which allow you to use a terminal session at the same time as other graphical applications. It doesn't really matter, which terminal emulator you use, generally you want one that has color and Unicode support. In macOS you can use Terminal.app which you can find under Applications > Utilities. A popular alternative is iTerm. On most Linux distributions you will usually be provided with at least one terminal emulator by default, otherwise you might want to try Terminator, Konsole, rxvt-unicode or something different.

When you open a new window or tab in your terminal emulator of choice you will be shown your prompt. What it looks like exactly depends a lot on configuration, which can vary greatly from OS to OS (you can configure everything to your likings, however this exceeds the scope of this short introduction). Generally it will indicate your current working directory, username and hostname. When working in the shell your session always has current working directory. Commands that accept relative filenames will use that directory as the base directory to look for files. By default you are in your user's home folder, which is often abbreviated with a tilde (~).

To execute a command you just type it into the shell and press enter.

At first we want to look at the command ls. If you type it in just like that it will print the files and directories in your current working directory. You can also provide a relative path to a directory you want to list, e.g. ls DIR. If you want more detailed information about the files you can use ls -l DIR, if you instead want to also include invisible entries (i.e. names starting with a dot) use ls -a. Of course it is possible to combine them both by running ls -l -a DIR or the short form ls -la DIR. Note that this kind of concatenating multiple arguments into one is only possible with single character parameters. Parameters can also come in long form, for example the equivalent of ls -a is ls --all DIR. Which forms are available depends on the individual command.

Now you might be thinking how to remember all parameters for every command you will ever use. Thankfully you only want to remember the most important ones, which are the ones you use most frequently, otherwise there is a nice way to look them up. You can either use the man command. For example run man ls to find more information about the ls command. Oftentimes you can find a more concise summary by trying to run the command in question followed by the parameter --help, however this is not something you can expect to work well with every command, whereas manual pages should be always available.

Back to the topic of current working directories. If you want to change your directory you can use cd followed by the directory you want to change to. There are two special virtual directories '.' and '..'. The single dot refers to the current directory while the double dot refers to a dir's parent directory. So executing cd .. changes into the parent directory of the current working directory.

A very brief summary of other useful commands:

cat FILE: display the contents of a file.

mkdir DIR: create a directory.

Windows[edit | edit source]

Windows doesn't use the Bash shell and in the past it was hard to get Bash to work on Windows. Users of Windows 10 Anniversary Update build 14393 or later however now have the ability to install a Ubuntu subsystem which will essentially provide them with a working Bash shell and access to many commands found in the Ubuntu Linux distribution. Users wishing to use Bash on Windows 10 are advised to follow the official installation instructions from Microsoft. After the installation you can basically follow the instructions for Ubuntu/Debian.

If you don't want to do that you have two options:

  1. Go with another non-Microsoft project providing a Bash environment for Windows. For example you can install Cygwin, a collection of free software tools available for Windows. During the install, make sure that you select the "ruby" package, located in the "Devel, Interpreters" category.
  2. Use the Windows Powershell. You might sometimes have to write something different than in this book, but for basic examples this might still be enough and safe you the time you would otherwise need for installation. However if you are serious about learning a shell, learning Bash has the advantage that it is not exclusive to Windows, unlike Powershell, which prevents you from being locked in into a platform should you one day decide to switch to Unix-like operating systems or use a non-Windows server.