Basics of the Unix/Linux Environment
description
Transcript of Basics of the Unix/Linux Environment
![Page 1: Basics of the Unix/Linux Environment](https://reader035.fdocuments.us/reader035/viewer/2022062301/5681615a550346895dd0e613/html5/thumbnails/1.jpg)
![Page 2: Basics of the Unix/Linux Environment](https://reader035.fdocuments.us/reader035/viewer/2022062301/5681615a550346895dd0e613/html5/thumbnails/2.jpg)
Basics of the Unix/Linux
EnvironmentFile Permissions and Text Editing
![Page 3: Basics of the Unix/Linux Environment](https://reader035.fdocuments.us/reader035/viewer/2022062301/5681615a550346895dd0e613/html5/thumbnails/3.jpg)
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
![Page 4: Basics of the Unix/Linux Environment](https://reader035.fdocuments.us/reader035/viewer/2022062301/5681615a550346895dd0e613/html5/thumbnails/4.jpg)
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.)
![Page 5: Basics of the Unix/Linux Environment](https://reader035.fdocuments.us/reader035/viewer/2022062301/5681615a550346895dd0e613/html5/thumbnails/5.jpg)
We have to let the shell know that the “-” is NOT a switch.
Use the “-” switch all by itself.%rm - -rm: remove - (yes/no)? yalpaca.ceri.memphis.edu193:>
![Page 6: Basics of the Unix/Linux Environment](https://reader035.fdocuments.us/reader035/viewer/2022062301/5681615a550346895dd0e613/html5/thumbnails/6.jpg)
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.)
![Page 7: Basics of the Unix/Linux Environment](https://reader035.fdocuments.us/reader035/viewer/2022062301/5681615a550346895dd0e613/html5/thumbnails/7.jpg)
OwnershipUser
the person who created or is in charge of the file/directory (u)
Groupa group of users that can be associated with the
file/directory (g)
Othersany user not part of the User or Group designation (o)
![Page 8: Basics of the Unix/Linux Environment](https://reader035.fdocuments.us/reader035/viewer/2022062301/5681615a550346895dd0e613/html5/thumbnails/8.jpg)
PermissionsRead
ability to read the file/directory (r)
Writeability to write or overwrite the file/directory (w)
Executeability 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.
![Page 9: Basics of the Unix/Linux Environment](https://reader035.fdocuments.us/reader035/viewer/2022062301/5681615a550346895dd0e613/html5/thumbnails/9.jpg)
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.pl standard 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 40722drwxr-xr-x 3 hdeshon user 3584 Aug 1 13:50 ./ standard directory
permissionsdrwxr-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*
![Page 10: Basics of the Unix/Linux Environment](https://reader035.fdocuments.us/reader035/viewer/2022062301/5681615a550346895dd0e613/html5/thumbnails/10.jpg)
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
![Page 11: Basics of the Unix/Linux Environment](https://reader035.fdocuments.us/reader035/viewer/2022062301/5681615a550346895dd0e613/html5/thumbnails/11.jpg)
Changing Permissionschmod: change file or directory permissions
%chmod ugo+x helloworld.pl%ls –lF helloworld.pl
-rwxr-xr-x 1 hdeshon user 42 Aug 20 13:47 helloworld.pl*
%chmod go-rx helloworld.pl%ls –lF helloworld.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
![Page 12: Basics of the Unix/Linux Environment](https://reader035.fdocuments.us/reader035/viewer/2022062301/5681615a550346895dd0e613/html5/thumbnails/12.jpg)
Changing Permissionsyou can also use numbers to change ownership
644 represents u+rw; g0=r755 represents u+rwx; go=rx #I use this one a
lot
%chmod 775 helloworld.pl%ls –lF helloworld.pl
-rwxr-xr-x 1 hdeshon user 42 Aug 20 13:47 helloworld.pl*
![Page 13: Basics of the Unix/Linux Environment](https://reader035.fdocuments.us/reader035/viewer/2022062301/5681615a550346895dd0e613/html5/thumbnails/13.jpg)
Text Editing OptionsMouse-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
![Page 14: Basics of the Unix/Linux Environment](https://reader035.fdocuments.us/reader035/viewer/2022062301/5681615a550346895dd0e613/html5/thumbnails/14.jpg)
Text Editing OptionsKeyboard-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.
![Page 15: Basics of the Unix/Linux Environment](https://reader035.fdocuments.us/reader035/viewer/2022062301/5681615a550346895dd0e613/html5/thumbnails/15.jpg)
OK, nedit or vimnedit 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.
![Page 16: Basics of the Unix/Linux Environment](https://reader035.fdocuments.us/reader035/viewer/2022062301/5681615a550346895dd0e613/html5/thumbnails/16.jpg)
NEditto 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.
![Page 17: Basics of the Unix/Linux Environment](https://reader035.fdocuments.us/reader035/viewer/2022062301/5681615a550346895dd0e613/html5/thumbnails/17.jpg)
This is what it looks like
![Page 18: Basics of the Unix/Linux Environment](https://reader035.fdocuments.us/reader035/viewer/2022062301/5681615a550346895dd0e613/html5/thumbnails/18.jpg)
![Page 19: Basics of the Unix/Linux Environment](https://reader035.fdocuments.us/reader035/viewer/2022062301/5681615a550346895dd0e613/html5/thumbnails/19.jpg)
vimto start it up
%vim [name-of-file]
Two modesnormal/command modeinsert/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
![Page 20: Basics of the Unix/Linux Environment](https://reader035.fdocuments.us/reader035/viewer/2022062301/5681615a550346895dd0e613/html5/thumbnails/20.jpg)
![Page 21: Basics of the Unix/Linux Environment](https://reader035.fdocuments.us/reader035/viewer/2022062301/5681615a550346895dd0e613/html5/thumbnails/21.jpg)
moving the cursoresc
0$ ^
$ -- 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
type esc to enter normal mode
^
^control key
^f
^b
![Page 22: Basics of the Unix/Linux Environment](https://reader035.fdocuments.us/reader035/viewer/2022062301/5681615a550346895dd0e613/html5/thumbnails/22.jpg)
to enter insert modeesc
s
I,i
A,a
i -- inserta -- appends -- substitute
A -- append at end of lineI -- insert at beginning of line
type esc to exit insert mode
![Page 23: Basics of the Unix/Linux Environment](https://reader035.fdocuments.us/reader035/viewer/2022062301/5681615a550346895dd0e613/html5/thumbnails/23.jpg)
deleting textesc type esc to enter normal
mode
dd
x -- delete character behind cursorX -- delete character in front of cursor
dw -- delete worddd -- delete lineXdd -- delete next X lines
X,x
dw
![Page 24: Basics of the Unix/Linux Environment](https://reader035.fdocuments.us/reader035/viewer/2022062301/5681615a550346895dd0e613/html5/thumbnails/24.jpg)
copy, paste, undo and redo
esc type esc to enter normal mode
p
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
U,uyyyw ^R
^
^control key
control key .
![Page 25: Basics of the Unix/Linux Environment](https://reader035.fdocuments.us/reader035/viewer/2022062301/5681615a550346895dd0e613/html5/thumbnails/25.jpg)
search and replaceesc type esc to enter normal
mode
/
/[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
n
:s/ return:g/ :
![Page 26: Basics of the Unix/Linux Environment](https://reader035.fdocuments.us/reader035/viewer/2022062301/5681615a550346895dd0e613/html5/thumbnails/26.jpg)
saving and exiting vim
ZZ
:w:q
:w [filename] -- write to file:w! [filename] -- overwrite file:wq -- write and quit
:q --- quit:q! --- quit without savingZZ -- write and quit
esc type esc to enter normal mode
:
shift shift
return
![Page 27: Basics of the Unix/Linux Environment](https://reader035.fdocuments.us/reader035/viewer/2022062301/5681615a550346895dd0e613/html5/thumbnails/27.jpg)
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 :1 go to first line of file