Tuesday, February 9, 2010

MacOs X and UNIX | Basic Tutorial

Getting Started on MacOs

You can skip this if you know how to access your unix command-line
- Open: Applications -> Utilites (shortcut: cmd-shift-U)
- Run Terminal.app

Browsing

The standards for Unix filesystems are as follows
/ -The root directory / The directory divider symbol
~/ -Your home folder
./ -The current directory
../ -Up one directory
* -The wildcard symbol
Directory: For those who only ever use the Finder or Filesystem GUI, a directory is a folder... baisically. Really a directory is just a pointer to any memory address.

Commands

cd -Change to the given directory
ls -List the contents of the active directory
rm -Erase a memory link (delete a file)
srm -Securely erase a link, by writing all zeros (like rm but it actually wipes the memory instead of just removing the pointer.)
mkdir -Make a new directory in current location. (Like New Folder)
mv- Copy files from one place to another

Excercises and Examples
Try these out to see if you understand:
Remove the quotations when typing commands.

1.

-Type ls, this should list the contents of your home folder, which is of course a directory. From here on all folders will be referred to as directories. If you do not see your home directory type cd ~/.
-Type touch test.noway. The touch command updates the last modified date of a file or creates a new one if the given filename does not exist. I used the .foobar extension to make sure you didnt accidentally change a file you had which happened to be named test.
-Switch to the finder and go to your home folder. You should now see a file called test.foobar.
-You just created that file well move it in exercise 2

2.

-Type ls, this should list the contents of your home folder. If you do not see your home directory type cd ~/.
-Type mkdir foo a new folder will appear named foo.
-Press the up arrow key to recall mkdir foo
Type mkdir foo/bara new folder will appear in foo named bar.
You can use the arrow-keys to scroll through command history at any time.
-Type touch test.noway this will create an empty file if you didn not do the first lesson.
-Type mv test.noway foo/bar test.noway is now in ~/foo/bar/
-Type mv ~/foo/bar/test.nowway ~/Pictures test.noway is now in your pictures folder.
-Type cd ~/Pictures ls will show you that you are in your pictures folder.
-Type mv test.noway ../ test.noway should move up one directory into you home folder.
-Type pwd you should see the path of your active directory.
-Type cd ../ your active directory should move up one to ~/. You can use pwd to test this.
-Type srm test.noway this will securely remove test.noway. Your computer may make funny clicking noises, but that is normal.
-Type rm foo You will receive an error message. Unix cannot by default delete a directory if there is something in it. Either delete ~/foo/bar/ or type rm -R this is what is known as a flag, switch, or dip-switch. -R will cause rm to load the hierarchy for deletion by reading all the pointers.

Help

Unix is notoriously poorly documented on the internet. Mainly becuase everything you need to know can be accessed via man
man a command - Access help for command.
man -k or apropos a string (search text) - When you know what you need but do not know what it is called.
Use space and arrows to navigate man. Press q when you done.
The OS manual can be accessed via info bash assuming the top bar of the terminal window says bash, which is the default.

FAQ

1. What is * for?
This is the wildcard character. Use it when you have given the computer enough information to figure out what you would type.
e.g.

cd ~/Pi* = cd ~/Pictures
rm ~/Pi*/* = rm ~/Pictures/ everthing in pictures.
rm ~/Pi*/a* = rm ~/Pictures/ everthing in pictures beginning with the letter a
rm ~/Pi*/a*b = rm ~/Pictures/ everthing in pictures beginning with the letter a and ending in b
rm ~/Pi*/*.jpeg = rm ~/Pictures/ every .jpeg in pictures

2. What is ./ for?
Some programs need you to use this to differentiate between other commands and the file youre modifying.

3. Error: You do not have sufficient privileges, access denied ?
Use man to lookup chmod and chgroup
chmod 777 file - your file can be accessed by everyone
chmod 755 file - your file can be acessed by you

4. I need to be an admin, but I am not under this account?
Use sudo at the begining of your command. Type admin password when prompted
Use login to change users in your terminal, but not MacOs.

5. What do I use if the man page says to use a | character?
The | character is referred to as the pipe character. It is used to pass parameters to the input of the command you are using.

No comments:

Post a Comment

try to make something then you never be lost

+++

Share |

"make something then You never be lost"

wibiya widget