---- Perl One-Liners ----

OS Issues

  1. Basic command line usage
    Perl one-liners are run from the command line, which is controlled through the keyboard. Each operating system has its own application to invoke the command line. There are also differences in the functionality offered by the shell, which is the mediator between command line application and the core of the operating system. The Perl one-liners listed below are intended for a command-line interface to a UNIX-like OS. They function the same on each platform but some particularities about working on the command line need to be explained first.
  2. Getting started on Mac
    The default application for the command line on a Mac is called 'Terminal'. It can be opened by typing the name into Spotfinder or by double-clicking on its symbol in the Applications / Utilities folder. A new window appears showing a text line at the top with the cursor positioned after the prompt, which consists of the computer name, the current directory, the user name and the dollar sign:
  3. Getting started on Windows
    After installing Cygwin, the command line interface (also called Bash Shell) can be started by clicking on the according program symbol either on the desktop or under programs. A new window opens showing the login and computer name, followed by the current working directory and a prompt in shape of the dollar symbol, followed by a blinking cursor:
  4. Getting started on Linux
    For Linux there are as many command line applications as there are window managers. In Ubuntu, which uses Gnome as its window manager, a 'Terminal' application is available from the Launcher bar, which opens a command line window when clicked. It shows the prompt, consisting of the login and computer name, the current directory name and the dollar sign, followed by the cursor. Other distributions provide similar mechanisms.
  5. The prompt
    The command line is a place to type instructions for the computer. The start of the line can include a variation of items, such as computer name, login name, current working directory and other user-configurable pieces of information. This is normally followed by a dollar sign or greater-than symbol. After that comes a blinking or highlighted cursor indicating where text will appear. Commands are processed by pressing the 'enter' or 'return' key .
  6. File system organisation
    The storage space for user accounts is organised through directories anchored to the home directory like roots to a tree. A directory listing from within the home directory normally shows folders like 'Desktop', 'Documents' and 'Downloads'. On UNIX-based systems this is achieved through typing 'ls -l' followed by hitting return. The output lists files and folders, the latter being indicated by a leading 'd' .
  7. Changing directory
    Check which directory the cursor is currently located in by typing 'pwd', which stands for 'print working directory'. From the home directory change to the Desktop by typing 'cd Desktop'. From there move to the downloads directory: 'cd ../Downloads' .
  8. Paths
    When working with files, these can be specified through relative or absolute path names. If the current working directory is the Desktop folder, then a file input.txt in the Downloads directory can be specified through '../Downloads/input.txt' (relative path) or '~/Downloads/input.txt' (absolute path) .
  9. Command line history
    Commands that were typed on the command line are stored in a history file and can be revoked by stepping back using the up-arrow key. The history can also be searched by typing Ctrl-R (control key together with the 'R' key) .