General Linux tips

Some general linux tips that are not obvious, known, and/or well documented, but still very useful.

Web

To search the web for Linux stuff, use google's Linux search engine.

(Bourne-again) Shell - Bash

  • To exit a shell (close it), or log out of a login shell without having to type "exit" each time, simply press <ctrl>+d.
  • To get reverse pattern search in your last used commands, press <ctrl>+r and then type in what you are looking for. This function is "search as you type". To cycle through the found commands, press <ctrl>+r. Return will execute the shown command, while escape will exit the search, copying the currently shown command to the command line. <ctrl>+c will just cancel it and give you an empty command line.
  • Instead of typing "clear" to clear the display of a shell, simply press <ctrl>+l (*l* as in lemon).
  • If you've typed (part of) a command and want to clear the line to type something else, press <ctrl>+c.
  • determine file owner (file ownership):
    ls -l filename | awk '{print $3; }'
  • likewise: determine group of a file (group ownership):
    ls -l filename | awk '{print $4; }'

Nebenbei bemerkt: Die Taste <ctrl> (control) entspricht der Taste <Strg> (Steuerung) auf der deutschen Tastatur. Diese heißt NICHT String! ;-)

Software

  • to run a program regularly with a certain interval, use watch:

    watch command

    will simply run "command" at default intervals of 2 seconds.

    watch cat /proc/acpi/thermal_zone/THRM/temperature

    will simply display the file /proc/acpi/thermal_zone/THRM/temperature every 2s, which should make for a simple cpu temperature display on acpi-enabled 2.6 kernel machines.
  • Hate the vi editor? Try jedit - a powerful sourcecode editor that is free, open source, and written in java (so it will run on your system after an easy installation). It makes UltraEdit, TextPad and the like look bad functionality-wise. It also supports working with files via ftp and sftp (ssh) using easily installable plugins.
  • Tired of the slow file finding utility "find" under Linux? Try "gnu locate" instead, it uses a regularly rebuilt database of your filesystem to find files and folders very fast.
    Remarks: "time" is used to measure how long the command runs. The output was piped to wc -l, which counts the lines of the output, i.e. how many times the pattern was found. The filesystem this was tested on is an almost full 40GB drive with ~260k files.

    A search for something that doesn't exist is very quick:
    time locate laberrabarber | wc -l
          0
    
    real    0m0.271s
    user    0m0.260s
    sys     0m0.000s
    (Doing this with "find" instead of "locate" takes about 7 minutes on my machine)

    A query that returns a lot more results (in this case 20833) doesn't take all that much longer:
    time locate test | wc -l
      20833
    
    real    0m0.285s
    user    0m0.280s
    sys     0m0.000s
    Locate can also search for patterns, of course. To look for something containing "test" somewhere below any directory called "include", try:

    locate */include/*test*

Links