1 / 25

Basics of the Unix/Linux Environment

"Two of the most famous products of Berkeley are LSD and Unix. I don't think that this is a coincidence.” Anonymous. Basics of the Unix/Linux Environment. Common Commands. Making directories. mkdir : make directory % mkdir bin src Projects Classes

radwan
Download Presentation

Basics of the Unix/Linux Environment

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. "Two of the most famous products of Berkeley are LSD and Unix. I don't think that this is a coincidence.” Anonymous

  2. Basics of the Unix/Linux Environment Common Commands

  3. Making directories • mkdir: make directory % mkdir bin src Projects Classes Makes 4 directories: bin, src, Projects, and Classes in the working directory.

  4. Removing Directories • rmdir: remove directory; only works with empty directories but is safe % rmdir bin src Projects Classes Removes the 4 directories bin, src, Projects, and Classes in the working directory -- if they are EMPTY.

  5. Removing files and directories • rm: remove files and directories; a very straightforward and DANGEROUS command There is no trash can on a unix machine. CERI accounts are set up so that rm is aliased to rm –i, which means the computer will ask you if you really want to remove the file(s) one at a time %which rm rm: aliased to /bin/rm –i

  6. %rm file1 remove file1? yes % Valid answers. Yes, yes, Y, y – to accept and erase. No, no, N, n – to not erase. <CR> - does not erase. Something it does not understand – does not erase.

  7. rm –d: remove directory like rmdir • rm –r: remove directory and all subdirectories and files; implies –d; can be very dangerous… one typo could remove months of files % rm -r Classes • \rm: You can return to the original definition of rm using the “\”. You will no longer be prompted before a file is removed so don’t make a typo

  8. Looking at files • more: browse or page through a text file; opens file quickly and pages down full screen; use space bar to page down • less: same as more but allows forward and backward paging; in OSX, more is aliased to less because less is more with additional features

  9. Looking at files continued • head -nX: prints the first X number of lines to the screen; default is 10 lines if -n is not specified • tail -nX: prints the last X number of lines to the screen; default is 10 lines if -n is not specified (mac/linux) • tail -Xf: prints the last X number of lines to the screen; default is 10 lines if -f is not specified (ceri suns)

  10. Manipulating files • cat: concatenate files into a single column; it dumps the entire file contents to the screen unless redirected to a file • Since it dumps the entire file contents to the screen, we can use it to “print out” or ”type out” a file. %cat dead.letter Hello...testing Another Unix philosophy issue – use of side effects. We don’t need another command to print or type the contents of a file to the screen as it is a side effect of the cat command.

  11. Example: make one file out of file1, file2 and file3 and call it alltogether. %cat file1 file2 file3 > alltogether or %cat file1 file2 file3 • This command (does not need input redirection, exception to regular rule that input comes from Standard IN) takes files file1, file2, and file3 and puts them into file alltogether or you can skip creating the file alltogether

  12. Creating files using cat - type the command %cat > name_of_file Now type in your text. Press the <Return> key to start a new line. When you have finished typing in your text, enter Ctrl-d (Press and hold down the Ctrl key and type a "d"). This stops the cat command and returns you to the system prompt. %cat > test.file Hello everyone<CR> CNTL-D %more test.file Hello everyone

  13. paste: concatenate files with each file a new column; when used on a single file, it dumps the entire file contents to the screen

  14. Piping and Redirect • Input and output on the command line are controlled by the |, >, <, and ! symbols • | : pipe function; sends the output from command on left side as input to the command on the right side % cdSACdata % ls | head -n5 1002 1019 1023 1045 1046

  15. Piping and Redirect • > : redirect standard output (screen) to a specific file* % cdSACdata % ls | head -n5 > directory.list % more directory.list 1002 1019 1023 1045 1046 * In tcsh, this will not overwrite a pre-existing file with the same name. In bash shell, the > overwrites any pre-existing file with no warning

  16. Piping and Redirect • >! : redirect standard output (screen output) to a specific file and overwrite the file if it already exists * % ls | head –n5 >! directory.list % more directory.list 1002 1019 1023 1045 1046 *This syntax is specific to tcsh, your default CERI shell; in bash this will put the output into a file named !

  17. Piping and Redirect • >> : concatenate standard output (screen output) to the end of a specific file % ls | head –n2 >! directory.list % ls | tail –n2 >> directory.list % more directory.list 1002 1019 tmp tmp.file • < : redirect file on right as input to command on the left % head –n1 < suma1.hrdpicks 1 51995 31410273254 30870 958490 297

  18. Copying, moving, or linking files & directories • cp: copy files • cp -r: copy directory and all files & subdirectories within it % cp file1 Project/SUMATRA/file2 % cp file1 Project/SUMATRA/.

  19. mv: move files or directories % mv file1 file2 Project/SUMATRA/. • If you want to change the names when you move them, you have to do them one at a time % mv file1 ESCI7205/HW/HW1 % mv file2 ESCI7205/HW/HW2

  20. ln -s: create a symbolic link between two files % ln –s sourcefile1 Project/SUMATRA/targetfile1 % ln –s sourcefile1 Project/SUMATRA/. This makes the file show up in the new directory (the target) listing, but the file really only exists in the original place.

  21. Wildcards • Wildcards all you to match multiple instances of characters/numbers in file or directory names • They can be used in combination with almost all unix commands • Wildcards are essential when dealing with large amounts of geophysical data

  22. Wildcards • * : represents zero or more characters or numbers % ls 2/*.BHZ.* 2/HIA.BHZ.SAC 2/WMQ.BHZ.SAC 2/filt.HIA.BHZ.SAC 2/filt.WMQ.BHZ.SAC %ls 2/f*.BHZ.* 2/filt.HIA.BHZ.SAC 2/filt.WMQ.BHZ.SAC • ? : represents a single character or number % ls 2/HIA.BH?.* 2/HIA.BHE.SAC 2/HIA.BHN.SAC 2/HIA.BHZ.SAC

  23. Wildcards • [] : single placeholder used to specify a range of characters or numbers rather than all possible characters or numbers % ls 2/HIA.BH[E,N,Z].* 2/HIA.BHE.SAC 2/HIA.BHZ.SAC 2/HIA.BHN.SAC % ls */HIA*198[0-9]* 795/HIA.BHZ.D.1988.041:07.18.30 799/HIA.BHZ.D.1988:14:35:27.00 812/HIA.BHZ.D.1988:03:43:49.00 813/HIA.BHZ.D.1988.362:13.58.59 814/HIA.BHZ.D.1989.041:17.07.43

  24. CNTL-C • Use CNTL-C to quit a job • If you accidently start something that isn’t working, CNTL-C will quit and return you to a blank command line

  25. See this link for a list and description of many Unix commands http://pcsplace.com/tech-list/ultimate-list-of-linux-and-unix-commands/

More Related