|
#1
| ||||
| ||||
| HOW-TO: UNIX basics for newbies OK, here is a small "how to" for knowing how to do a few basic things in UNIX (specifically the terminal in OS X). Now when you open you your terminal you probably see something like: Welcome to Darwin! [hostname:~] your_username% --> for the purposes of this HOW to we will use this: Welcome to Darwin! [admiralty:~] admiral% <-- Now you might wonder how to so stuff in the terminal. This is where the HOW-TO comes in handy. (NOTE: I will do one command per post ) Lets start off with a command that lets you see what exaclty you have in teh directory you are in! This command is the ls command. The ls command could be thought of as "list" (list what's here). Doing the ls gives you something like this: Code: [admiralty:~] admiral% ls Desktop Library Music Public admiralty Documents Movies Pictures Sites [admiralty:~] admiral% What is in sylver color are the contents of where I am now (which happens to be my home directory). ------ There are special "flags" that go along with the LS command which "format" the output. Three useful ones are the following: Code: [admiralty:~] admiral% ls -a . .FBCIndex Documents Pictures .. .FBCLockFolder Library Public .CFUserTextEncoding .Trash Movies Sites .DS_Store Desktop Music admiralty [admiralty:~] admiral% ----- There also exists the -l command which "lists" everything in a row. Lets examine it: Code: [admiralty:~] admiral% ls -l total 0 drwx------ 4 admiral staff 264 Oct 4 19:29 Desktop drwx------ 5 admiral staff 264 Oct 4 19:29 Documents drwx------ 22 admiral staff 704 Oct 7 15:10 Library drwx------ 2 admiral staff 264 Oct 4 19:30 Movies drwx------ 2 admiral staff 264 Oct 4 19:30 Music drwx------ 2 admiral staff 264 Oct 4 19:30 Pictures drwxr-xr-x 3 admiral staff 264 Aug 21 13:34 Public drwxr-xr-x 4 admiral staff 264 Aug 21 13:34 Sites drwxr-xr-x 9 admiral staff 264 Oct 4 19:47 admiralty [admiralty:~] admiral% --> continues bellow
__________________ <<------------------------------>> Seid ihr bereit fuer Club Admiralty ???? Club Admiralty: Http://www.club-admiralty.com Copyright 1996-present Bonified Gadget Geek :-) <<------------------------------>> |
|
#2
| ||||
| ||||
| The first column of the above tells you what the "permissions" are. d = directory r = read w = write x = execute now this is how to read drwxrwxrwx file type owner (you) permissions group perms other perms d rwx rwx rwx Lets say I am another guy (I fall under others) and I have r-x this means that I only have read and execute permiossions. If I have --- means that I have no permissions. So whenever someone doesnt have a permiossion to do something the "-" appears where that permission would exist. The 3rd column: Indicates the user who created that document The 4th column: Indicates that user's group The 6th, 7th and 8th columns indicate the date and time that file was last modified and the 9th column indicates the file name OK! Information overload, right ? well, this was a brief explantation, we'll take it easy from now on, I promise ![]() ---- Now the last LS flag for this HOW-TO, the -F flag Code: [admiralty:~] admiral% ls -F Desktop/ Library/ Music/ Public/ admiralty/ Documents/ Movies/ Pictures/ Sites/ [admiralty:~] admiral% Now you know what is in your directory and to somewhat decipher what it is.
__________________ <<------------------------------>> Seid ihr bereit fuer Club Admiralty ???? Club Admiralty: Http://www.club-admiralty.com Copyright 1996-present Bonified Gadget Geek :-) <<------------------------------>> |
|
#3
| ||||
| ||||
| Cool! Now how do I change folder ? well... so you want to change to another folder eh ? The good thing is that it is simple! there is only one command, cd . Now. lets say we are in the same directory as above, and we want to go into Documents/ ... what do we do ? we do the command cd documents...and pouf! we're there! here is what it looks like: Code: [admiralty:~] admiral% cd Documents [admiralty:~/Documents] admiral% ls (No I am not canadian )--- Now lets say I wanna go back... it's also simple! All you have to do is type cd .. (cd space dot dot) Code: [admiralty:~/Documents] admiral% cd .. [admiralty:~] admiral% ---- Now finally... lets say you want to go back to your home directory, but you are God knows where in your computer and dont know exactly WHERE your home directory is. Lets say you are in: Code: admiralty:some_folder/some_Other_Folder/Some_smaller_folder/ at the prompt just type cd and hit return. You will be back in your home directory ![]()
__________________ <<------------------------------>> Seid ihr bereit fuer Club Admiralty ???? Club Admiralty: Http://www.club-admiralty.com Copyright 1996-present Bonified Gadget Geek :-) <<------------------------------>> |
|
#4
| ||||
| ||||
| How do I make a folder ? How do I delete something ? OK, ready to move one step further ? cool! now to make a folder...its quite simple! We use to mkdir command. The format is this mkdir desired_name so if we want to make a folder called "job" we do this at the prompt: mkdir job and hit return Code: [admiralty:~/pictures] admiral% mkdir job [admiralty:~/pictures] admiral% ls job [admiralty:~/pictures] admiral% ----- So..now how about deleting a few things ? We do this with the rm command. To delete a single file you do this Code: [admiralty:~/pictures] admiral% ls job text.txt [admiralty:~/pictures] admiral% rm text.txt [admiralty:~/pictures] admiral% ls job [admiralty:~/pictures] admiral% I did an LS to see what I had in my folder. I had the folder named "job" and a text file called "text.txt". I did the rm command followed by the file name I wanted to delete. I hit return. The I did another LS to verify that I deleted it. ----- To remove a directory you use the rm command with the flag -r (r stands for recursive but we wont get into that now) here is what we have then: Code: [admiralty:~/pictures] admiral% ls job [admiralty:~/pictures] admiral% rm -r job [admiralty:~/pictures] admiral% ls [admiralty:~/pictures] admiral% I did an LS to see what I had in my folder, I had a folder called "job" I did the command rm -r with the folder I wanted to delete (rm -r job) and to check that it was deleted, I did an LS. And that is how you delete! ![]()
__________________ <<------------------------------>> Seid ihr bereit fuer Club Admiralty ???? Club Admiralty: Http://www.club-admiralty.com Copyright 1996-present Bonified Gadget Geek :-) <<------------------------------>> |
|
#5
| ||||
| ||||
| How do I rename something ? How do I copy ? Ahhh renaming. For that we use the mv command ("move" command). It is done like this: mv old_name new_name The old_name is the file you have, the new_name is the name you want to give it. lets take a look at an example: Code: [admiralty:~/pictures] admiral% mkdir jow [admiralty:~/pictures] admiral% ls jow [admiralty:~/pictures] admiral% mv jow joe [admiralty:~/pictures] admiral% ls joe [admiralty:~/pictures] admiral% I made a directory called "jow" ... of course I made a typo! To correct this is a simple matter with the MV command. I just do mv jow (the file I made) joe (the new name I want to give it). To make sure I did what I wanted it to do, I did an LS command, and I see that it worked! --- How do you copy something ? Simple! Use the command called cp (for CoPy). The syntax of this command is similar to the MV command cp source destination where source is the source file, and destination is the destination file. Lets say I want to duplicate my "AK" text file so that I have "AK" and "AK1": Code: [admiralty:~/pictures] admiral% ls AK joe [admiralty:~/pictures] admiral% cp AK AK1 [admiralty:~/pictures] admiral% ls AK AK1 joe [admiralty:~/pictures] admiral% I did an LS to see what I had, and I DID have the AK file, did the CP command as cp AK AK1 , where AK was my original file and AK1 is my duplicate "cloned" file. Then I did an LS to double check and actually see that I did what I wanted to do And that ladies and gents is how you copy and rename ![]()
__________________ <<------------------------------>> Seid ihr bereit fuer Club Admiralty ???? Club Admiralty: Http://www.club-admiralty.com Copyright 1996-present Bonified Gadget Geek :-) <<------------------------------>> |
|
#6
| ||||
| ||||
| Finally 2 last commands : the pwd ( Print Working Directory) and the date commands. pwd is nice if you dont know where you are. Lets say you have been toying around with UNIX for some time now and you have gone to a directory but dont know where exaclty it is! pwd fixes this by outputting where you are. Lets say I want to find where exaclty my home directory is, Code: [admiralty:~] admiral% pwd /Users/admiral [admiralty:~] admiral% )And finally the date command. It tells you the date, time, day and year , useful if you want to know the time and date ![]() sample: Code: [admiralty:~] admiral% date Sun Oct 7 16:51:31 EDT 2001 [admiralty:~] admiral% Well, these are the most basic UNIX commands that one needs to survive ![]() Admiral
__________________ <<------------------------------>> Seid ihr bereit fuer Club Admiralty ???? Club Admiralty: Http://www.club-admiralty.com Copyright 1996-present Bonified Gadget Geek :-) <<------------------------------>> |
|
#7
| |||
| |||
| Nice work - now what if i would like to copy all the files in a directory to another directory - say the contents of /users/freestlyer/documents to /users/freestlyer/archive/documents both paths exist. now, say that the contents of the archive/documents folder are a mix of .doc file and .xls files - and ive just made two sub directories within /archive/documents being /users/freestlyer/archive/documents/xls /users/freestlyer/archive/documents/doc -In Dos I might put my pointer at /user/freestlyer and go: move c:\users\freestlyer\documents\*.* /users/freestlyer/archive/documents/*.* or selectively sort from there with c:\users\freestlyer\documents\*.doc <and so on and so forth> got any tips? Cheers FreeStyler |
|
#8
| |||
| |||
| I realize this is an old thread, but I'll post something since I've seen the question of how to move directories and/or multiple files a couple of times. To copy an entire directory tree, you can use the -R switch. For example: % cp -R documents/ new_location/ OR % cp -Rp documents/ new_location/ The first one will copy the directory and all sub-directories. The second one will attempt to preserve as many file attributes as it can (ownership, permissions, etc.) To copy a number of files, you can use wildcards (similar to DOS, not the same). % cp documents/*.doc new_location/ I didn't put the -R this time, since I'm assuming that *.doc will only match files. You can specify more than one source as well: % cp documents/*.doc documents/*.xls new_location/ This will copy all the .doc and .xls files (and nothing else) into the directory new_location. NOTE: if the destination is not a directory and only one source is listed, it will copy the file to a new filename. For example, to make a backup of a file: % cp something.doc something-backup.doc Hope that helps... (use the 'man' command to get more info on anything here!) |
![]() |
| Thread Tools | |
|
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| [FAQ] - Setting the UNIX shell prompt | michaelsanford | HOWTO & FAQs | 4 | March 27th, 2003 01:25 PM |
| is osx a true unix system | Click | Mac OS X System & Mac Software | 115 | May 6th, 2002 01:43 AM |
| UNIX basics? | iceyg | Mac OS X System & Mac Software | 3 | February 22nd, 2002 01:15 PM |
| Unix basics | b4tn | Mac OS X System & Mac Software | 2 | January 15th, 2002 04:56 PM |