Editing
Scanco Administration
(section)
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===Unix command line basics=== ====Twelve Essential Commands==== These are the commands which you have to know in order to be basically functional with a shell (command line). {| |-valign="top" |width="80pt"| <tt>ls</tt> | List directory contents. <tt>ls -l</tt> long listing with dates and permissions <tt>ls -a</tt> list all, including hidden files (hidden files start with a period) |-valign="top" | <tt>cd</tt> | Change directory. <tt>cd -</tt> change to previous directory <tt>cd ~</tt> change to home directory <tt>cd ..</tt> change to parent directory |-valign="top" | <tt>pwd</tt> | Print current (working) directory. |-valign="top" | <tt>cp</tt> | Copy file(s). <tt>cp -r somedir somedest</tt> Copy recursively (directory and all contents) |-valign="top" | <tt>mv</tt> | Move (or rename) a file (or directory) |-valign="top" | <tt>rm</tt> | Delete (remove) a file. <tt>rm -r somedir</tt> Delete recursively (directory and all contents) <tt>rm -ri somedir</tt> Delete recursively, but prompt before each removal <tt>rm -rf somedir</tt> Delete recursively, never prompt |-valign="top" | <tt>mkdir</tt> | Create directory. |-valign="top" | <tt>rmdir</tt> | Remove (empty) directory. |-valign="top" | <tt>cat</tt> | Print file contents (to console). |-valign="top" | <tt>less</tt> | Scroll through file contents, one page at a time. SPACEBAR to advance a page, B to go back a page, Q to quit, /pattern to search for pattern |-valign="top" | <tt>man</tt> | Get help on <tt>command</tt>. (eg. <tt>man ls</tt> for help on <tt>ls</tt>). You move around in man as you do with less: SPACEBAR is forward a page, and so on. |-valign="top" | <tt>exit</tt> | Close shell (i.e. the terminal). If this is your login shell, you will log out. |} [[Image:Redirect.jpg|15px]] [[#top|''Return to Contents'']] or [[Main_Page|''Return to Main Page'']] ====File names with spaces==== Spaces on the command line separate arguments. Therefore file names containing spaces require special treatment to avoid being interpreted as two separate files. There are a couple of methods. You can use quotes: cp "file name with spaces" file_name_without_spaces You can also use the backslash, which indicates that any special significance is to be removed from the following character. Thus a space, instead of being the delimiter for arguments on a command line, is to be interpreted as a regular character. cp file\ name\ with\ spaces file_name_without_spaces [[Image:Redirect.jpg|15px]] [[#top|''Return to Contents'']] or [[Main_Page|''Return to Main Page'']] ====Copying and pasting==== Copying and pasting in a terminal is generally done with the middle mouse button. Just mark the text you want to copy with the mouse, holding down the left mouse button in the usual way. Then move the cursor (which is different than the mouse pointer - move the cursor with arrow keys typically) to where you want to insert and click the middle mouse button (on a wheel mouse the middle button is the wheel). Tip: You can double-click to mark a whole work, or triple-click to mark a whole line. Remember - you haven't only marked it, you've put it in the clipboard. Note: This applies to X11, for example on Linux. If using OS-X, just use Option-C and Option-V as usual. [[Image:Redirect.jpg|15px]] [[#top|''Return to Contents'']] or [[Main_Page|''Return to Main Page'']] ====Recalling previous commands==== You can scroll though your previous commands (command history) by using the UP and DOWN arrow keys. A more advanced trick is to use CTRL-R, which is particularly useful when you want to recall a command you used some time ago. Hit CTRL-R and then start typing some fragment of the command you're searching for. The prompt will automatically update to show you the most recent match to the fragment you've typed so far. If you want the matching command previous to the one shown, hit CTRL-R again. Once you've got the previous command you're looking for, hit ENTER to run it again, or start editing it. [[Image:Redirect.jpg|15px]] [[#top|''Return to Contents'']] or [[Main_Page|''Return to Main Page'']] ====Be lazy: use TAB to minimize typing==== Some commands and especially some file names can be pretty long. Don't want to type it all? Type the first few letters, then hit TAB. The shell will fill in the rest, as far as there is a unique completion (either command or filename). If there is not a unique completion to the end, you might have to type another character or two and then hit TAB again. [[Image:Redirect.jpg|15px]] [[#top|''Return to Contents'']] or [[Main_Page|''Return to Main Page'']] ====Keyboard Shortcuts==== Here are some common command line keyboard shortcuts. Some of these are bash-specific shortcuts, so not all of them will work on all systems. Note: If you're using OS-X, a number of the editing shortcuts below work in ALL programs in OS-X. (With the sad exception of Microsoft Office, which overrides the system-wide key bindings.) {| |+ Table 1. Common editing key bindings |- |width="80pt"| <tt>CTRL-A</tt> || Move to the end of the line. |- | <tt>CTRL-E</tt> || Move to the beginning of the line. |- | <tt>CTRL-F</tt> || Move forward one character. |- | <tt>CTRL-B</tt> || Move backward one character. |- | <tt>ALT-F</tt> || Move forward one word. |- | <tt>ALT-B</tt> || Move backward one word. |- | <tt>CTRL-D</tt> || Delete one character forward. |- | <tt>CTRL-H</tt> || Delete one character backward. |- | <tt>ALT-D</tt> || Delete one word forward. |- | <tt>CTRL-W</tt> || Delete one word backwards. |- | <tt>CTRL-K</tt> || Delete (Kill) everything from the cursor forwards (to the end of the line). |- | <tt>CTRL-U</tt> || Delete everything from the cursor backwards (to the beginning of the line). |- | <tt>CTRL-T</tt> || Transpose two characters. |- | <tt>ALT-T</tt> || Transpose two words. |- | <tt>ESC .</tt> || Insert the last argument (word) from the previous command. |- | <tt>CTRL-X-X</tt> || Move between end of line and current cursor position |} {| |+ Table 2. Common control key bindings |width="80pt"| <tt>CTRL-C</tt> || Terminate the current program, or sometimes cancel some operation. |- | <tt>CTRL-\</tt> || Seriously kill the current program! Use only after <tt>CTRL-C</tt> has failed. |- | <tt>CTRL-D</tt> || End-of-file. This is often used to signal the end of input, or to exit a program. |- | <tt>CTRL-G</tt> || Cancel the current operation. An occasionally useful command to get yourself out of things. |- | <tt>CTRL-L</tt> || Redraw the console. Mostly useful if some program running in the background spews a lot of stuff onto your terminal. |- | <tt>CTRL-Q</tt> || The only time you need this is if you accidently hit <tt>CTRL-S</tt>. In that case the console is locked until you hit CTRL-Q to unlock it. Apparently once a long long time ago this was actually a useful feature. |- | <tt>CTRL-R</tt> || Recall command containing characters. After hitting <tt>CTRL-R</tt>, type the fragment you want to search for. If it returns a command which isn't the one one want, hit <tt>CTRL-R</tt> again to cycle through matches. |- | <tt>CTRL-Z</tt> || Suspend the current program and put it in the background. This is very useful once you figure out how it works. Refer to the section on putting jobs in the background. |} [[Image:Redirect.jpg|15px]] [[#top|''Return to Contents'']] or [[Main_Page|''Return to Main Page'']] ====Using scp to copy files between computers==== scp is a secure copy command that works bewteen computers. Typically any computer that supports ssh also supports scp. You must have an actual user account on the target computer, so for example you typically won't be able to scp to mike.kin . scp works just like the cp command, with a few extra decorations: scp eric@mighty-mac.kin.ucalgary.ca:Documents/important_file.txt . In this example the file I want to copy is on the computer mighty-mac.kin.ucalgary.ca, and I used eric@ to specify my user name. You can leave off the user name if it is the same on both computers. The period as the destination is just standard Unix short-hand for the current directory. You can use the -r flag to copy whole directories. For example: scp -r calculations mighty-mac.kin.ucalgary.ca:Documents/Projects In this example calculations is a directory containing many files, and possibly subdirectories. This example copies files to mighty-mac instead of from it. [[Image:Redirect.jpg|15px]] [[#top|''Return to Contents'']] or [[Main_Page|''Return to Main Page'']] ====Running long calculations==== Here are some useful tips for running long jobs. =====Getting the prompt back after starting a job===== Use & at the end of the command. This puts the job in the background. For example: ./myjob someargs & To see all your background jobs (the ones started in the current shell), enter: jobs To bring one of these to the foreground, use: fg %n where <tt>n</tt> is the job number (yes it needs a <tt>%</tt> in front of it). To move it to the background again, hit CTRL-Z. This however doesn't just move the job to the background, it suspends it. To get it running again, use bg %n [[Image:Redirect.jpg|15px]] [[#top|''Return to Contents'']] or [[Main_Page|''Return to Main Page'']] =====Keeping a job running after you log out===== Use nohup. For example, suppose you want to run <tt>./myjob 20</tt>. In this case, you could use: nohup nice ./myjob 20 &> output & There are several things to note here: * The <tt>&</tt> at the end of the command line is there so you get the command prompt back immediately (see the previous section). * We have redirected the output to a file out_file with <tt>&> output</tt>. If you don't do this, any output to STDIN (normally the console) will automatically go into a file called <tt>nohup.out</tt>. * We've niced the job to reduce it's execution priority. This is courteous if you're a multiuser system. If you want to see what's in nohup.out (or whatever you called it) at any time, you can do the usual cat nohup.out Here's another potentially more useful command: tail -f nohup.out tail shows you the last few lines of the files. In addition, the -f flag ("follow") means that as lines get added to the file, they are displayed on the screen. This looks just like when you run the program without nohup, except when you hit CTRL-C, the program keeps on running in the background. [[Image:Redirect.jpg|15px]] [[#top|''Return to Contents'']] or [[Main_Page|''Return to Main Page'']] =====Finding out if any of your jobs are still running===== This command will show all jobs that belong to user "eric": ps -u eric Another useful command is "top", which will show interactively which processes are using the most processor cycles. [[Image:Redirect.jpg|15px]] [[#top|''Return to Contents'']] or [[Main_Page|''Return to Main Page'']] =====Terminating a job prematurely===== If you decide that you want to kill the job before it completes, this is the command: kill PID where PID is the actual PID (a number) of the process. You find the PID with 'top' or 'ps -u eric' (replace eric by your user ID of course). Occasionally a process will decline to terminate when you request it to. This is the more brutal, never-fails method to kill a job immediately: kill -s KILL PID [[Image:Redirect.jpg|15px]] [[#top|''Return to Contents'']] or [[Main_Page|''Return to Main Page'']] =====Suspending a long-running job and restarting it later===== First find the PID (process ID) with top or with ps. For example, I might list all jobs belonging to me with: ps -u eric To stop the job, send it a STOP signal: kill -s STOP PID (replace PID with the actual PID number). It is now no longer running, but it still occupies memory (although the memory it uses will probably be swapped out to disk). When you want to resume execution, give it a CONT signal: kill -s CONT PID [[Image:Redirect.jpg|15px]] [[#top|''Return to Contents'']] or [[Main_Page|''Return to Main Page'']]
Summary:
Please note that all contributions to bone.wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
BoneWiki:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Navigation menu
Personal tools
Not logged in
Talk
Contributions
Log in
associated-pages
Page
Discussion
English
Views
Read
Edit
View history
More
Search
Navigation
Main page
Documents
Recent changes
Help
Tools
What links here
Related changes
Page information