Skip navigation
This discussion is archived

how use terminal to access a folder on desktop

13810 Views 8 Replies Latest reply: Dec 14, 2010 10:14 AM by rccharles RSS
J-e-L-L-o Level 1 Level 1 (25 points)
Currently Being Moderated
Dec 12, 2010 3:08 PM
I have a question. I am learning c++ programming and I want to use terminal to start off with. I was saving my source code on the desktop. I got them up and running thru terminal by cd desktop to choose it.

but now to make it simpler and cleaner i want to put these files in a seperate folder. If my folder is called C++ source code that is on my desktop... what do I type in terminal to use that for compiling my code.

thanx
13in 2.4Ghz macbook pro, Mac OS X (10.6.5), 4GB
  • Matt Clifton Level 7 Level 7 (26,975 points)
    Currently Being Moderated
    Dec 12, 2010 3:19 PM (in response to J-e-L-L-o)
    If the folder has spaces, such as "C++ source code", you can either surround the folder with quotes as I just did, eg

    cd "C++ source code"

    or you can escape the spaces, eg

    cd C++\ source\ folder

    Don't forget, too, that you can usually hit the tab key to autocomplete a path in Terminal.

    PS - I would generally advise against using punctuation in folder names, such as "C++", just to avoid incompatibilities and code confusion.

    Matt
    MacBook Pro (13" Mid 2010), Mac Pro (Early 2008), iPhone 3G, Mac OS X (10.6.5)
  • MrHoffman Level 6 Level 6 (11,745 points)
    Currently Being Moderated
    Dec 12, 2010 8:35 PM (in response to J-e-L-L-o)
    The backslash is an escape character for the shell; it allows you to get spaces into the path, for instance. (Windows uses  as a directory separator. Mac OS X and other Unix and Linux systems uses the / for that purpose. There are other differences in file specification syntax between Windows and other platforms, as well.)

    If you have a subdirectory of your login directory named Code, then the path in Terminal is


    cd ~/Code


    That tilde is shorthand for your login directory, and the longer version of that path is usually something like this:


    cd /Users/your-short-name-here/Code


    Here's a longer command sequence, moving first to your login directory, then a relative path into the Code subdirectory:

    cd ~
    cd Code


    Had you had a space in that directory with, say, My Code, then you'd have one of the following:


    cd ~/My Code
    cd /Users/your-short-name-here/My Code


    Since you're planning to do some programming, here is a [file system overview|http://developer.apple.com/library/mac/#documentation/MacOSX/Conceptua l/BPFileSystem/Articles/Domains.html] from the Apple developer documentation. This document describes various concepts and constructs, as well as the directories that should be used for various purposes.
  • Camelot Level 8 Level 8 (45,680 points)
    Currently Being Moderated
    Dec 12, 2010 10:27 PM (in response to J-e-L-L-o)
    seems as if the name "code" and "source code" won't work in terminal for folder names


    Then you're doing something wrong. There's nothing special about the name 'code'.

    cd code didn't work


    'cd code' would change to the 'code' directory relative to your current location. In other words, if you open Terminal and start in your home directory (e.g /Users/yourname/) then this will change to the 'code' directory in your home directory (e.g. /Users/yourname/code/)

    From your earlier posts it seems that your code directory is on your Desktop, not in your home directory, and therefore cd code would not work (unless you were already in your Desktop.

    So your options are:

    1: cd to your Desktop, then cd to code:

    $ cd Desktop
    $ cd code


    2: include the Desktop path element in your cd statement:

    $ cd Desktop/code


    3: specify a full pathname (with a leading /) to the directory you want to change to:

    $ cd /Users/yourname/Desktop/code


    or other variations on the theme. Understanding the working directory and relative paths is going to be a critical step in your learning process.
    Mac OS X (10.6.5)
  • rccharles Level 5 Level 5 (5,155 points)
    Currently Being Moderated
    Dec 13, 2010 11:07 AM (in response to J-e-L-L-o)
    To see what directory you are in, use the pwd command.



    Here is an overview of the terminal commands. Lets assume that your account has a short user name of mac.
    Macintosh-HD -> Applications -> Utilities -> Terminal
    #What is my short user name? Type the whoami command.
    mac $ whoami
    mac
    mac $ 

    #How to list all of your disks.
    # The ls command is for list
    mac $ ls /Volumes/
    Audio CD       Macintosh-HD   Spotless       Tiger-ext
    mac $ 
     

    # Let's say your flash drive is named Spotless

    # cd is change directory
    mac $ cd /Volumes/Spotless
    # pwd is print working directory
    mac $ pwd
    /Volumes/Spotless
    mac $ 
     



    # The ls command is for list
    # l is long
    # F is type of file where / is directory
    mac $ ls -lF
    total 134704
    -rw-r--r--     1 mac  staff     64560 Mar  3  2009 A-picture-of-Youpi-key.png
    drwxr-xr-x    83 mac  staff      2822 Nov  7 14:52 Applescript files/
    drwxrwxrwx    12 mac  staff       408 Dec 13  2008 Christmas Cards/
    drwxr-xr-x     9 mac  staff       306 Dec 21 17:39 Christmas Cards 2009/
    ... trimmed ...


    What does all this mean?
     
    drwxrwxrwx
     
    d = directory
    r = read
    w = write
    x = executeable program
     
    drwxrwxrwx
     |  |  |
     |  |   all other users not in first two types
     |  |  
     |  group
     |  
     owner
     



    # l is long
    # a is all to show hidden files & folders
    mac $ ls -lFa
    total 134736
    drwxr-xr-x    41 mac   staff      1496 Dec 22 17:11 .
    drwxrwxrwt     8 root  admin       272 Dec 24 13:55 ..
    -rwxrwxrwx     1 mac   staff     15364 Dec 23 12:52 .DS_Store*
    drwx------     4 mac   staff       136 Jan 22  2009 .Spotlight-V100
    drwxrwxrwt     5 mac   staff       170 Sep 14 16:36 .TemporaryItems
    d-wx-wx-wx     4 mac   staff       136 Dec 31  1969 .Trashes
    -rw-r--r--     1 mac  staff     64560 Mar  3  2009 A-picture-of-Youpi-key.png
    drwxr-xr-x    83 mac   staff      2822 Nov  7 14:52 Applescript files
    drwxrwxrwx    12 mac   staff       408 Dec 13  2008 Christmas Cards
    drwxr-xr-x     9 mac   staff       306 Dec 21 17:39 Christmas Cards 2009

    ... trimmed ...



    # mv is move or rename
    mv -i the-name the-new-name

    # You can just rename the file back to what it was with mv command.
    mv -i old-name new-name

    Here is what these commands mean:
    cd is change directory
    pwd is a print working directory
    ls is list
    sudo is Super user do
    mv is move or rename

    For cryptic comments, you can always uses the manual command which is man. For example:
    man mv

    # Type the letter q to quit.

    In case you have spaces in your filenames or directories, you need to escape them. See examples:

    mac $ ls -l ~/"see it"
    -rw-r--r-- 1 mac staff 3171 Oct 26 23:38 /Users/mac/see it
    mac $
    mac $ cd /Users/mac/Desktop/ttt\ html\ copy/

    Do you know about tabing? Type in a few letters of a name then press the tab key. The computer will type out the rest of the name if it is unique.

    Press the up arrow(s) key to see the previous command(s).

    history to see many previous commands.

    mac $ history
        2  man launchd.conf
        3  history



    Robert
    iMac G3 600, Mac OS X (10.4.11)
  • rccharles Level 5 Level 5 (5,155 points)
    Currently Being Moderated
    Dec 14, 2010 10:14 AM (in response to J-e-L-L-o)
    Good to solve that mystery.

    Robert
    iMac G3 600, Mac OS X (10.4.11)

Actions

More Like This

  • Retrieving data ...

Bookmarked By (0)

Legend

  • This solved my question - 10 points
  • This helped me - 5 points
This site contains user submitted content, comments and opinions and is for informational purposes only. Apple disclaims any and all liability for the acts, omissions and conduct of any third parties in connection with or related to your use of the site. All postings and use of the content on this site are subject to the Apple Support Communities Terms of Use.