13.07.2015 Views

Linux System Administration Recipes A Problem-Solution Approach

Linux System Administration Recipes A Problem-Solution Approach

Linux System Administration Recipes A Problem-Solution Approach

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

CHAPTER 8 ■ USING THE COMMAND LINE BETTER> mv file.txt file.txt Alt-BS> mv file.txt file.> mv file.txt file.tex• Ctrl-_ and Ctrl-X Ctrl-U: These undo the last change. You can undo all changesmade to the line simultaneously with Alt-R.• Ctrl-D: This exits the shell, if at the start of an empty line. This is handled by stty,not by readline, so it should work in any shell. If used in the middle of a line, itdeletes the character to the right of the cursor. Using Alt-D or Esc-D will delete aword to the right.• Ctrl-C: This cancels whatever you’re running currently. Like Ctrl-D, this is a sttysetting and should work with any shell.• Ctrl-L: This clears the screen. This is useful when you don’t want it to be obviouswhat you’ve been doing! However, be warned that if you’re using a terminal thatscrolls, your history will be available via scrolling back. This is also useful ifsomething peculiar has happened to the lines and they’re not displaying properly.You can also try typing stty sane in this instance.■ Note See recipe 1-2 for discussion of setting up your .bashrc file to improve the way your history is stored.8-2. Writing Your Own bash FunctionsMost sysadmins will already have some aliases set up in their ~/.bashrc file for easy reference tocommands they use frequently (and some distributions, including Debian and Ubuntu, include somedefault settings in /etc/bashrc). Here’s an example from mine:alias e='ssh juliet@myemailserver.example.com'Aliases are limited, though, since in bash and related shells you can’t pass arguments in from thecommand line to an alias. There’s a “cheat” option, if the argument you want to pass in is always on theend of the line:alias gps='ps -A | grep'This alias will mean that if you type gps apache, the process list will be searched for the patternapache, so this saves you a little typing. However, this won’t work if the argument you want to pass in isin the middle of the line.The way to do this is by creating a function: functions will take arguments anywhere inside them.For example, say you want to be able to run LDAP searches more readily:function lds() { ldapsearch "($1=$2)"; }174Download at WoweBook.Com

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!