Personal tools
You are here: Home Members jgsack's Home CLT CLTips_MemoryAids
Views

Command Line Tips subpage
suggestions for remembering all this

know the territory

An important aid to coping with unfamiliar territory is to become familiar with the territory!

where are things

  • most programs are in /bin or /usr/bin
  • for other locations look at the output of echo $PATH .. this is where the system searches for programs when you type a program name.
  • programs can be in other places too, but you may have to type their path explicitly, as something like:
         /tmp/DemoProg       .. execute a program DemoProg located in the /tmp directory
         ~/Desktop/TryMeToo  .. execute a program dowenloaded to the desktop
    

Warning: Be aware that whenever you run a program residing somewhere other than one of the standard places, you really should know what the program is, where it came from, and why you are running it. Malware is rare on Linux and Unix-bases systems in general, but not impossible or unknown. if it's not part of tghe standard system, how did it get there?

  • other locations of you should eventually learn about
    • filesystem hierarchy standard: see http://www.pathname.com/fhs/
    • /etc .. system configuration files. Note the tradition of using text files makes it possible to easily search for things.
  • /usr/share, /usr/doc, /usr/share/doc, ... good exploring here

learn more about man, info, and general techniques for finding answers for yourself

  • man -k XXX (also known as apropos)
  • man -a XXX, man N XXX
  • info sometimes gives much more content than man .. try it (remember -l means "last")
  • google .. choose your keywords to get fewer matches. consider define: linux:, site: options
  • wikipedia is often great for browsing toward an answer (or off on a tangent, too)

How oes this help? Well, sometimes just looking around at the thousands of programs in these diredtories on any Linux distribution can be helpful in remembering the name of some program you're trying to remember. sometimes just glancing at these directories may trigger mental associations or stimulate new ideas.

use tab-completion

  • tells whether there even is a program starting with that
  • helps avoid mispellings .. use it recursively to complete the spelling or report possible matches, allowing you to add another character or two and retry the completion
  • note that tab -completion works for filename arguments to commands, too. After typing the command (and options, if any), start typing the file (using a path prefis, as needed), and use the same trial-and-error tab-completion as above. The tab-completion facility will happily complete or offer ditrectory names as well as files.

aliases and functions

An earlier discussion revealed a hint about the alias capability of shells. Use help alias or man alias to read more about aliases. Or better yet, google for shell alias, and do some looking around for yourself. Aliases are one of the simplest customizations that allow you to avoid having to remember program names, favorite options, or messy argument syntax.

For example, I often like to see the most recent files changed, so I use an alias:

    alias lt='ls -lart' .. my mnemonic is "list by time"

Note that aliases still append all the rest of your command line input at the end of the expanded alias. Thus, lt ~/notes shows the last files changed in the ~/notes directory at the bottom of the output .. making it unimportant if lots of lines have scrolled off the screen.

Aliases can be useful as throwaway tools. If I find myself typing the same command a lot, I might just make an alias to be used today, and forgotten tomorrow.

Perhaps the confusing part is how to make the aliases permanent. The answer falls within the topic of shell startup behavior. There is more than one way to do it, and any reference to shell startup files will suggest at least 3 places.

For reasons that made sense sometime in the past, I have placed my alias (above) and other bash login initializations in /etc/profile.d/jgs-alias.sh. Technically what's going on here is that for anyone using the bash shell on my system, this and other scripts in this directory ending with extension .sh get processed upon login. Others may prefer to use ~/.bash_profile as a per-user initialization.

Just to give some more examples, Here's my modest magic file:

  #jgs-alias.sh -- global aliases set by /etc/profile

  alias lt='ls -lart'
  alias lwp-HEAD='lwp-request -m HEAD'
  function lt30(){ ls -lart $* | tail -30; }
  function lt22(){ ls -lart $* | tail -22; }

  hgrep() { history | grep $*; }
  hgrep22() { history | grep $* | tail -22; }

  function filewhich(){ file `which $*`; }
  function rpmwhich(){ rpm -qf `which $*`; }
  function lesswhich(){ less `which $*`; }
  function lddwhich(){ ldd `which $*`; }
  function lol(){ [ -f $1 ] && less -XE $1 || ls -l $1; }

  alias rpmgrep='rpm -qa | grep'
  alias e1='/sbin/ifconfig eth1;/sbin/iwconfig eth1'

  export IGNOREEOF=3

  #===eof===

Remember that such things can grow and evolve, and are completely under your control. One non-obvious tip is that changes do not normally show up until the next time you login. But you can force immediate re-reading of one of these source files with the shell source command. For me it would be:

  source /etc/profile.d/jgs-alias.sh   .. update aliases (and functions, ..) for current shell

For the record, the source command can be abbreviated as . (a period). This is all too easy to overlook, so I usually prefer to spell it out.

Note that there are some (simple) examples of functions above, but we haven't discussed them. Aliases typically perform simpler operations than functions. Functions allow more freedom and allow arguments to be rearranged. If it seems like something is impossible to make a shell alias for, it's possible you can find a way with a shell function. help function gives a capsule summary, and man bash has a section on FUNCTIONS.

Remember that aliases and functions are a shell feature, and different shells may differ in behavior. If I remember correctly, zsh, the Z shell allows argument handling, whereas bash doesn't.

When you progress to using anything beyond the simplest functions, you are entering into the realm of shell scripting, which (here) might be considered an advanced topic.

long-term-memory

This is my pet name for a sheme I use of maintaining a running logfile for jotting down any and everything I think I might want to refer back to. Not much more than a diary, I guess. Others might like to use fancy programs specifically designed for this purpose, but I kind of like free form reverse-chronological text files. I create a new one each year, and name them something like ltm_2007.txt. These files live in a standard (for me) location, and I even have a symlink in my home dir, LTM -> notes/ltm_2007.txt (which I change every New Years Day). I further have a custom launcher on my panel so that I can open an editor on my LTM file, make a quiick entry, and save it without too much distraction from whatever I am doing.

Another mechanism I find useful is to make my own cheat-sheet for specific programs OR operations that have too many options. Again, I put such things in the same common notes directory, so I can easily find it even long afterwards. I commonly organize such a file with my favorite options and sample command lines at the top, and then maybe reminders about less frequent but still useful examples.

I haven't found it necessary, but it might be worth adding a bookmark in your gnome Places menu to allow quick opening of a nautilus browser in that directory, so you can look for these various memory aids. KDE must have similar?



Powered by Plone CMS, the Open Source Content Management System

This site conforms to the following standards: