Terminal commands aren't working as expected

Discussion in 'Mac OS X Lion (10.7)' started by uberaffe, Nov 24, 2011.

  1. uberaffe, Nov 24, 2011
    Last edited: Nov 24, 2011

    uberaffe macrumors newbie

    Joined:
    Nov 24, 2011
    #1
    Hi there, I'm a long time Windows, Unix and Linux user and have recently been swayed into Mac conversion of my main personal computing environment for home use.

    As most would expect I'm struggling with the difference in thinking in many of the conventions Mac OS X uses compared to my well trained muscle memory of Windows and X, but I continue to push on.

    I am finding myself dropping to a terminal window to complete some routine tasks that I can do much more quickly than figure out OS X way of handling, but I'm finding several strange behaviors that I am hoping folks better versed in this BSD clone Darwin that's underpinning OS X can explain.

    1. Why can't I use the gui text editor to open certain system files? e.g. /etc/hosts - (ANSWERED - Apple has explicitly limited this - I'm a little worried about this recent answer I found. Without consistency of execution it becomes pretty hard to trust the OS you're working with...)

    2. cp command - this is and my next question are so simple I fear the wrath I may get from them, but please be patient - trying a basic copy of files in the same directory but changing their extension at the same time. e.g. I've shrunk several audio files (.m4a) into ringtone length and want to rename the files to .m4r. I would normally use the command 'ren' in DOS to a do a single file or move but a 'copy' is less volitile if I mess up the syntax at least I don't lose my source files. Syntax I would use in Unix/Linux and that I've been trying to make work in Darwin under OS X 10.7.2 is 'cp *Ringtone*.m4v *.m4r' - but it just gives me the usage of the command. I've tried moving all of the files I want to rename into a new directory through the GUI and from terminal in the new directory run the following 'cp *.m4a *.m4r', but I get the same results - nothing happens except I get a response indicating the syntax of the command is:
    usage: cp [-R [-H | -L | -P]] [-fi | -n] [-apvX] source_file target_file
    cp [-R [-H | -L | -P]] [-fi | -n] [-apvX] source_file ... target_directory

    I've checked the man page to see if it was a "special" version of cp, but don't see anything that should preclude this from working.

    3. same as #2 but with 'mv' instead of 'cp' - I must be doing something wrong...I just can't see it yet. Any help would be appreciated.

    4. And this is what has prompted me to finally post something. In exasperation of my problems above I was typing good 'ol 'ls - l' alot - those who use RedHat probably know the builtin alias of 'll" and use it regularly - obviously Darwin doesn't have that alias so I went to create it - no dice, running 'alias' with no parameters just returns a prompt with no error message. the command 'alias ls 'ls - l' ' returns the following:
    -bash: alias: ls: not found
    -bash: alias: ls -l: not found

    What the heck is that? the man page indicates that alias is there and is a builtin command (as I would expect) but I can't run it? I've even gone so far as to log in as root and tried it with the same results - I'm *really* hoping some Mac experts can hit me with a, "Silly Rabbit, just turn on xxxx feature and all your terminal command woes will cease..."

    Thanks in advance for any assistance the more knowledgeable might be able to provide....
     
  2. Franciturci macrumors member

    Joined:
    Oct 7, 2009
    #2
    For point 1. What do you mean by the fact that you can't edit /etc/host with a gui text editor? I have TextMate on my Mac and the command
    Code:
    mate /etc/hosts
    works with no problem.


    For point 2. and 3. I think this is the normal behaviour for any Unix machine , both for cp and mv, see here http://staff.washington.edu/dittrich/misc/faqs/unix.rename.wildcard, probably you're used to DOS. In order to do what you want, just write a small bash script with a for loop and make it visible from your path.

    The point 4 is indeed surprising. On my machine, which has your same configuration,
    Code:
    ls -l
    works perfectly. May you check that the output of
    Code:
    which ls
    is /bin/ls ?

    EDIT: maybe I've got your problem: the syntax for aliases under unix is
    alias ll='ls -l'
     
  3. calderone macrumors 68040

    calderone

    Joined:
    Aug 28, 2009
    Location:
    Seattle
    #3
    To comment on GUI editing, Apple hasn't limited anything. Files such as /etc/hosts are protected from editing with permissions (as they should be). The reason it works with TextMate is because they added in the ability to elevate permissions for file editing.

    Some apps have it and some don't. If you pick the right app, you can edit in the GUI.

    ls -l is working for the OP, just not the creation of an alias.

    OP that is because your syntax is wrong.

    Code:
    alias ll="ls -l"
    This isn't a Mac specific usage either, it is pretty universal.
     

Share This Page