Библиотека сайта или "Мой Linux Documentation Project"
The shell tips chapter provides handy tricks that you may wish to use when you are using a GNU/Linux shell (the command-line interface). This information includes handy shortcut key combinations, the shell's command history and information on virtual terminals.
If you can't boot into your system: If your having problems booting into your system you may like to use a shell so you can boot into your system and attempt to fix things up again.
To do this you need to pass the “init=/bin/sh” to your system before you boot up.
If you don't know how to do this please see Chapter 14, the technique is the same except this time you pass "init=bin/sh" rather than "single".
- Automatic Command Completion
Use the TAB key and bash will attempt to complete the command for you automatically. You can use it to complete command (tool) names. You can also use it when working with the file-system, when changing directories, copying files et cetera.
There are also other lesser known ways to use automatic command completion (for example completing user names):
- ESC-Y (Y: special character)
testing autoindexing Will attempt to complete the command name for you. If it fails it will either list the possible completions (if they exist). If there are none it will simply beep (and/or) flash the screen.
- CTRL-X-Y (Y: special character)
! (exclamation mark) a magic character for completing a command name or a file name. The ! special character has the same function as the TAB key. It works in some other situations; for example when completing man page names.
An alias allows one command to be substituted for another. This is used to make a command do something else or to automatically add certain options. This can be either be done during one session using the alias command (see below) or the information can be added to the .bashrc file (found in the users home directory).
Below is an example of what an alias section (within your .bashrc file) might look like:
# my personal aliases alias cp='cp -vi' #to prompt when copying if you want to overwrite and will tell you where information is going alias rm='rm -i' #Prompts you if you really want to remove it. alias mv='mv -i' #Prompts you if you are going to overwrite something
On any Mandriva GNU/Linux system the global aliases (for all users) are all in /etc/profile.d/alias.sh. The above listed commands already have aliases, as well as several other commonly used commands.
- set -x
This can be useful to find out what is happening with certain commands such as things being quoted that contain wildcards or special symbols that could cause problems, or complex aliases. Use set +x to turn this back off.
After using set -x you can run the command:
+ ls -F --color=auto
- \ (backslash)
Please note that the alias for the remove command is there for a reason. Using it incorrectly could remove files which you don't want removed.
Only use \rm if you know exactly what you are doing (recovering files is not easy, rm does not send things to a recycle bin).
The “\” character can be used before special characters (such as a space or a wildcard), to stop bash from trying to expand them. You can make a directory name with a space in it using a backslash before the space. For example you could type cd My\ Directory\ With\ Spaces which normally wouldn't work.
- ~ (tilde character)
Home directory shortcut: ~ (tilde) can also be used as a shortcut to other users home directories, simply type: ~user_name and it will take you to the users home directory. Note that you need to spell the username exactly correct, no wildcards.
- set bell-style none
This particular set command will turn off the system bell from the command-line (use xset -b for X windows). If you want the bell to stay off pernamently (no audible bell) then you can add this command to your “.bashrc” or “.bash_profile” (just add it to the same one you have your alises in...).
echo “hello world”
Simply displays “ hello world”.
echo rm -R *
This will output what will be passed to the rm command (and therefore what would be deleted), putting echo before a command renders it harmless (it just expands wildcards so you know what it will do).
Using echo to prevent accidents: Typing: echo command(s) could save you the trouble of accidentally doing something you didn't expect.
Using echo allows you to expand the wildcards to understand what will happen before you actually run the command.
This information was adopted (with editing) from Mandrakesoft's Command Line Manual, see  in the Bibliography for further information.
Только зарегистрированные пользователи могут оценивать и комментировать статьи.