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)
- Lists the possible completions (it won’t attempt to complete it for you) or beep if there are no possible completions.
Use the following special characters combined with either ESC–Y or CTRL–X–Y , where Y is some special characters. For example ESC–$ or CTRL–X–$ to complete an environment variable name.
- ~ (tilde) complete a user name
- @ (at sign) complete a machine name
- $ (dollars sign) complete an environment variable name
- ! (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.
The alias command will list your current aliases. You can use unalias to remove the alias (to disable it just for one command add a “\” (back-slash) before the command)…
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 is one of bash’s inbuilt commands, try looking in the bash manual for its many usage options.
Using set with the -x option will make bash print out each command it is going to run before it runs it.
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:
The output printed before the command runs (for example):
+ ls -F --color=auto
Which means that the command is really an alias to run ls with the -F and –color=auto options. Use a “\” (backslash) before the command to run it without the alias.
The backslash escape character can be used before a shell command to override any aliases.
For example if rm was made into an alias for rm -i then typing “rm” would actually run rm -i.
However, typing \rm lets the shell ignore the alias and just run rm (its runs exactly what you type), this way it won’t confirm if you want to delete things.
|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.
The “\” character can also be used to stop bash from expanding certain symbols (as an alternative you could use single quotation marks, although you may need to use both).
|The TAB Key|
|Please note that using the TAB key (automatic-command-completion) will automatically use escapes for spaces (so you don’t have to type them manually).|
The “script” command creates a typescript, or “capture log” of a shell session – it writes a copy of your session to a file, including commands you type and their output.
~ (tilde character)
The tilde character is used as an alias to a users home directory.
For example, if your user-name was “fred”, instead of typing cd /home/fred you could simply type cd ~. Or to get to fred’s tmp directory (under his home directory) you could type cd ~/tmp.
|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…).
The reset command re-initializes your current terminal. This can be useful when the text from your terminal becomes garbled, simply type “reset” and this will fix your terminal.
Closes your current terminal (with x-terminals) or logs-out. Also try CTRL–D .
Logs out of a terminal, also try CTRL–D .
A little command that repeats anything you type.
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).
Also try using the -e option with echo. This will allow you to use the escape character sequences to format the output of a line. Such as ‘\t’ for tab, ‘\n’ for newline etc.
|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.
Chris Karakas – Conversion from LyX to DocBook SGML, Index generation
|Revision 1.2||15th April 2006||Revised by: GA|
|Corrected typing errors, generated new, much smaller index (more accurate in my opinion). Updated errors in document for TLDP.|
|Revision 1.1||28th February 2006||Revised by: CK|
|Corrected typos, generated new index (9000 index entries!).|
|Revision 1.0||6th February 2006||Revised by: GA|
|Major restructuring, now in a docbook book format. Removed large chunks of content and revised other parts (removed chapters and sectioned some areas more). This is likely the final release by the author, I hope that someone finds this guide useful as I do not intend to continue work on this guide.|
|Revision 0.7.1||25th February 2005||Revised by: CK|
|Set special characters in math mode, produced PDF and PS with Computer Modern fonts in OT1 encoding and created correct SGML for key combinations.|
|Revision 0.7||5th December 2004||Revised by: GA|
|Updated document with new grammatical review. Re-ordered the entire Text section. Removed a fair amount of content.|
|Revision v0.6||20th April 2004||Revised by: GA|
|Attempted to fix document according to TLDP criticisms. Added notes and tips more sectioning. Now complying to the open group standards for the UNIX
system trademark. Document should be ready for TLDP site.
|Revision v0.5||6th October 2003||Revised by: GA|
|Fixed a variety of errors as according to the review and made some consistency improvements to the document.|
|Revision v0.4||15th July 2003||Revised by: GA|
|Made small improvements to the document as suggested (so far) by the thorough TLDP review, improved consistency of document and made small content additions.|
|Revision v0.3||26th June 2003||Revised by: GA|
|Minor errors fixed, updated the appendix with information for finding where a tool is from. Fixed referencing/citation problems and improved further reading and intro sections, added an audio section.|
|Revision v0.2||20th April 2003||Revised by: GA|
|This is the initial public release. Added more code-style then before, broke text-section into more subsections. Improved consistency of document and fixed various index entries.|
|Revision v0.1||27th March 2003||Revised by: GA|
|This is the initial draft release (the first release to be converted from LyX to DocBook SGML).|
- Table of Contents
- 1. Introduction
- 2. Legal
- 3. The Unix Tools Philosophy
- 4. Shell Tips
- 5. Help
- 6. Directing Input/Output
- 7. Working with the file-system
- 8. Finding information about the system
- 9. Controlling the system
- 10. Managing users
- 10.1. Users/Groups
- 11. Text Related Tools
- 12. Mathematical tools
- 13. Network Commands
- 14. Security
- 15. Archiving Files
- 16. Graphics tools (command line based)
- 17. Working with MS-DOS files
- 18. Scheduling Commands to run in the background
- 19. Miscellaneous
- 20. Mini-Guides
- A. Appendix