Useful Linux Commands

From ULYSSIS documentation
Revision as of 01:55, 26 October 2019 by Bert (talk | contribs) (→‎Text editors)

Once you've connected, you can use these commands to use the ULYSSIS shell.

First of all, whenever you need to type a longer command or filename, try the TAB key as it will try to complete the name of the command or file you are typing. Pressing TAB twice will show a list of possible completions.

A more extensive document on this can be found at http://info.ee.surrey.ac.uk/Teaching/Unix/.

Basic file managment

cd directoryname

Change directory. Works the same as under MS-DOS. cd without argument changes to your home directory (like My Documents in windows). Go to the parent directory with cd ..

ls

List the contents of the current directory. Many different formats are available, a common one is ls -al. To accomodate MS-DOS/Windows users, dir is an alias (synonym) for ls -alF, which gives output similar to the dir command in MS-DOS/Windows.

cp inputfile targetfile

Copy inputfile to targetfile. Additional arguments (e.g. -r or -v are explained in the man-page.)

mv inputfile targetfile

Move inputfile to targetfile. Additional arguments (e.g. -i or -v are explained in the man-page.) This is the way to rename a file. Note that you cannot use a construction like mv *.htm *.html to add an ``l to a bunch of files. A small shell script can provide a way to do this: for i in *.htm; do mv i; done

rm filename

Remove filename. Additional arguments (e.g. -r or -v are explained in the man-page.) Note: there is no undelete-alike function in most unices.

mkdir dirname

Creates a directory called dirname.

rmdir dirname

Removes an empty directory. Use rm -r to delete a directory and recursively everything in it. Add -f to disable any prompts (dangerous!).

Getting help

man command-name

Displays manual pages, if available. E.g. man ls. Use 'q' to exit. Relatives: apropos, help.

apropos word

Searches through headers of all man pages.

help command-name

Displays help about command-name. Only for internal bash-functions.

bash

The Bourne Again SHell. Widely used successor of sh, the Bourne shell. This is the program you're working under after you open a ssh-session (you don't have to start it to use it). Bash interprets your commands, and executes them. Tab-completion, * and ? expansions, etc are all bash functions. man bash will give you tons of info about it. Alternatives : tcsh, zsh, rc

Text editors

It's easier to use a text editor on a server, than editing your file locally and uploading that file.

nano

Probably the easiest text editor. Should be self-explanatory.

joe

Another easy text editor. Press Ctrl+C to quit.

vim

Probably the best text editor. Start editing by pressing i. Stop editing by pressing the escape key. Save and quit with :wq. Quit without saving with :q!.

Utilities

df

Displays info about the free diskspace on the system. df . will give info about the filesystem where the current directory resides. The output becomes a bit more readable with the -h switch.

du

Displays info about the diskusage in the current directory (and its subdirectories. A common parameter is -s , equivalent to -summarize , to summarize the disk-usage (without the per-subdir totals).

quota

Displays info about your diskusage, and your disk quota. Quota are limits on diskusage, imposed by the system administrator. The system will warn you if you exceed these limits.

ps

Displays info about processes. Various options possible, for example ps auxf gives info on all processes, including process owner, memory usage, and parent-child indication.

htop

Displays top CPU processes. Use it to see what gets most cpu power at the moment. Don't leave top open for a long time, since it eats cpu time itself. (quit with 'q').