os x terminal unix commands

Discussion in 'Mac Basics and Help' started by theprizerevealed, May 24, 2016.

  1. theprizerevealed macrumors member

    Joined:
    Feb 26, 2016
    #1
    I forgot how to change directories when the directory name or file name is more than one word with a space between the words. For example, when I type "cd Pictures" then use the "ls" command to see the folders or files there is a directory My Pictures ( I know it's a directory because I used "ls -all" ) but when I try to use the command "cd My Pictures" then the return messages is "no such file or directory". What did I forget?
     
  2. boast macrumors 65816

    boast

    Joined:
    Nov 12, 2007
    Location:
    Phoenix
    #2
    Remember you can press tab for auto complete

    And you're looking for a backslash before the space

    My\ Pictures, or "My Pictures" with quotes.
     
  3. satcomer macrumors 603

    satcomer

    Joined:
    Feb 19, 2008
    Location:
    The Finger Lakes Region
    #3
    To change connection settings via Terminal use networksetup instead of the older ifo. Just do a man on networksetup.

    If you are unsure on how to get to a folder just drag the folder to the Terminal window and release and then the path to that folder! This way you can see how to make a manual path!
     
  4. theprizerevealed thread starter macrumors member

    Joined:
    Feb 26, 2016
    #4
    well, let's say you wanted to go to that directory directly without using the 'cd' command to switch directories one by one. I tried the command 'cd \Pictures\My\ Pictures' but it didn't work
    --- Post Merged, Jun 13, 2016 ---
    never mind I see it's 'cd ~/Pictures/My\ Pictures'
     
  5. mfram macrumors 65816

    Joined:
    Jan 23, 2010
    Location:
    San Diego, CA USA
    #5
    It would be one of the following:
    Code:
    cd Pictures/My\ Pictures
    cd "Pictures/My Pictures"
    
    Forward slash ('/') is the directory separator. Normally in Unix shells, spaces are used to separate arguments. So if you want to add a space to an argument you must add the escape character ('\') before the space. That's why the backslash is there.
     
  6. theprizerevealed thread starter macrumors member

    Joined:
    Feb 26, 2016
    #6
    thank you, another question is how does this usage relate to a filename that includes a parenthesis such as '(' or ')' ??? I have tried to use the backslash in a filename to determine some characteristics of the filename but the shell tells me that there is an unrecognized token near the (. However it did not seem to have any problem with the '-' character.

    Thanks for your assistance.
     
  7. mfram macrumors 65816

    Joined:
    Jan 23, 2010
    Location:
    San Diego, CA USA
    #7
    Yes, the parenthesis is a special character. As ar braces {} and brackets []. Normally you shouldn't have to worry since TAB-completion will help you out. As you type commands, put in the first couple of characters of a file and press TAB. The shell will complete the rest of the filename as best it can. If the filename includes special characters, the shell will automatically insert the escape characters.

    Brace and bracket usage shows below:

    Code:
    host:~$ ls pic*
    pic1.jpg  pic2.jpg  pic3.jpg  pic4.jpg  pic5.jpg
    host:~$ ls pic[123].jpg
    pic1.jpg  pic2.jpg  pic3.jpg
    host:~$ ls pic{2,4}.jpg
    pic2.jpg  pic4.jpg
    host:~$ mv pic{2,7}.jpg
    host:~$ ls pic*  
    pic1.jpg  pic3.jpg  pic4.jpg  pic5.jpg  pic7.jpg
    host:~$ mv pic{7,2}.jpg
    host:~$ ls pic*  
    pic1.jpg  pic2.jpg  pic3.jpg  pic4.jpg  pic5.jpg
    
     
  8. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #8
    When you ask a question about a command line, please provide the exact command-line used, and the exact text of any error messages. You can select text in a Terminal window, then copy it to the clipboard and paste it into a post. It's difficult to guess exactly what you may have typed when all you provide is a vague description.

    If you want to see what you should type for any pathname, you can use the 'echo' command, then a space, then drag and drop the desired file from the Finder onto the Terminal window. The full path will then be automatically typed in, with the necessary \'s in the required places.

    The 'echo' command simply echoes its args, but it does so after the \'s and quotes have been removed, wildcards expanded, etc. So you can simply press RETURN at that point to see what the actual filename will be.

    The process of using filenames with special characters for the shell is called "quoting". There's a whole section on it in the 'bash' man page:
    https://developer.apple.com/legacy/library/documentation/Darwin/Reference/ManPages/man1/bash.1.html

    The heading for the section is QUOTING, which you can search for on that man page.
     

Share This Page