Presentation is loading. Please wait.

Presentation is loading. Please wait.

Unix Shell Basics Edited from Greg Wilson's "Software Carpentry"

Similar presentations


Presentation on theme: "Unix Shell Basics Edited from Greg Wilson's "Software Carpentry""— Presentation transcript:

1 Unix Shell Basics Edited from Greg Wilson's "Software Carpentry" http://www.swc.scipy.org/

2 Introduction Most modern tools have a graphical user interface (GUI) But command-line user interfaces (CLUIs) still have their place Easier to build a simple CLUI than a simple GUI Higher action-to-keystroke ratio Easier to see and understand what the computer is doing on your behalf Which is part of what this course is about Most important: it's easier to combine CLUI tools than GUI tools Small tools, combined in many ways, can be very powerful This lecture focuses on Unix

3 The Shell The most important command-line tool is the command shellcommand shell Usually just called “the shell” Looks (and works) like an interactive terminal circa 1980 (or cmd in Windows)

4 Varieties of Shell The shell is just one program among many Many different shells have been written The Bourne shell, called sh, is an ancestor of many of them It's still a lowest common denominator that you can always rely on We'll use bash (the Bourne Again Shell) in this course Even on Windows (thanks to Cygwin)Cygwin Others include C shell (csh), TC shell (tcsh), etc.

5 Paths Files and Directories are items in the file system A path is a description of how to find something in a file systempath An absolute path describes a location from the root directory downabsolute path  Equivalent to a street address  Always starts with "/"  /home/hpotter is Harry Potter's home directory  /courses/swc/web/lec/shell.html is this file A relative path describes how to find something from some other locationrelative path  Equivalent to saying, “Four blocks north, and seven east”  From /courses/swc, the relative path to this file is web/lec/shell.html

6 Current Directory Every program (including the shell) has a current working directorycurrent working directory pwd. Every directory has a parent cd.. Every user has a home cd ~

7 Navigating pwd cd ls

8 Options ls –F ls –a ls –l ls –l -t

9 Viewing Files cd /usr/include cat math.h more math.h

10 Getting help man – the Unix Manual if installed correctly! man ls man more

11 Grep grep extern math.h grep –v extern math.h

12 Word Count wc math.h

13 Doing Instead of Looking cd ~ mkdir mydir cd mydir cp /usr/bin/math.h. ls

14 Optimization Example Download SimulationApp.class Put in local directory, and run java SimulationApp look in coarse_grid_script runs simulation many many times Too much output to handle!

15 Redirection coarse_grid_script > result_file /usr/bin/sort result_file /usr/bin/sort –g –k 8 result_file Don’t re-invent the wheel! Don’t code sorting routines into your own code unless absolutely necessary

16 awk awk '{print $7}' result_file awk '{print $7 $8}' result_file awk '{print $7" "$8}' result_file

17 Pipes awk '{print $7" "$8}' result_file | /usr/bin/sort -g –k 2 > sorted_outputs

18 License Copyright © 2005-06 Python Software Foundation Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.


Download ppt "Unix Shell Basics Edited from Greg Wilson's "Software Carpentry""

Similar presentations


Ads by Google