What command lines do you use, and what are they for?

Posted:
in macOS edited January 2014
For those of us Mac users who aren't Unix gurus yet OS X is pretty but we're really only scratching the surface.



I was wondering what commands you old Unix vets know(and new users for that matter)in OSX.



Just a list of what the command is, and what you use it for.



for example, the only one i use with any frequency.



telnet



lets me log into a remote e-mail server. however, sends all my info as plain text and is a huge gaping security problem.



So let's get a thread of useful commands!



-alcimedes
«1

Comments

  • Reply 1 of 35
    eugeneeugene Posts: 8,254member
    awk cat chgrp chmod chown chsh crontab curl cut cvs defaults df diff du echo find grep gzip head kill less ln locate ls make man mkdir more mv ncftp niutil open passwd pbcopy pbpaste perl ps pwd renice rm sed sh ssh sort su sudo sum tail tar tcsh top touch umask uname uptime vi w wc whoami whois



    ...



    [ 07-06-2002: Message edited by: Eugene ]</p>
  • Reply 2 of 35
    graphitemangraphiteman Posts: 428member
    Eugene, you are so descriptive!



    I use a number of commands, but these are some of the more common ones I use:



    ls [-la] path: Displays the contents of the foklder passed. If you include the -la part, it will show hidden files too. This is useful if the finder is poky, you are mucking with hidden folders, or if you just performed a command line over or something.



    mv oldpath newpath: Moves or renames a file/folder. To rename, just pass the same path with the new filename on the end.



    rm [-rf] path: Removes a file, with the -rf part, removes folders as well without confirming anything. WARNING: THIS COMMAND, IF USED IMPROPERLY, CAN WIPE YOUR HARD DISK AND ANY ATTACHED DRIVES WITHOUT BLINKING AN EYE



    uptime: Displays how long your computer has been running.



    ssh ip address: establishes a secure connection to another computer.



    bill gates: you'll have to see for yourself. [be sure to include the space between bill and gates]
  • Reply 3 of 35
    cubedudecubedude Posts: 1,556member
    [quote]Originally posted by graphiteman:

    bill gates: you'll have to see for yourself. [be sure to include the space between bill and gates]
    <hr></blockquote>



    <img src="graemlins/lol.gif" border="0" alt="[Laughing]" /> <img src="graemlins/lol.gif" border="0" alt="[Laughing]" /> <img src="graemlins/lol.gif" border="0" alt="[Laughing]" />
  • Reply 4 of 35
    What Eugene said. Also, add to his list:



    cp - copy file

    cpmac - copy file w/ resource fork

    pico - text editor
  • Reply 5 of 35
    macgpmacgp Posts: 88member
    cat chgrp chmod chown defaults echo find grep gzip ls make man mkdir mv ncftp open passwd ps pwd renice rm sed sh ssh sort su sudo sum tail tar tcsh top touch uptime vi whoami whois mail fg pico
  • Reply 6 of 35
    sebseb Posts: 676member
    Here's a fun one:



    defaults write com.apple.terminal TerminalOpaqueness '0.50'



    It makes the terminal transparent. Change the value between the 'xxx' to set it. Open a new terminal window, change the colors in preferences, and voila you've got a customized terminal window to learn unix in (still learning here).
  • Reply 7 of 35
    alcimedesalcimedes Posts: 5,486member
    lol, that bill gates one is hilarious.



    for those of you with a mile long list, care to break out at least two or three for a real explanation?



    -alcimedes



    p.s. turns out if you type "bill" then anything else it asks if you want to kill it. wonder if that's just a coincedence.
  • Reply 8 of 35
    kaboomkaboom Posts: 286member
    I like to use my own aliases for stuff I use all the time.

    Just create a new file called 'aliases.mine' in /usr/share/init/tcsh/ and format it like so:

    [code]alias p 'pico'

    alias sp 'sudo pico' #sudo pico

    alias psa 'ps -acex' #list all processes

    alias cdl 'cd \\!*; l' #change directory and list

    alias b 'cd -' #go to previous directory

    alias ... '..;l' #go up one directory and list

    alias aliases 'grep "alias" /usr/share/init/tcsh/aliases.mine' #show my aliases</pre><hr></blockquote>

    The '#'s are comments. The space after the alias' name is a tab.

    I find that 'cdl' is probably my most common alias.

    Just type 'cdl nameOfDirectory' and it will change to that directory and list the contents all in one shot. That way you don't have to 'cd' to the directory then 'ls'.

    The 'sudo pico' is for when I edit my 'aliases.mine' file.

    Aliases are your friend.

    And I am a complete Unix n00b! I actually find the command line fun (now that I can type).
  • Reply 9 of 35
    ghost_user_nameghost_user_name Posts: 22,667member
    [quote]Originally posted by alcimedes:

    <strong>p.s. turns out if you type "bill" then anything else it asks if you want to kill it. wonder if that's just a coincedence.</strong><hr></blockquote>tcsh will search for a similar command if what you entered is not valid. In this case, "bill" is not a command and the closest match is "kill".
  • Reply 10 of 35
    kaboomkaboom Posts: 286member
    That Bill Gates joke is a result of the terminal trying to guess the closest command to what you typed. It's guessing that you misspelled a command and is suggesting what you might have meant.

    e.g. If you type 'cill' it will ask you "OK? kill?" or 'till' or 'gill' etc....



    Also, a great terminal feature is tab auto complete.

    If you hit the 'tab' key, the terminal will try and guess what you want next.

    For example:

    Let's say that you are in your "Home" directory. (cd ~) and you want to go to your "Documents" folder. If you type 'cd Do' and press the tab key, it will auto complete the word Documents. If there are more than one directory that start with "Do" then it will give you a list of other possible choices.

    This also works with commands. It's a great way to learn what commands exist in the terminal. Just type a letter and hit 'tab'. It will give you a list of all the commands that begin with that letter. Then just do a 'man commandName' to see what that command does.



    Ahhh, the Unixy goodness of OSX!
  • Reply 11 of 35
    ghost_user_nameghost_user_name Posts: 22,667member
    [quote]Originally posted by alcimedes:

    <strong>for those of you with a mile long list, care to break out at least two or three for a real explanation?</strong><hr></blockquote>Well, everything you need to know is in the man pages. Need info on the "grep" command? Simply enter "man grep" to read the grep manual.



    Here are a few I use from Eugene's list:



    awk - search data for and print pattern

    cat - concatenate or print a file

    chgrp - change group of a file

    chmod - change flags of a file

    chown - change owner of a file

    crontab - set crontab files

    curl - url downloader

    cvs - archive downloader, syncs local files with online files

    defaults - sets application and system preferences

    df - show free disk space

    diff - find differences between two files

    du - show disk usage

    echo - print text

    find - find files

    grep - search data for and print pattern

    gzip - gzip compression tool

    head - show first part of a file

    kill - quit a process

    less - display text

    ln - make symbolic link (similar to an alias)

    locate - find files using the system's locate database

    ls - list files in a directory

    make - run makefile for a project

    man - display man pages

    mkdir - make a new directory

    more - similar to less, but less is more

    mv - move a file

    ncftp - ftp program

    niutil - NetInfo configuration tool

    open - open a file

    passwd - change a password

    perl - execute perl commands

    ps - show process status, similar to top

    pwd - display current directory

    renice - change priority of a process

    rm - remove file or folder

    sh - a simple shell

    ssh - secure shell connection

    su - become another user

    sudo - execute command as another user

    sum - checksums a file

    tail - show last part of a file

    tar - tar archiver

    tcsh - the default shell in Mac OS X's terminal

    top - display system stats

    touch - touch a file

    uptime - display computer's uptime

    vi - text editor

    w - show current users

    whoami - show what user you are

    whois - use online directory to search names



    [ 07-06-2002: Message edited by: starfleetX ]</p>
  • Reply 12 of 35
    alcimedesalcimedes Posts: 5,486member
    *bump*



    came back looking for seb's terminal hack, thought some others might like to see it.
  • Reply 13 of 35
    pyr3pyr3 Posts: 946member
    A little trick to rename a file is to move it to the same location but with a different file name. For example:



    mv ./word.doc ./file.doc



    will rename word.doc to file.doc
  • Reply 14 of 35
    iq78iq78 Posts: 256member
    Unfortunately I have used: ln -s A LOT.



    It creates a symbolic link (alias) of a file. I say unfortunately, because if the aliases on OSX worked properly I shouldn't have to break into the command line.



    For example, I would like to make an alias of a preference file between two users. This is a requirement for Quicken2002, if you want two users to be able to open/use/save the same quicken file. Well, Quicken can't use the alias pointer requiring a symbolic link instead.



    BEFORE everyone jumps on me about how this is Intuit's problem (they have a lot of problems, I agree). I never had this problem in OS9 with any application. THey could use aliases as well as the actual file. So, I'm thinking able should have made the default alias a symbolic link instead of the crappy regular link that it currently uses.
  • Reply 15 of 35
    bluejekyllbluejekyll Posts: 103member
    [quote]Originally posted by IQ78:

    <strong>Unfortunately I have used: ln -s A LOT.



    It creates a symbolic link (alias) of a file. I say unfortunately, because if the aliases on OSX worked properly I shouldn't have to break into the command line.



    </strong><hr></blockquote>



    I know! what the hell is up with that? Is Apple trying to give an aneurysm?



    The only thing I figure is that the links are being created to be backwards compatable with OS 9, but I have OS X installed on UFS, so OS 9 wouldn't be able to use that anyway!



    Anyway, commands I use a lot:

    find - for finding a file, take a lot of options but i like doing this:

    find * -name *~ -exec rm {} \\;



    which finds all emacs backup files and deletes them.



    oh rm - removes a file (permanently), you shouldn't use -f unless it is necessary. Be careful what you do here. -f forces the file to be removed, even if you are not the owner (if you have the privaledge of doing so)



    emacs - greatest text editor ever made, vi sucks!



    commands you must know to get around:

    cd - change directories

    cp - copy a file to somewhere else

    mv - move a file somwhere

    ls - list a directory

    ll - shortcut to ls -al

    man - tells you everything you need to know about a command, or a C library function.



    there are many more...
  • Reply 16 of 35
    mrbilldatamrbilldata Posts: 489member
    man -k ' '







    Why doesn't "apropos" work <img src="confused.gif" border="0">



    [ 07-29-2002: Message edited by: MrBillData ]</p>
  • Reply 17 of 35
    nevynnevyn Posts: 360member
    ls -lart

    list the current directory including hidden files in reverse time-order.



    grep

    It's like what Sherlock may eventually reach as far as finding files/contents is concerned.



    netstat

    \tinformation about the available network connections. Zillions of options.



    ssh

    \tYou can think of it as 'just telnet', but it is substantially more secure. ssh is a strict superset of telnet.



    top

    The textual version of 'process monitor', with a heck of a lot more options.



    rm/mv/cp/cd the essentials.



    cat filename

    Spit the named file to the terminal window.



    more filename

    Spit the named file to the terminal window one screen at a time (space bar for next page, many, many other options).



    man man

    Starting place for a ridiculous amount of info.



    curl

    A better 'ftp' than ftp. Accepts URLs for one thing.



    man tcsh

    tcsh is the 'shell' that's actually the default running widget when you are typing in the terminal.app. There's a lot of stuff built straight into tcsh, or added to configuration files by Wilfredo Sanchez.
  • Reply 18 of 35
    rogue27rogue27 Posts: 607member
    ones I use often that a beginner can do with no problem:



    ls

    lists the items in the current directory.



    top

    shows processor and memory usage of running processes. press 'q' to turn it off.



    cd [directory name]

    change to the named directory. don't actually type the brackets.



    kill [process id]

    kill or quit a running process. you can run top to find the process id number "pid"



    I use many others, but I don't want to tell you anything dangerous and I don't want to list a bunch of commants with no explanations either, but since others did, I'll give you one last command you should like:



    man [command]

    this will bring up the manual page on how to use a specific command. so, for example, if somebody told you to use chmod for something, you could type "man chmod" and find out what chmod does and how to use it.
  • Reply 19 of 35
    cyko95cyko95 Posts: 391member
    Mainly, I use:



    "pico" for editing

    "ps -ax"for viewing all running processes

    "kill XXX" (X's are for what ever # the previous command shows the process ID as.) for killing processes.
  • Reply 20 of 35
    davegeedavegee Posts: 2,765member
    Don't forget our friend the pipe!



    ls -al (will do a 'directory listing')

    wc (will count things such as lines of text and number of characters)



    Now if you add a pipe you can do things like this:



    % ls -al | wc

    16 137 884



    The directory listing that would have been displayed was a total of 16 lines and those lines had total of 137 'words' (anything broken by a tab or a space) and the total number of bytes that made up the listing was 884.



    The pipe | can (and is) used ALOT and allows for some really cool things.



    Another cool symbol is &gt;



    % ls -al &gt; mydirectory



    Will take the directory listing that would have normally been output to the screen and instead redirect it to a file called mydirectory.



    You can then open that file in any text editor you like.



    One more cool symbol is &lt;



    %wc &lt; mydirectory



    The above command will PUSH the text found in that text file I just created in the last example INTO the unix app called wc (see above). The output from wc was displayed to the screen as usual.



    %wc &lt; mydirectory &gt; newfile



    In that last example the output from wc was NOT displayed to the screen but instead written to a file called newfile.



    While these examples are kinda lame they do show some of the really wild things you can do with unix.



    Dave



    [ 07-29-2002: Message edited by: DaveGee ]</p>
Sign In or Register to comment.