Command-line Work on Linux Server
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:
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.
- Click on the white window icon, or use your computer menu of programs to select the Secure Shell Client.
- You may either select the libcontent1 profile, if already programmed in, or click "Quick Connect" and enter in "libcontent1.lib.ua.edu" and the user name.
- Enter your password, and click "ok".
- 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.
- You can resize the windows by dragging their corners, and you can relocate the windows by clicking/dragging the top bar.
- 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.
- 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.
- 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.
- 'ls' means "list." This is the command you type in to list the contents of the current directory.
- '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.
- To also see system hidden files, use 'ls -la' (a is for 'all').
- 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.
- 'cd' means "change directory." This is the command you type in to change directories on the server.
- 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.
- 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.
- To move up into the parent directory, type 'cd ..' -- that will take you up one level. 'cd ../..' takes you up 2 levels.
- 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'.
- 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.
- Viewing file content:
- To view a file's contents on commandline, type in 'cat filename' where filename is the name of the file you want to view. If that file is in the sister directory to the directory you are in -- assume it is in the output directory and you are in the scripts directory -- type in 'cat ../output/filename'.
- 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. If that file is in the sister directory to the directory you are in -- assuming it is in the output directory and you're in the scripts directory, type in 'vi ../output/filename'. See the VI section next.
For further information: BASH Reference Manual
VI: to view files from the command line on the server
- 'view filename' will open the file in view mode. While it is possible to edit a file in view mode, saving those changes will require the addition of an exclamation point to the save command.
- Control-f will move the view forward a page at a time
- Control-b will move the view backward a page at a time
- arrow keys will scroll
- 'G' means "Go", I think. If you follow it with a space and number, it will take you to the line in the file corresponding to that number. By itself, it takes you to the end of the file. (thanks, Nitin!)
- ':q' (meaning "quit") closes the file. If you have inadvertantly made edits that you don't want to save, ':q!' will get you out of the file without saving changes. Alternatively, if you want to save your edits, type in ':wq' for "write quit".
- Some characters change the mode to where whatever you enter will be typed in, so if you don't want to edit the file, try not to hit any other keys. If by accident you do get into insertion mode, use Control-Esc to get out of it. And be sure to use ':q!' to get out of the file without saving your changes.
For further information: VI Editor commands