Basic Linux Commands and Procedures

Basic Linux Commands and Procedures


The list of bare-bones Linux commands

Here are some very basic linux commands that we will use. Many of the LMORPHO tasks assume the user has the ability to use these commands. One important concept in any linux/unix environment is that of "path". A file may be located in a large "directory" tree structure. Each directory may contain many "files". The user can refer to any file using the full path name (i.e. linking all of the directories together as well as the final file name). As an example, the first image that we worked on was:

 
/morpho3/sco/projects/c_crawford/images/lris/pss1317_ast.fits

To get to the above file and do things with it, we might use some of the following common tasks:

 
cd    - change directory 
  example:  cd /morpho3/sco/projects/

mkdir   - create a directory 
  example:  mkdir /morpho3/sco/projects/our_work 

ls    - list files in current directory   
  example:  ls           list everything  
  example:  ls *.fits    list all FITS files  
  example:  ls a*   list all file names starting with "a"  
  example:  ls -FC  list files with SYMBOLS (dir, etc...)  

pwd   - list the location of the current directory 
  example:  pwd    

history  - list the commands you recently used  

rm   - remove a file  
  example:  rm a.fits   deletes the file a.fits 
  example:  rm t*.fits   deletes all FITS filessatring with "t" 
  example:  rm -i a.fits   deletes a.fits AFTER INTERROGATION 

cat   - stick two (or more) files together into one file  
  example:  cat a b > c   glue "a" and "b" into a file called "c"  

mv    - move a file to a new name 
  example:   mv a b   rename file "a" to be "b" 

cp    - copy a file to a new name 
  example:   cp a b   copy file "a" to be "b" 

cp -r    - copy a DIRECTORY to a new name 
  example:   cp -r dir_a dir_b   copy file directory "a" to be "b" 


Editing files with vi.

One of the early Unix file editors is called "vi". Many of the jobs we'll perform with LMORPHO will require the ability to create and modify simple text files. To create a file called "FILES.LIST" we could use the following command line:

 
[sco@morpho]#  vi FILES.LIST  

At this stage you are running a program (the vi program). From here on you'll issue vi commands that allow you to insert text, modify text, delete text, etc.... When the file is shaped up the way you want it, just type "shift-ZZ" to get out of the editor. Here are some of the basic vi commands:

 
i    - insert text 
   
              After this, you will see the text that 
              you type appear in the vi screen.   

a    - append text starting at cursor position 

ESC    - get out of insert mode 

j   - move the cursor to next line 
k   - move the cursor to previous line 
l   - move the cursor to the right  
h   - move the cursor to the left 

x   - delete character under cursor 
10x   - delete 10 characters

dd   - delete 1 line of text (at cursor location)
3dd   - delete 3 lines of text (at cursor location)

 /   - Search for a string. After you hit "/" a
font "/" font appears at the bottom of the screen where you can type in 
a string to be searched for. The search occurs after you hit return.
 
 u   - Undo the last change you made. 

shift-ZZ   - exit the vi program 

Printing files in PSF 276

To print PostScript files on the laser writers in PSF 276:

lpr -Ppro1 filename           (B/W printer) 
lpr -Ppro2 filename           (color printer) 


Writing shell scripts in linux.

You can place a list of linux commands into a single file, make that file executable. and then execute those commands by simply typing the name of file. Such a file is then called a shell script. Here is a simple example. I use the vi editor discussed above to create a file called "test.scrpt" with the following lines:
vi test.scrpt
more test.scrpt

 
#
echo "    "
echo "Contents of my directory: "
ls
echo "    "
echo "The present time:
date

To make the shell script executable:
chmod 777 test.scrpt
To run the script:
test.scrpt
This one command will now perform all of the commands we placed in our script!


Back to ACUG page