Saturday, April 9, 2016

Change File Permissions in Terminal OSX

Knowledge about changing permissions for a specific file is pretty important and can even save Your information from being lost.

So let's see what we can check and how.

1. Execute next command in Your terminal window:

$ ls -la

You should see same information as on screen below.


What do those letters form first column stand for?
- d = directory
- r = read access
- w = write access
- x = execute access
- - = no permissions at all

Column 3 indicates owner of a file and column four shows us an user's group which might has or not permissions to read/write/execute file.

So if we'll check first column again from left to write we'll see that:

- first symbol / several symbols - user's permissions
- second symbol (after dash) / symbols - group permissions
- third symbol / symbols - all other users permissions

Let's analyse example.txt file:

- user has read and write permissions
- group has read and write permissions
- other users have only read permission

2. If You want to change ownership of the file just execute:

$ sudo chown NEW_USER:NEW_GROUP example.txt

this command will update owner and group for this file.

3. If You want just update permissions for specific file then You need to execute:

$ sudo chmod 000 example.txt

this command deny all actions with this file for all users.

4. Let's explore octets in general:

- 0 - No read, no write, no execute  - " - "
- 1 - No read, no write, execute       - " -x "
- 2 - No read, write, no execute       - " -w- "
- 3 - No read, write, execute            - " -wx "
- 4 - Read, no write, no execute      - " r- "
- 5 - Read, no write, execute           - " r-x "
- 6 - Read, write, no execute           - " rw- "
- 7 - Read, write, execute                - " rwx "

5. So according to this table if we'll execute next command:

$ sudo chmod 432 example.txt

- owner will be able only to read file;
- group will be able to write and execute;
- all others will be able only to write.

6. If You want to apply same permission to folder and all its content You have to add one more flag to Your command:

$ sudo chmod -R 777 Documents

This is pretty much core knowledge which You have to have in order to change permissions for folder / file in OSX terminal.

Monday, April 4, 2016

Use Multiple Python Versions In OSX

This post aims to help with managing several different Python versions on OSX without any troubles.

As usually just follow next steps:

1. $ brew update

2. $ brew install pyenv

3. Add into .bashrc: 

" if which pyenv > /dev/null; then eval "$(pyenv init -)"; fi"

4. Shows list of options

$ pyenv install -l  

5. Installs needed python version

$ pyenv install X.XX.XX 

6. Shows installed python versions in system

$ pyenv versions 

7. Sets specific version as global one

$ pyenv global X.XX.XX 

8. Sets specific version as local one

$ pyenv local X.XX.XX 

9. Unsets local version for python

$ pyenv local --unset 

For further exploring:

10. Shows list of available commands for pyenv

$ pyenv commands 

This is pretty much enough for this topic (at least for now).