terminal tips and talk about it in general

Discussion in 'General Mac Discussion' started by howard, Apr 12, 2004.

  1. howard macrumors 68020

    howard

    Joined:
    Nov 18, 2002
    #1
    i've been wanting to learn the terminal

    what do you guys use it for and what do you do with it on a daily basis? i'd love to learn little things about it, i'm fairly new at it.

    also how do you connect to an ftp site with the terminal?

    any sorts of useful things i think it would be cool to talk about and learn from eachother.
     
  2. sonofslim macrumors 6502a

    sonofslim

    Joined:
    Jun 6, 2003
    #2
    i've been using applescript to automate terminal and shell script tasks, which is dorky and fun, not to mention really useful. i also recently discovered that there's a command line interface for PHP, if you're running it.

    for ftp help: type man ftp at the prompt. the built-in man pages (the command is short for "manual," if you're new to the terminal) tend to run a little on the technical side, but there's a wealth of information there. and... yes, for help with the "man" command, type man man at the prompt.
     
  3. howard thread starter macrumors 68020

    howard

    Joined:
    Nov 18, 2002
    #3
    cool thanks

    i got another question...

    say i'm using the cd command to move through folders... i go into music and then press ls to see whats there... now if i want to keep moving through the directories is there a way to continue from the music folder instead of start all over? ...

    example

    cd /Users/username/Music

    [usernam-Computer:~/Music] nate%

    then i want to go from there to say radiohead...do i have to type all over again this:

    cd /Users/username/Music/Radiohead

    or is there an easier way or a shortcut... i'm just using the music thing as an example, so i can learn the functions of the terminal

    thanks :)
     
  4. Dros macrumors 6502

    Joined:
    Jun 25, 2003
    #4
    If you start off the place you want to go with a "/", then that tells the computer you want to start at the top directory, like you have been doing:
    cd /Users/username/Music/Radiohead

    But if you are in Music, then just say "cd Radiohead/" and it will jump one level. Here is a nice tip that will save some time. If you type "cd Ra" and hit tab, it will autocomplete the name for you if "Ra" is enough to uniquely identify the desired file. Otherwise, you may need to hit tab a few times and it will show a list of possibilities "Radiohead Radioeyes Radishheads" etc.
     
  5. howard thread starter macrumors 68020

    howard

    Joined:
    Nov 18, 2002
    #5
    Dros,

    cool! thanks for the tips...

    see its that simple stuff i need to learn...knowing that /etc.. means starting at root is probably so obvious to a lot of people who know the terminal that they wouldn't think to explain it to someone learning its for that kind of info i wanted to start this thread..

    thanks again!
     
  6. jxyama macrumors 68040

    jxyama

    Joined:
    Apr 3, 2003
    #6
    at least in tcsh, you can push the up arrow key to get the history of commands... it will go through commands you had just executed in reverse chronological order.

    this and the already mentioned tab key auto completion are life savers in using the terminal...
     
  7. Doctor Q Administrator

    Doctor Q

    Staff Member

    Joined:
    Sep 19, 2002
    Location:
    Los Angeles
    #7
    Sometimes the man pages are a little scary because they tell you all the details and not how to get started. It might help you to know that only a few commands are needed to get started with command-line FTP. After you type ftp myserver, where myserver is the server name or address, and get connected, and enter any required username and password, you could get by with only a few commands: cd, ls, type, get, put, and quit.

    Here are some details:

    Some ftp servers prompt you for a username and password. If not, you can type user myname and pass mypassword as commands.

    The cd directory command lets you change directories on the server. The ls command shows you the files in the current directory.

    To set the file transfer type to binary (for data files), type type image. To set the file transfer type to text (for ASCII text files crossing platforms), type type ascii. To upload a file, type put filename. To download a file, type get filename.

    Type quit to exit ftp and return to the command prompt.

    There is plenty more you can do in ftp, but this should be enough to get you started.
     
  8. howard thread starter macrumors 68020

    howard

    Joined:
    Nov 18, 2002
    #8
    hey thanks a bunch doctor Q that does help a ton...

    i was thinking exactly what you were saying after looking at the manual...its pretty daunting and i had know idea what any of the stuff meant...

    thanks :)
     
  9. cait-sith macrumors regular

    Joined:
    Apr 6, 2004
    Location:
    canada
    #9
  10. Doctor Q Administrator

    Doctor Q

    Staff Member

    Joined:
    Sep 19, 2002
    Location:
    Los Angeles
    #10
    For more beginner info about Terminal, download the Terminal Basics guide here.
     
  11. whocares macrumors 65816

    whocares

    Joined:
    Oct 9, 2002
    Location:
    :noitаɔo˩
    #11
    Some cd shortcuts:

    Code:
    cd /
    Takes you to the drive's root.

    Code:
    cd
    Takes you to your user home.


    To complement the autofill ("tab") of text, you can also use your middle mouse button if you have one. Hightlight the text you wish to copy (left click + drag) and then hit the middle button to paste the highlighted text at the curser. Very nifty. :)

    My favourite terminal command is "find". It's abit hard to learn (funny syntax) but is really useful for some specific tasks (like changing privileges on all the subfolders of a given folder without changing the files).

    Also checkout /bin and /usr/bin folders to see what binaries (terminal apps) you have and run "man" on the ones that interest you.
     
  12. Ajmbc macrumors regular

    Joined:
    Jan 29, 2003
    Location:
    Louisiana
    #12
    Once you learn the basics, (moving files, browsing directories) then you can get into the more interesting things.

    Text editors:

    Pico- your basic notepad text editor- man pico

    Emacs- a more advanced sort of all-in-one operating system kind of text editor

    Vi- a visual command based text editor that is much easier than it looks.

    I would suggest using the vi tutorial (google for this) and learning vi- it is a great text editor.

    Python- Python is a cool little language. You make a script and you can have it execute or solve for different things- such as math problems. Google python

    >console- Not really having to do with the app 'terminal' itself- but when you get to be comfortable operating your system via a terminal- at the login prompt type in your name as >console, log in and you will get a login prompt- login and you will operate your user account via text.

    Compiling your own terminal apps- If you have developer's tools installed, you can compile binaries on your own- get source code from the vendor and follow the instructions to compile the app

    Ps and listing processes- To list all processes going on in your tty (or your current terminal window) type in 'ps'. To see system-wide processes type in 'ps auxc'. You can then kill, or force quit an app or program by typing in 'kill pid' where pid is the process id, shown in the ps command's listing. Typing in 'kill -9 pid' means kill this process no matter what. Always try the first method first.

    aj
     
  13. howard thread starter macrumors 68020

    howard

    Joined:
    Nov 18, 2002
    #13
    wow great info,

    i see i've got plenty to do now! thanks

    i never found those sites doc q and cait sith... i kept getting links to the mac dev center which wasn't working out...i'll take a look at those when i get some time tomorrow probably and report back...

    this thread is turning out very useful, :)
     
  14. janey macrumors 603

    janey

    Joined:
    Dec 20, 2002
    Location:
    sunny los angeles
    #14
    actually in OS X 10.3 its vim (vi improved), not vi :)
    vi the command still works though.
    The developer tools installs a compiler called gcc.
    Random stuff off the top of my head:
    Some cool commands to know for terminal.app are apropos, top, uptime, alias, sudo rm -rf / (JUST KIDDING, DO NOT TRY IT), sudo and su in general, chmod, ls, clear and everyone's friend man.
    Everything you want(ed) to know about the bash/tcsh/zsh/sh shells can be discovered by doing a man (insert name).
    To go to the parent directory type in cd ..
    Install fink or darwinports for things like mono, fortune, glpong and hundreds of other interesting ports.
    oh and cool thing is that its really customizable, so instead of a boring "[somebodys-computer:/] somebody%" you can do anything from the overused "Yes, master?" to a simple "username@compname.local:~ $"/.

    Oh, and if you're cding to a folder with spaces in the names, precede the space with a \, i.e. /Users/jane/Music/iTunes\ Library/ or just use quotes, "/Users/jane/Music/iTunes Library".
     
  15. whocares macrumors 65816

    whocares

    Joined:
    Oct 9, 2002
    Location:
    :noitаɔo˩
    #15
    I like to have the command number in my terminal prompt. As stated before you can use the up arrow to backshift through your history command. You can also recall a command with its history number. Use the 'history' command to get the list of used commands. To access a command, just use '!command_number': if you want number 55, just type '!55'.

    The cool thing is you can use the options on this. Say you typed 'ls' to list the content of a directory and its command 56, if you want to do a long list (with the '-l' option) just type '!56 -l'. Granted this is actually longer than typing 'ls -l', but that's because 'ls -l' is a short command. ;)



    BTW, you edit you prompt line with the .tcshrc file (for the csh shell - default in 10.0 through 10.2). You can also specify stuff like paths (paths it will search for binaries) and aliases. Here's an example of mine:

    Code:
    set prompt="[%m:%c3] %n (\!)% "
    
    
    setenv PATH /usr/local/bin/:/bin:/sbin:/usr/bin:/usr/sbin
    alias ls 'ls -F'
    It sets my prompt to '[machine_name:current_path] user_name (command_number)%'. (it shows a max of 3 levels for the path). Sets the PATH variable and creates an alias called 'ls' that lists stuff with file type (ie when I type the 'ls' command, I don't get the standard output, but an output with the file type).
     
  16. whocares macrumors 65816

    whocares

    Joined:
    Oct 9, 2002
    Location:
    :noitаɔo˩
    #16
    Oh, and to change volume, look for folders in the 'Volume' folder. All mounted volumes are listed there. For example, if you have a mounted volume called 'Backup', here's how to get to it in the terminal:

    Code:
    cd /Volumes/Backup
     
  17. Counterfit macrumors G3

    Counterfit

    Joined:
    Aug 20, 2003
    Location:
    sitting on your shoulder
    #17
    I don't think anyone answered you earlier question. I think it could be summed up as "How do I go back to the directory just above where I am now?". simple:
    Code:
    cd ..
    Oh, and once you get fink, make sure you check out my favorite program: wtf :D
     
  18. JFreak macrumors 68040

    JFreak

    Joined:
    Jul 11, 2003
    Location:
    Tampere, Finland
    #18
    tip #1: use the tab key when typing directories/filenames. for example when you want to go to /Users/Shared/iTunes/SomeArtist/SomeAlbum directory you can get there a lot faster by typing the beginning of directory name and then press tab key to autocomplete the rest. another reason why it's good practice to use it is that it always types the names correctly.

    so...

    typing "/Us<tab>/Sh<tab>/iT<tab>/So<tab>/So<tab>" is 20 keypresses compared to the full directory name that has 41 characters in the example i typed earlier. use it, you'll love it.
     
  19. cb911 macrumors 601

    cb911

    Joined:
    Mar 12, 2002
    Location:
    BrisVegas, Australia
    #19
    Counterfit, i think that link's broken. i'm interested in this 'wtf' now. :D

    i'd also recommend install DarwinPorts and Fink, they're very nice to have.

    also, play around with compiling stuff. that way you can grab any source code (actually, i think you need PPC source code, so any source code won't work. someone correct me if i'm wrong) and then compile it so you have a running app on your machine.
     
  20. Doctor Q Administrator

    Doctor Q

    Staff Member

    Joined:
    Sep 19, 2002
    Location:
    Los Angeles
    #20
    Correct, and you can also be even lazier. Type cd and a space, then find the folder in the Finder and drag and drop it into the Terminal window. Click in the Terminal window again and press return.

    For example, if you drag in folder /Users/Shared/iTunes/SomeArtist/SomeAlbum, the command will look like this, without you having to type any of the folder path:

    cd /Users/Shared/iTunes/SomeArtist/SomeAlbum
     
  21. howard thread starter macrumors 68020

    howard

    Joined:
    Nov 18, 2002
    #21
    i'm able to connect... cd around and everything..but i'm a little confused by how you upload. how do i put a specific file..say in the documents folder on to a specific folder, say the upload documents folder on the ftp site?

    i was able to download just fine by using your instructions however it appears the default download directory is my users folder...how can i change that to my desktop folder?
     
  22. latergator116 macrumors 68000

    latergator116

    Joined:
    Sep 30, 2003
    Location:
    Providence, RI
    #22
    Here is a great way to get rid of things that you can't trash (i.e. when you try to delete something and you get a message saying "you can not delete this because the file is in use"). This command will surely get rid of it. ;)

    sudo rm -rf (now drag in whatever you want to delete)

    *make sure not to include parenthesis.

    P.S. be sure to type in this command correctly because it can be potentially dangerous.
     
  23. Doctor Q Administrator

    Doctor Q

    Staff Member

    Joined:
    Sep 19, 2002
    Location:
    Los Angeles
    #23
    When you use ftp file transfers, the folder/directory on the server side is determined by your cd commands. The folder/directory on the client side (your Mac) is the folder/directory you are in when you start ftp. For example, if you want to ftp a file from /Users/Me/Documents on your Mac to /somewhere/someplace on the server, you can use these commands at the shell prompt:

    cd /Users/Me/Documents
    ftp myserver


    and then these commands in ftp:

    cd /somewhere/someplace
    put filename
     
  24. xhost_plus macrumors newbie

    Joined:
    Mar 25, 2004
    Location:
    Reno, NV
    #24
    NCFTP


    I found that NCFTP is better than FTP because it supports Tab-completion. The same Tab-completion that you are used to in Bash.

    www.ncftp.org
     
  25. xhost_plus macrumors newbie

    Joined:
    Mar 25, 2004
    Location:
    Reno, NV
    #25
    Yes like deleting your root folder.
     

Share This Page