WalaWiki content from p1k3.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

100 lines
3.8 KiB

  1. WareLogging. SourceCode. BASH is the BourneAgainShell. In terms of scripting, I tend to think it's considerably more sane to write Perl these days, but I promise you Bash is not going away any time soon.
  2. = keys & builtins =
  3. * Press ctrl-r for an interactive search of your command history. This is usually faster than arrow keys, and probably safer than guessing at a bang completion.
  4. * esc, . (escape, followed by a period) will pull up the last word of the last command
  5. * "cd -" - bounce back to the last directory.
  6. * Redirect STDERR: "command 2> file"
  7. = references & tutorials =
  8. * [http://www.ibm.com/developerworks/library/l-bash.html Bash by example, Part 1]
  9. * [http://www.cs.uu.nl/wais/html/na-dir/unix-faq/shell/csh-whynot.html csh programming considered harmful]
  10. * [http://www.shelldorado.com/ Heiner's SHELLdorado]
  11. * [http://talug.org/events/20030709/cmdline_history.html Using Bash's History Effectively] - A few cool tricks here I wasn't aware of.
  12. ** export HISTIGNORE="&:ls:[bf]g:exit"
  13. ** 'shopt -s cmdhist' - record multiline commands as a single line in history
  14. ** history | grep -i "<search string>"
  15. ** !<history number>
  16. = aliases =
  17. To investigate: BashFunctions.
  18. From several versions of ~/.bashrc:
  19. # stack-based directory navigation:
  20. # c to change, b for back, u for up.
  21. alias b='popd'
  22. alias u='pushd ..'
  23. alias c='pushd'
  24. # frequent commands:
  25. alias m='mutt'
  26. # p used to be pine, but I quit using pine.
  27. alias p='ssh p1k3.com'
  28. alias v='vim'
  29. # these might break using GNU date(1), I should really check.
  30. alias t='cd /www/p1k3/archives/`date +%Y`/`date +%m`'
  31. alias tv='vim /www/p1k3/archives/`date +%Y`/`date +%m`/`date +%d`'
  32. # colorized & shortened ls
  33. alias ls='ls --color=auto '
  34. alias ll='ls -lh'
  35. alias la='ls -A'
  36. alias l='ls -CF'
  37. # for those MS-DOS kinda days
  38. alias dir='ls --color=auto --format=vertical'
  39. alias vdir='ls --color=auto --format=long'
  40. # command prompt
  41. # user@host:working_directory$
  42. PS1='\u@\h:\w\$ '
  43. = .inputrc =
  44. This stuff is crucial: Kill the obnoxious beep, and cycle through possible completions rather than requiring 2 presses of the tab key to display a list of choices.
  45. set bell-style none
  46. set completion-ignore-case on
  47. set completion-query-items 150
  48. set mark-directories on
  49. set visible-stats on
  50. TAB: menu-complete
  51. = Constantly refreshing display of command output =
  52. I often want to monitor a file or service in real-time. This lets me do it:
  53. while [ 1 ]; do { clear; tail -20 /var/log/messages; sleep 1; } done
  54. This will display the last 20 lines of /var/log/messages on a blank screen, refreshing every second. Replace "tail -20 /var/log/messages" with the command that you want to refresh.
  55. <[[Brennen]]> As another approach, [http://www.gnu.org/software/coreutils/manual/html_chapter/coreutils_5.html#SEC19 tail(1)] itself offers the -f / --follow option, so for example,
  56. tail -f /var/log/httpd/access.log
  57. At least some versions of tail support following multiple files at once. These may be GNU specific options; I'll look it up at some point.
  58. There's also watch(1), which is essentially the above loop for whatever command you feed it.
  59. <[[Brent]]> Very cool! I created the above trick because I've been on systems on which watch wasn't available, and I wanted to watch a process (say, "ps -ef | grep sql") instead of a file.
  60. It's also nice to have it clear the screen each time.
  61. = In-place Files =
  62. In attempting to automated FTP uploads, [[Brent]] has had trouble passing data to the ftp command. An easy solution:
  63. ftp -n -i (HOST) <<- endcommands
  64. USER (USERNAME) (PASSWORD)
  65. cd wwwroot
  66. mput *
  67. bye
  68. endcommands
  69. The -n parameter suppresses auto-login, and -i turns off prompting.