Command-line Work on Linux Server

From UA Libraries Digital Services Planning and Documentation
Revision as of 10:05, 20 May 2010 by Jlderidder (Talk | contribs)

Jump to: navigation, search

The storage/delivery server operating system is SUSE Linux, and the default shell (command line interpreter) via ssh (Secure Shell access) is BASH.

The following are a few commands to help the beginner locate files and open, view, and close them on the server, as well as to run command-line scripts. More information is available at the links provided:

  1. SSH User Manual
  2. BASH Reference Manual
  3. VI Editor commands

SSH: to get to the server

SSH offers 2 interfaces: a command-line interface (the white window icon) and a graphical user interface (GUI: the yellow folder icon). While you may use the GUI for browsing to locate content, you will need the command-line interface for running scripts. So the following instructions are for this latter interface.

  1. Click on the white window icon, or use your computer menu of programs to select the Secure Shell Client.
  2. You may either select the libcontent1 profile, if already programmed in, or click "Quick Connect" and enter in "" and the user name.
  3. Enter your password, and click "ok".
  4. You are now at the command line on the server, and within the BASH shell. If at this point, you click on the yellow folder icon at the top, it will open up the graphical user view of your home directory, which may help. Also, clicking on the white window icon at the top will open another command-line interface of your home directory. You may open as many of these as is helpful, so as to work in multiple directories at the same time. This can be useful if you want to run scripts from one directory, view the output in a second directory, and examine the files to be processed in a third directory.
  5. You can resize the windows by dragging their corners, and you can relocate the windows by clicking/dragging the top bar.
  6. to change settings, such as font size, color, type, and background colors, click "edit", click "settings", and select Global Settings/Appearance/Font or Colors. Make your selections and click "OK". It helps if you select text colors and cursor color that will stand out against the background selected.
  7. To exit the server, type "exit" on command line of each window open, or simply close all SSH windows. Before you exit, be sure to close any files you have opened, or the server will retain the "opened" file for recovery until you return.
  8. Never leave your desktop unattended while you have an SSH window open on the server; this is a serious security risk. If you must leave your desktop while SSH is open, lock the access to your desktop first.

For further information: SSH User Manual

BASH: to get around on the server, and run scripts

To find out more about any of these commands, go to Google and type in "manpage" and then the command. Or, on the commandline, type in "man", space, and the basic command without the parameters which follow it. This will open the text version of the manpage stored on the server, and it will open it in VI (next section discussed). For example, "man ls" will give you an option of two versions of the 'ls' command. Enter "1" and a text file will open in the window. Use "control-F" to move forward in the file and "control-B" to move backwards in the file. Alternatively, you can use the arrow keys to scroll up and down. To close the file, type colon q (':q').

All commands should be followed by hitting the "enter" key.

  1. 'ls' means "list." This is the command you type in to list the contents of the current directory.
    1. 'ls -l' (that is el ess space hyphen el) will provide a complete (el is for 'long') listing of all non-system files in a long format, so you can see who the files and directories belong to, permissions issues, size of files, and date created.
    2. To also see system hidden files, use 'ls -la' (a is for 'all').
    3. To list the contents of a directory, add the name of the subdirectory: 'ls UploadArea' will list the contents of the UploadArea subdirectory. 'ls UploadArea/MODS" will list the contents of the MODS directory within the UploadArea directory. In the Linux operating system (as opposed to a Windows operating system) the marker between directory and subdirectory is a forward slash ("/") instead of a backward slash.
  2. 'cd' means "change directory." This is the command you type in to change directories on the server.
    1. If you type in 'cd' with no parameters (nothing following the command), you will be returned to your home directory, where you entered the system.
    2. If you type in 'cd UploadArea' you will change directories to the UploadArea subdirectory. If then you type in 'ls' you will see the contents of that directory.
    3. To move up into the parent directory, type 'cd ..' -- that will take you up one level. 'cd ../..' takes you up 2 levels.
    4. To change to a sister directory that's in the same directory you're in, type 'cd ../sister' where 'sister' is the name of the adjacent directory. Example: 'cd UploadArea/scripts' takes you into the scripts subdirectory of the UploadArea. If then you want to go to the "output" subdirectory of the UploadArea, then type in 'cd ../output'.
    5. To run a script, it is best to change into the directory where that script is located, as often it expects to find the output directory in a relative location to the script. Once you are in the scripts directory, type in the script name and hit enter. If this fails, that means your classpath is not properly set; so report that, but type in './scriptname' instead; that is, preface the script name with './' (period forward slash) to indicate to the BASH shell that you want to run the script located in the directory where you are.
    6. To view a file, type in 'view filename' where "filename" is the name of the file you want to view. If you are wanting to edit the file at the command line, type in 'vi filename' instead. See the VI section next.

For further information: BASH Reference Manual

VI: to view files from the command line on the server

Personal tools