1 / 27

Basics of the Unix/Linux Environment

Basics of the Unix/Linux Environment. File Permissions and Text Editing. Dealing with file names with special characters.

jennis
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. Basics of the Unix/Linux Environment File Permissions and Text Editing

  2. Dealing with file names with special characters • Say I have a file named “!”. (this is probably because I used >! at some time while in bash, but this syntax is for tcsh not bash, so I redirected my output to a file called !) %ls ! ! %rm ! remove !? Y

  3. What about a file named “-”? Make a file named “-” with touch command (use man to see what the touch command does) %touch - %ls - f2.dat HW Try to remove it. %rm - usage: rm [-fiRr] file ... What is the problem? (you tell me.)

  4. We have to let the shell know that the “-” is NOT a switch. Use the “-” switch all by itself. %rm - - rm: remove - (yes/no)? y alpaca.ceri.memphis.edu193:>

  5. Remember that filenames can have any character but the “/” (used to define the path), so sooner or later you are going to get a file name that will be hard or dangerous to reference. You will have to be especially careful/creative if you get a file named “*” as %rm * is disastrous (and the more privileges you have and the higher up you are in the directory structure, the more disastrous it is.)

  6. Ownership • User • the person who created or is in charge of the file/directory (u) • Group • a group of users that can be associated with the file/directory (g) • Others • any user not part of the User or Group designation (o)

  7. Permissions • Read • ability to read the file/directory (r) • Write • ability to write or overwrite the file/directory (w) • Execute • ability to execute or run the file and view directories (x) • if a directory is not executable, you cannot cd into it or see what is in it at all.

  8. Viewing ownership & permissions • ls -l: lists long format % ls -aFl *pl bin | head -n 10 -rw-r--r-- 1 hdeshon user 42 Aug 20 13:47 helloworld.plstandard permissions -rwxr-xr-x 1 hdeshon user 1276 Aug 7 2007 res2sacfiles.pl* preferred executable permissions bin: used to store executable scripts and programs for global access total 40722 drwxr-xr-x 3 hdeshon user 3584 Aug 1 13:50 ./ standard directory permissions drwxr-xr-x 41 hdeshon user 2048 Aug 21 10:07 ../ -rwxr-xr-x 1 hdeshon user 13508 Aug 1 13:50 addcglags* -rwxr-xr-x 1 hdeshon user 1155 Aug 1 13:50 addnoise* -rwxr-xr-x 1 hdeshon user 49152 Aug 1 13:50 ah2asc*

  9. Changing owners and groups • If you create a file, you are the owner/user. • Mitch and Bob have the system set up to automatically set group to ‘user’, or all users of the CERI unix system. • Default for CERI files are rw-r--r-- otherwise known numerically as 644

  10. Changing Permissions • chmod: change file or directory permissions %chmodugo+xhelloworld.pl %ls –lFhelloworld.pl -rwxr-xr-x 1 hdeshon user 42 Aug 20 13:47 helloworld.pl* %chmodgo-rxhelloworld.pl %ls–lFhelloworld.pl -rwx------ 1 hdeshon user 42 Aug 20 13:47 helloworld.pl* • –R flag allows you to set all files to the same permissions within a directory and all subdirectories

  11. Changing Permissions • you can also use numbers to change ownership • 644 represents u+rw; g0=r • 755 represents u+rwx; go=rx#I use this one a lot %chmod 775 helloworld.pl %ls–lFhelloworld.pl -rwxr-xr-x 1 hdeshon user 42 Aug 20 13:47 helloworld.pl*

  12. Text Editing Options • Mouse-driven options • nedit: this GUI text editor allows interactive mouse or keyboard driven text manipulation; colored text and auto-recognition of various standard scripting and programming languages is helpful for debugging scripts and code; appears to be a student favorite at CERI and is available on the Unix system • emacs: a less sleek looking GUI text editor allows interactive mouse or keyboard driven text manipulation; it is very powerful and is an old favorite of computer programmers

  13. Text Editing Options • Keyboard-driven options • vim: this non-GUI text editor relies primarily on keyboard driven text manipulation; steep learning curve but very powerful; colored text and auto-recognition of various standard scripting and programming languages is helpful for debugging scripts and code; my personal favorite • pico: a pared down non-GUI text editor very similar to the email program pine. If you don’t know what pine is, use nedit instead.

  14. OK, nedit or vim • nedit is available on the CERI unix machines because Bob and Mitch have installed it • nedit has a shallow learning curve • vim is available standard on all unix and unix-like systems • vim is harder to learn *note to OSX users, nedit can be downloaded and installed on OSX. Xcode is a similar but more powerful editor for code development.

  15. NEdit • to start it up %nedit &an & placed at the end of a command line opens the program in the background so that you can continue to use the terminal window.

  16. This is what it looks like

  17. vim • to start it up %vim [name-of-file] • Two modes • normal/command mode • insert/input mode • Typing takes place in insert mode and the editing power comes to the fore in normal mode • Use esc to toggle out of insert mode

  18. moving the cursor esc type esc to enter normal mode $ 0 ^ ^f ^ ^b ^ control key $ -- go to end of line (eol) 0 -- go to beginning of line (bol) ^ -- go to first character at bol ^f -- scroll screen forward ^b -- scroll screen backwards

  19. to enter insert mode esc type esc to exit insert mode I,i A,a s i -- insert a -- append s -- substitute A -- append at end of line I -- insert at beginning of line

  20. deleting text esc type esc to enter normal mode dw dd X,x x -- delete character behind cursor X -- delete character in front of cursor dw -- delete word dd -- delete line Xdd -- delete next X lines

  21. copy, paste, undo and redo esc type esc to enter normal mode yw yy p U,u ^R control key ^ . ^ control key yy -- copy the line (yank) yw -- copy the word (yank) p -- paste the line or word after the cursor u -- undo change U -- undo all changes to the line ^R -- redo change . -- repeat last command

  22. search and replace esc type esc to enter normal mode :s/ :g/ : return n / /[word(s)] -- search for the next instance of the word or words n -- go to next instance of word or words :s/[old]/[new] -- substitute old with new string; cursor is on old string :g/[old]/s/[old]/[new]/g -- globally find old, substitute all old with new

  23. saving and exiting vim esc type esc to enter normal mode :q :w : return shift ZZ shift :w [filename] -- write to file :w! [filename] -- overwrite file :wq -- write and quit :q --- quit :q! --- quit without saving ZZ -- write and quit

  24. other useful features :![unix command] -- allows you to run standard unix commands without exiting vim; very useful with GMT Example :!ls *.SAC list all sac files in the current directory :set hlsearch -- will highlight all instances of a string when using /[word] to search >aB -- indent the block/loop defined by {} when cursor is located within the block in question :sp -- split the screen ^WW -- use to move from one split screen to the next; useful when writing subroutines within the same file : set number or :set nonumber -- turn line numbers on/off :X -- jump to line number X example :1go to first line of file

More Related