Basic Commands Description ================================================================================ bash -x <script> execute script and display also command-lines (for debugging) if left out <script>, all login-scripts are displayed. cat <filename> displays contens of <filename> pwd displays current path export displays all environment variables in alphabetical order env displays all enviroment variables; (can be compared with VMS logicals) dos2unix to remove the LF/CR (^M) alias displays all aliases (can be compared with VMS symbols) alias <name> display alias <name> echo $<name> display environment variable <name> fg put program back to forground control-z puts program in background dir > dir.txt 2>&1 redirect stdout and stderror to same file ar t library.a show contents of library.a nm object.o show contents of object.o fgrep <string> <filename> find a <string> in <filename> rm <filename> deletes a file rm -i * deletes files after prompt rm -Rf <directory> deletes a directory-tree chown <user>:<group> <filename> changes ownership of file chown -R <user>:<group> <directory> changes ownership of directory tree chmod chmod +x <file spec> add execute permission to file; required for execution of a script; chmod +w <file spec> add write permission to file; chmod -w <file spec> remove write permission to file; chmod ugo <file spec> changes protection u(ser)=# g(roup)=# o(wner)=# 0 none 1 execute 2 write 3 execute write 4 read 5 execute read 6 read write 7 read write execute chmod -R 755 <directory> changes protection of all files in specified directory tree find -name <file> | xargs grep <string> find -name <file> find a filename in current directory tree tar -czf <file>.tar.gz <directory1> [<directory2>] ... create gzipped tar file tar -xzf <file>.tar.gz extract gzipped tar file tar -tzvf <file> display contents gzipped tar file
Advanced Commands Description =================================================================== cat /proc/meminfo displays memory usage cat /etc/passwd displays contents password file cat /etc/fstab displays mountable disks cat /etc/mtab displays mounted disks ipcs displays info about process communications shared memory / semaphores / message queus ipcrm remove process comm. facility
Backup Scheme Before a backup-procedure is implemented, first must be decided what the scheme of the backup will be. A scheme can vary, depending on how frequently data on disks will change. Depending on this scheme, environment, availability of hardware and knowledge of the operating-system, the operating system-manager can choose from e.g. the following procedure-principles to get data on and from a remote system: 1a) Backup with tar,gunzip and transfer backup over FTP to a remote system. 1b) Transfer backup over FTP from remote system and restore with tar,gunzip. 2a) Backup with tar,gunzip directly to remote system over NFS. 2b) Restore with tar,gunzip directly from remote system over NFS. 3a) Backup with dump directly to remote system over NFS 3b) Restore with restore directly from remote system over NFS For each of these backup-principles listed above a backup-procedure is obtained in the "Linux"-tools, which can be shown by the command: tools See the commands: 1) tar_gz_ftp --help 2) tar_gz_nfs --help 3) dump_nfs --help
Gnome Commands Description ====================================================================== gnome-about Display Gnome information gnome-calculator Calculator gnome-character-map Display character set gnome-control-center Control-Panel gnome-dictionary Dictionary gnome-help Help gnome-mouse-properties Set mouse properties gnome-network-preferences Network proxies gnome-panel Display Linux taskbar on the screen gnome-panel-screenshot Grab screen gnome-print-manager Print manager gnome-session Desktop gnome-system-monitor System monitor gnome-terminal Gnome-Terminal
OpenVMS DCL Commands Linux Commands ================================================================================ BACKUP tar CC gcc COPY cp COPY rcp CREATE/DIRECTORY mkdir DELETE rm DELETE <directory>.DIR rmdir <directory> DELETE/ENTRY lprm DELETE/SYMBOL unalias DIFFERENCES diff DIRECTORY ls DIRECTORY [...] ls -R DIRECTORY [...]<filename> find -name <filename> DIRECTORY *.dir ls -d DIRECTORY /FULL ls -l EDIT vi EDIT/READ_ONLY less EXIT return HELP <topic> man <topic> HELP HINTS <topic> man -k <topic> INQUIRE <choice> read <choice> INITIALIZE <device> fddisk -fmt <device> LIBRARY/LIST <library> ar -t <library> LOGOUT exit PRINT lpr READ read RECALL/ALL history RENAME mv SEARCH grep SET DEFAULT cd SET FILE/ENTER=<link> <file> ln -s <file> <link> SET VERIFY set -v SHOW DEFAULT pwd SHOW DEVICE D df SHOW LOGICAL printenv SHOW MEM free SHOW QUEUE lpq SHOW SYSTEM ps -ef SHOW SYMBOL/ALL alias SHOW TIME date SHOW USERS users SHOW USERS/FULL who -H STOP/ID <process-id> kill -<process-id> TYPE <filename> cat <filename> TYPE/PAGE <filename> more <filename> TYPE/PAGE NL: clear WAIT sleep WRITE SYS$OUTPUT "<text>" echo "<text>" OpenVMS Command-files Linux BASH Scripts Explanation ================================================================================ I1 .gt. I2 I1 -gt I2 Greater than I1 .lt. I2 I1 -lt I2 Less than I1 .ge. I2 I1 -ge I2 Greater or equal I1 .le. I2 I1 -le I2 Less or equal I1 .eq. I2 I1 -eq I2 Equal I1 .ne. I2 I1 -ne I2 Not equal S .eqs. "" -z S Empty string S1 .eqs. S2 S1 = S2 Strings equal S1 .nes. S2 S1 != S2 String not equal E1 .and. E2 E1 -a E2 AND E1 .or. E2 E1 -o E2 OR .not. E ! E NOT OpenVMS File Test Linux File Test Explanation ================================================================================ f$search("file") .nes. "" -f filename Exists, Regular .not. f$file_attributes("file","EOF") -s filename NOT Empty n/a -r filename Readable n/a -w filename Writable n/a -x filename Executable f$file_attributes("file","DIRECTORY") -d filename Directory
Linux Command Explanation ============================================================== ethtool Display or change ethernet card settings free Display system memory utilization hdparm get/set hard disk parameters top Overall system monitoring gnome-system-monitor Graphical overall system monitoring vmstat Resource monitor iostat Display overview of CPU utilization mpstat CPU statistics sar Produce report ???
When logged in to an account, Linux generates a user shell. Within this shell, commands can be issued and variables can be declared. Shell scripts can also be created and executed. When a shell scripts is executed, however, the system generates a subshell. There are then two shells, the one logged in and the one generated for the script. Within the script shell, another shell scripts could be executed which would have its own shell. When a script has finished execution, its shell terminates and the "command-line" is returned to the shell from which it was executed. In this sense, many shells could be created, each nested within the other. Variables defined within a shell are local to it. If a variable defined in a shell script, then, when the script is run, the variable is defined with that script's shell and is local to it. No other shell can reference that variable. In a sense, the variable is hidden within its shell. Environment variables can be defined in all types of shells including the BASH- shell, the Z-shell and the TCSH-shell. The strategy used to implement envionment variables in the BASH shell, however, is different from that of the TCSH-shell In the BASH shell, envionment variables are exported. That is to say, a copy of an environment variable is made in each subshell. For example, if the EDITOR variable is exported, a copy is automatically defined in each subshell. In the TCSH shell, on the other hand, an environment variable is defined only once and can be directly referenced by any subshell. In the BASH-shell, an environment variable can be thought of as a regular variable with added capabilities. To make an environment variable, you apply the export command to a variable you have already defined. The export command instructs the system to define a copy of that variable for each new shell generated. Each new shell will have its own copy of the environment variable. This process is called exporting variables. Thinking of exported environment variables as global variables is a mistake. A new shell can never reference a variable outside of itself. Instead, a copy of the variable with its value is generated for the new shell. The user makes a new login environment with the following actions: Action telnet su - The shell gets a total new set of environent variables. The environment variable SHLVL=1. The next files are executed in that order: /etc/profile /opt/linux_tools/.linux_tools /home/softdev/.bash_profile /home/softdev/.bashrc /etc/bashrc The user makes a sub-shell with the following actions: Action gnome-terminal su execute script-file The sub-shell gets a copy of the exported environment variables from its parent-shell. When a sub-shell is created from another (sub-)shell then the variable SHLVL is increased by 1. Thus SHLVL!=1. The next files are exectuted in that order, except for executing scriptfiles: /home/softdev/.bashrc /etc/bashrc /opt/linux_tools/.linux_tools Thus non-exported environment variables, aliases and functions are not copied from the parent-shell to a sub-shell. To make this possible for executing files, execute the file in its own shell: $ . <file> NOTE: Be sure the location of <file> is included in the PATH-environment variable. NOTE: Exported variables are NOT copied back from a sub-shell to its parent- shell. NOTE: Binairy files are always executed a sub-shell shell. However, the environment variable SHLVL is not increased. NOTE: The c-function "system" is also executed in a sub-shell. SHLVL is increased.
Description: Execute a <command> (=interrupt handler) when the shell receives <signal> (=interrupt). Syntax: $ trap [-lp] <command> <signal> Listing of the availble signals: $ trap -l Display <command> associated to <signal> $ trap -p Ignore a signal: $ trap '' <signal> Restore a signal to its original command: $ trap - <signal> Example : $ cat trap_example error_handler () { echo "error_handler: $1" } trap 'error=$?;error_handler $error' ERR bla #reset ERR-signal to original/default command. trap - ERR $ trap_example ./trap_example: line 6: bla: command not found error_handler: 127 $
As a brief introduction to vi, go through the following: First, type vi x at the Unix prompt. Assuming you did not already have a file named x, this command will create one. (If you have tried this example before, x will already exist, and vi will work on it. If you wish to start the example from scratch, simply remove x first.) The file will of course initially be empty. To put something in it, type the letter `i' (it stands for "insert-text mode"), and type the following (including hitting the Enter key at the end of each of the three lines): The quick brown fox will return. Then hit the Escape key, to end insert-text-mode. This mode-oriented aspect of the vi editor differs from many other editors in this respect. With modeless editors such as joe and emacs, for instance, to insert text at the cursor position, one simply starts typing, and to stop inserting, one just stops typing! However, that means that in order to perform most commands, one needs to use the Control key (in order to distinguish a command from text to be inserted). This has given rise to jokes that heavy users of modeless editors develop gnarled fingers. Now save the file and exit vi, by typing `ZZ' (note the capitals). Again, the key to learning vi is to keep in mind always the difference between insert-text mode and command mode. In the latter mode, as its name implies, one issues commands, such as the ZZ above, which we issued to save the file and exit vi. The characters you type will appear on the screen if you are in insert-text mode, whereas they will not appear on the screen while you are in command mode. By far the most frequent problem new vi users have is that they forget they are in insert-text mode, and so their commands are not obeyed. For example, suppose a new user wants to type ZZ, to save the file and exit vi, but he has forgotten to hit the Escape key to terminate insert-text mode. Then the ZZ will appear on the screen, and will become part of the text of the file- and the ZZ command will not be obeyed. You now have a file named x. You can check its contents by typing (at the Unix shell prompt) more x which will yield The quick brown fox will return. just as expected. Now let's see how we can use vi again to modify that file. Type vi x again, and make the following changes. First, suppose we wish to say the fox will not return: We need to first move the cursor to the word "return". To do this, type `/re' and hit the Enter key, which instructs vi to move the cursor to the first instance of `re' relative to the current cursor position. (Note that typing only `/r' would have moved the cursor to the first instance of `r', which would be the `r' in `brown', not what we want.) Now use the `i' command again: Hit `i', then type `not ' (note the space), and then hit Escape. Next, let's delete the word `brown'. Type `/b' to move the cursor there, and then hit `x' five times, to delete each of the five letters in `brown'. (This will still leave us with a blank line. If we did not want this, we could have used the `dd' command, which would have deleted the entire line.) Now type `ZZ' to save the file and exit vi. Use `more' again to convince yourself that you did indeed modify the file. : command line / search * select token Frequently used commands You now know how to use vi to insert text, move the cursor to text, and delete text. Technically, the bare-bones set of commands introduced above is sufficient for any use of vi. However, if you limit yourself to these few commands, you will be doing a large amount of unnecessary, tiresome typing. So, you should also learn at least some of these other frequently-used vi commands: h move cursor one character to left j move cursor one line down k move cursor one line up l move cursor one character to right w move cursor one word to right b move cursor one word to left 0 move cursor to beginning of line $ move cursor to end of line G or 0G move to end of file nG move cursor to line n control-f scroll forward one screen control-b scroll backward one screen control-v copy block V copy block of lines i insert to left of current cursor position (end with ESC) a append to right of current cursor position (end with ESC) A append to end of line (end with ESC) R begin overwrite mode (end with ESC) dw delete current word (end with ESC) cw change current word (end with ESC) r change current character ~ change case (upper-, lower-) of current character dd delete current line D delete portion of current line to right of the cursor x delete current character ma mark currrent position d`a delete everything from the marked position to here `a go back to the marked position p dump out at current place your last deletion (``paste'') u undo the last command . repeat the last command J combine (``join'') next line with this one :<number> move to line <number> :w write file to disk, stay in vi :q! quit VI, do not write file to disk, ZZ write file to disk, quit vi :r filename read in a copy of the specified file to the current buffer /string search forward for string (end with Enter) ?string search backward for string (end with Enter) n repeat the last search (``next search'') N go back to previous search :s/s1/s2 replace (``substitute'') (the first) s1 in this line by s2 :lr/s/s1/s2/gc replace all instances of s1 in the line range lr by s2 (lr is of form `a,b', where a and b are either explicit line numbers, or . (current line) or $ (last line) g = global; c = verify :map k s map the key k to a string of vi commands s (see below) :abb s1 s2 expand the string s1 in append/insert mode to a string s2 (see below) % go to the "mate," if one exists, of this parenthesis Some specials = Correct indentations after copy and past from other window \hm Toggle between hex mode and normal mode All of the `:' commands end with your hitting the Enter key. (By the way, these are called "ex" commands, after the name of the simpler editor from which vi is descended.) The `a' command, which puts text to the right of the cursor, does put you in insert-text mode, just like the `i' command does. By the way, if you need to insert a control character while in append/insert mode, hit control-v first. For example, to insert control-g into the file being edited, type control-v then control-g. One of vi's advantages is easy cursor movement. Since the keys h,j,k,l are adjacent and easily accessible with the fingers of your right hand, you can quickly reach them to move the cursor, instead of fumbling around for the arrow keys as with many other editors (though they can be used in vi too). You will find that this use of h,j,k,l become second nature to you very quickly, very much increasing your speed, efficiency and enjoyment of text editing. Many of the commands can be prefixed by a number. For example, 3dd means to delete (consecutive) three lines, starting with the current one. As an another example, 4cw will delete the next four words. The p command can be used for "cut-and-paste" and copy operations. For example, to move three lines from place A to place B: 1. Move the cursor to A. 2. Type `3dd'. 3. Move the cursor to B. 4. Type `p'. The same steps can be used to copy text, except that p must be used twice, the first time being immediately after Step 2 (to put back the text just deleted). Note that you can do operations like cut-and-paste, cursor movement, and so on, much more easily using a mouse. This requires a GUI version of vi, which we will discuss later in this document. Macro's When you are using vi, you can use the `map' and `abb' commands to save a lot of typing. For example, I often accidentally transpose two letters when I am typing fast, say typing `taht' instead of `that'. Since I do this so often, I place the command :map v xp which means that the v key now performs the operations `x' and `p', (try `xp' yourself and you will see it work), in my ~/.exrc file ((without the colon; see below).Also, since I often edit HTML files, I save myself typing by including lines like abb cg <FONT color=green>; in my .exrc file. This means that whenever I am vi's insert/append mode and type "cg" and then hit the space bar, vi will automatically expand it to "<FONT color=green>". Here are some more examples: map ; $ map - 1G map \ $G map ^K ~ map ^X :.,$d^M map! ^P ^[a. ^[hbmmi?\<^[2h"zdt.@z^Mywmx`mP xi map! ^N ^[a. ^[hbmmi/\<^[2h"zdt.@z^Mywmx`mP xi abb taht that abb wb http://heather.cs.ucdavis.edu/~matloff The first three simply perform cursor movement (to end-of-line, start-of-file, end-of-file) Most of them only saves one keystroke, but they require much less finger movement (for the standard touch-typing hand position) and since they are such frequently-used operations they are worthwhile. The fourth map is for case change, again (for me) a frequent operation. The fifth map deletes all material from the current cursor position to the end of the file. I often find this useful, when editing a reply to an e-mail message for instance, or when I use :r to import another file into the one I am editing. The sixth and seventh maps, which are labeled "map!" instead of "map" to indicate that they operate during append or insert mode, are modifications of some macros which are "famous" in the vi user community. They are used for "word completion," an extremely useful trick to save typing. Suppose for example I am currently in append/insert mode and I wish to type the word "investigation," and that I have used the word previously. If I just type, say, "inv" and then control-p, vi will search for a word earlier in my file which began with "inv" and complete my "inv" to that word, in this case "investigation ". Typing control-n will do the same thing, except that it will search forward instead of backwards. Note again that in typing these macros in one's .exrc file, one must hit control-v first. For example, to insert control-g into the file being edited during append/insert mode, type control-v then control-g. .exrc file When you invoke the vi editor, it will look for the file ~/.exrc and obey any "ex" commands it finds there. For example, I have lines in my startup file corresponding to the map and abb examples in the last section: map v xp abb cg <FONT color=gree>n (Note that in the .exrc file we omit the colon, i.e. we type "map" instead of ":map", because vi assumes these are all "ex" commands.) That way I have those settings (and many others) permanently set, rather than my needing to type them in again each time I use vi.