Terminal in OS X

Discussion in 'Mac Help/Tips' started by cb911, May 18, 2002.

  1. cb911 macrumors 601


    Mar 12, 2002
    BrisVegas, Australia
    the other day i just found out about typing 'uptime' in Terminal to see how long your systems been running. i was wondering if there were any other things you can type for statistics and interesting stuff? and is there much chance of ruining anything if i type something wrong?
  2. edesignuk Moderator emeritus


    Mar 25, 2002
    London, England
    Re: Terminal in OS X

    As long as your not logged in to the terminal as 'root' you shouldn't be able to do any real damage.
  3. mac15 macrumors 68040

    Dec 29, 2001
    there is a huge amount you can do in the terminal
    but I don't bother with it......I like aqua better:D and I don't know squat about unix
  4. arn macrumors god


    Staff Member

    Apr 9, 2001
    Re: Terminal in OS X

    you can do a lot in terminal... and you can screw things up... since you can delete and change file permisions...

    if you are "root", then you can do even more damage.

    first rule is to never type in anything that you don't know what it does...

  5. mmmdreg macrumors 65816


    Apr 14, 2002
    Sydney, Australia
    type top or top -u for a list of processes and cpu usage and memory and all that stuff..
  6. cb911 thread starter macrumors 601


    Mar 12, 2002
    BrisVegas, Australia
    thanks mmmdreg. wow, it worked! ok, so i won't mess around in terminal. does anyone know any other useful commands or things for terminal?
  7. cb911 thread starter macrumors 601


    Mar 12, 2002
    BrisVegas, Australia
    wow cool! i just sat down and had a look at terminal after i typed top.
    all down the left hand side, on the second column it has a list of commands. are these other commands you can type?

    i was also wondering if there is any webstite i could go to so i can find out more about terminal, and what all those numbers and stuff mean?
  8. sparkleytone macrumors 68020


    Oct 28, 2001
    Greensboro, NC
    Mac OS X Unleashed is a good read if you are interested in the UNIX side of OS X
  9. mc68k macrumors 68000


    Apr 16, 2002
    I agree. This is currently the best offering for learning the Unix side of the OS. It gets as nerdy as you want it to go.

    cb911, I would start off by learning something simple, then working up to the process id's and such you were describing. Start out by navigating the filesystem or something. Most any basic Unix commands from any *nix will translate into BSD, so just start reading something. It really is fun.
  10. cb911 thread starter macrumors 601


    Mar 12, 2002
    BrisVegas, Australia
    ok so i'll start off simple. and i should read stuff? does anyone know a good website where i could learn the basics?
  11. mmmdreg macrumors 65816


    Apr 14, 2002
    Sydney, Australia
    These aren't commands for typing...they're currently running processes...
  12. Beej macrumors 68020


    Jan 6, 2002
    Buffy's bedroom
    www.macosx.org has some good newbie tutorials. They also have some pretty advanced stuff.


    I used to be able to type 'tcpdump' and see all the Internet action on my machine. When I type it now, I'm told there is no suitable device found. Does anyone know what the deal is?
  13. j763 macrumors 6502a

    Nov 25, 2001
    Champaign, IL, USA
    Also O'Reilly Network's Mac Site has some good terminal information. Don't be frightened of the terminal, just think before you type... It's not like DOS, if you type something in and hit return, there's no "Are you sure?" -- if you type it, Terminal will do it. Don't expect a warning. It's certaintly not necessary for Mac OS X users to use the terminal at all - you can just stick to the gui, but it's a valuable skill to have and allows you to try out a wider range of software.

    beej, the standard OS X admin user doesn't have permission to run tcpdump. Try typing in sudo tcpdump.
  14. evildead macrumors 65816


    Jun 18, 2001
    WestCost, USA
    Here are a few UNIX commands. I made this a long time ago while I was learing UNIX for the first time. This was my cheet sheet of notes for when i forgot some commands. Not all of the will work for OS X (some or system V commands) but it will get you started. As the other guys said... you can mess things up pretty bad using the terminal... so dont do it unless your prepared for it. And dont do it as root... unless you think you can handle it.


    #man <command> - gives you full manual of a command

    # df -k - lists mountted drives and partitions. gives space uesed/avalable

    # su <userName> swithch to a new user ( use "-" for root user)

    # sudo <command> run a command as root, if user has sudo privleges

    # rm = removes file
    rm [file name]
    rm -r [file name] = removes sub tree
    rm –r* = removes all files under current directory
    rm –fr [file name] = removes full directory

    # cp = copy file
    cp [file name1] [file name2]

    # pwd = displays current directory

    # mkdir [directory name] = makes directory

    # ls = lists directories/ files
    -a = lists all
    -c = lists in columns
    -l = long list
    # df = displays number of free blocks and files
    -b = kb free
    -k = prints allocation

    # cd = change directory
    # cd .. = change to parent directory

    # rmdir [directory Name] = removes directory (empty)

    # mv [file name1] [file name2] if file 2 exists file1 will be moved to. If not, rename

    # who = who is logged in to server

    # finger [user name] = info about user

    # tty = displays name of terminal

    # uptime = displays how long the server has bee up and # of users

    # s = save

    # man = online manual
    # man [command name] = info on a command

    # w [user name] = displays what user is doing

    [command] > [file name] = puts output of command to a file

    [command] >> [file name] = appends output of a command to a file

    [command] < [file name] = using a file as input to a command

    # cat [file name] = filter that puts contents of a file to the screen
    cat –n = w/ line numbers
    cat –b = blank
    cat –s = squeeze: cuts double blank lines
    cat –c
    • [file name] = cuts data and displays it to screen
      list = -8 or –8-10 or –13-30

      # colrm [start column] [end column] = deletes columns of data

      # sort = sorting
      -d = (dictionary) – consists only of letters/ numbers/ spaces
      -f = (fold) – treats upper case as lower case
      -r = (reverse)

      # spell –b [file name] = displays miss spelled words

      # wc [file name] = word count

      # head [file name] = displays first 10 lines
      head [-count] [file name] = displays first “count” lines

      # tail [file name] = displays last 10 lines
      tail [-count] [file name] = last “count” lines
      tail [+count] [file name] = displays line “count” down to EOF

      # more [file name] = displays one page of a file at a time
      -s = squeeze

      # pg [file name] = displays one page at a time

      # lp [file name] = prints file

      # chmod = change file permissions

      chmod [mode] [file name] (page 621)
      chmod [ugoa][+-][rwx]

      + = give
      - = take
      w = write permission
      r = read permission
      x = execute permission
      u = Applies to user
      g = Applies to group
      o = Applies to other (world)
      a = Applies to all

      # ln [file name] [new link name] = creating a new link

      # [command] & = runs program in background

      # ^z = suspend a program

      # fg = (foreground) – brings suspended program to front

      # bg = (background) – move current job to background.

      Notifying local and remote users
      # wall
      # rwall [mars] [Pluto] [Orion]
      the system…..
      Press Control-d

      Shutdown/ Boot Command
      # shutdown
      -y = continue shutdown, no intervention
      -g = time, in seconds, till shutdown
      -i = bring the system to a different run level
      [-i run_level] (0,1,S, 6)
      # init 0
      # init 6 = reboot
      # reboot
      # boot
      -r = reconfigure (find devices)
      -rv = verbose (long list dump)

      Identify system Disks
      Ok probel-scsi, probe-scsi-all, or probe-ipi

      Interrupting the system
      -do only if system hangs and remote log fails
      Do a Stop-a
      (at ok, sync)

      Identifying disk devices
      # dmesg

      # partconf = displays systems config information, memory and peripherals

      Volume Manager
      # volcheck = looks for volumes
      # eject floppy
      # eject cdrom

      # ufsdump [options] [arguments] [files_to_dump]

      0-9 -Specify the dump level. Level 0, lowest (full dump). Level 9 is highest
      a -Create an on-line archive of the file names dumped to tape
      f -Specify the device to which the files are written – requires and argument
      of device name.
      u -Update the dump record (/etc/dumpdates
      c -Set the blocking factor to 126 for all tape devices

      Can be raw or block file-system device names (/dev/(r)disk/c0t0d0s0)
      … The file-system name (/export/home)
      … A file for directory name (/export/home/lister)

      # usfdump 0ufc /dev/rmt/0 /export/home
      -when default tape device (/dev/rmt/0) is used, not necessary to use option
      do: # usfdump 0ufc /export/home

      # ufsrestore [option] [arguments] [file_name]

      i -Perform interactive restore
      r -Restore the entire backup
      t -List the table of contents of the backup
      x -Restore only the files named on the command line
      a[archive_file] -Take the table of contents info from the archive_file rather than the tape
      f[dump_file] -Use dump_file instead of /dev/rmt/0 as the file to restore from
      v -Display path names as they are being restored

      Using the command
      1. Insert tape
      2. Become supper user
      3. display & verify right tape
      # ufsrestore tuf /dev/rmt/0
      4. Once verified, extract the individual file you want to restore
      # cd /var/temp
      # ufsrestore xvf /dev/rmt/0 ./etc/password

      Using the command #2
      1. cd to a temp directory
      2. # ufsrestore –i ( use –if /dev/rmt/0 if cant find device)
      3. ufsrestor> cd to some directory (can cd in the tape)
      4. ufsrestor> add file_name
      5. ufsrestor> ex or extract
      6. ufsrestor> quit

      Configuring the NFS Environment

      The NFS Server
      1. Edit the /etc/dfs/dfstab file to enable automatic sharing of resources
      share –F nfs /user
      2. Start the NFS Server daemons by executing the script /ect/dfs/dftab
      # /etc/init.d/nfs.server start
      3. Use the dfshares command to verify the resource is available
      # dfshares
      4. To identify clients
      # dfmounts
      The NFS Client
      1. Use the /usr/sbin/dfshares command to display a servers available resources
      #dfshares [server_name]
      2. Use the /sbin/mount command to access the remote file resource.
      # mount [server_name]: /usr/share/man /usr/share/man
      The /usr/share/man is the mount point on the client.
      3. Edit the /etc/vfstab file to add and entry for the remote resources that will be
      automatically mounted.
      # [server_name]: /usr/share/man - /usr/share/man - yes –
      Other commands
      # unmount /usr/share/man = un-mount
      # mountall –r = mounts all file resources
      # unmounall –r = un-mounts all currently mounted resources

      Software Package Admin Commands

      # pkginfo = display software package information
      # pkginfo | more = using more to display info

      Adding a software package
      Pkgadd [-d device | path_name] pkg_name
      # pkgadd –d /cdrom/cdrom0/s0/solaris_2.4 SUNWando

      Verifying Package Installation
      # pkgchk [package_name]
      # pkgchk –p [path]

      Removing Software Packages
      # pkgrm [package_name]

      Spooling Packages for Install on Client from Server
      Server Side
      # pkgadd –d /cdrom/cdrom0/s0/solaris_2.4 –s spool [package_name]
      Client Side
      1. # mount [server_name]: /export/pkgs /export/pkgs
      2. # pkgadd –d /export/pkgs [package_name]
      Removing Spooled Packages
      # pkgrm –s /export/pkgs [package_name]

      # ps –ef displays current running processes
      - can pipe it to grep for better results

      # find / -name csh –print
      / = the directory to start searching in
      -print = prints full path name

      # file [file name]

      # set = displays environmental variables

      # hostname = displays what host you are logged into

      # grep [string] [filename] = searching for a string in a file

      -i = Ignores case
      -n = prints line number
      -v = prints all lines except those that match
      -c = prints only a count of the number of lines that match

      # touch = sets the last modified date for the files specified to the current date

      echo –e “[message] [escape option]”
      \a = alert (bell)
      \b = backspace
      \c suppress trailing new line
      \f from feed (new page)
      \n new line (line feed)
      \r carriage return
      \t tab
      \\ another \
      ex: echo –e “wake up! \a”

      -Formatting drives
      newfs /dev/rdsk/c0t0d0s0
      = full device name

      # newfs = formatting drives
      # newfs /dev/rdsk/c0t0d0s0
      - note… must partition first (run format)

      # cal = calendar program
      cal [12] [2001] = displays a month
      cal = displays this month
      cal [2001] = displays a year

      # passwd = password program. Use to change password

      # vi = text editor

      vi –R [file name] = read only
      vi –r [file name] = recovery mode after system crash
      vi –r = =

      vi command mode

      zz = save and quit
      :q! = quit no save
      I = start inserting text at beginning of current line
      A = start inserting text at end of line
      :set show mode = displays what mode your in
      w = moves cursor to next word
      0 = moves cursor to begging of current line
      :set number = displays line numbers
      :set nonumber = removes line numbers
      p = pasts last deleted item
      dw = deletes word
      :e [file name] – open new file for editing
      :x! = save and quit

      vi input mode

      ^v then any control key
      ~ change to upper case of a letter that cursor is on.
  15. Beej macrumors 68020


    Jan 6, 2002
    Buffy's bedroom
    Yeah sorry I should have mentioned that I'd tried that. I get "tcpdump: no suitable device found"

    Will tcpdump work on anyone else's Mac? Why has it stopped working on mine? :(

Share This Page