Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

howard

macrumors 68020
Original poster
Nov 18, 2002
2,017
4
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.
 

sonofslim

macrumors 6502a
Jun 6, 2003
742
0
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.
 

howard

macrumors 68020
Original poster
Nov 18, 2002
2,017
4
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 :)
 

Dros

macrumors 6502
Jun 25, 2003
484
1
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.
 

howard

macrumors 68020
Original poster
Nov 18, 2002
2,017
4
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!
 

jxyama

macrumors 68040
Apr 3, 2003
3,735
1
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...
 

Doctor Q

Administrator
Staff member
Sep 19, 2002
39,789
7,525
Los Angeles
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.
 

howard

macrumors 68020
Original poster
Nov 18, 2002
2,017
4
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 :)
 

whocares

macrumors 65816
Oct 9, 2002
1,494
0
:noitаɔo˩
Dros said:
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

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.
 

Ajmbc

macrumors regular
Jan 29, 2003
232
0
Louisiana
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
 

howard

macrumors 68020
Original poster
Nov 18, 2002
2,017
4
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, :)
 

janey

macrumors 603
Dec 20, 2002
5,316
0
sunny los angeles
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".
 

whocares

macrumors 65816
Oct 9, 2002
1,494
0
:noitаɔo˩
übergeek said:
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:~ $"/..

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).
 

whocares

macrumors 65816
Oct 9, 2002
1,494
0
:noitаɔo˩
übergeekOh said:
cd[/i]ing 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".

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
 

Counterfit

macrumors G3
Aug 20, 2003
8,195
0
sitting on your shoulder
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
 

JFreak

macrumors 68040
Jul 11, 2003
3,151
9
Tampere, Finland
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.
 

cb911

macrumors 601
Mar 12, 2002
4,128
4
BrisVegas, Australia
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.
 

Doctor Q

Administrator
Staff member
Sep 19, 2002
39,789
7,525
Los Angeles
JFreak said:
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.
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
 

howard

macrumors 68020
Original poster
Nov 18, 2002
2,017
4
Doctor Q said:
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.

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?
 

latergator116

macrumors 68000
Sep 30, 2003
1,689
20
Providence, RI
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.
 

Doctor Q

Administrator
Staff member
Sep 19, 2002
39,789
7,525
Los Angeles
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
 

xhost_plus

macrumors newbie
Mar 25, 2004
23
0
Reno, NV
NCFTP

sonofslim said:
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.


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

http://www.ncftp.org
 

xhost_plus

macrumors newbie
Mar 25, 2004
23
0
Reno, NV
latergator116 said:
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.

Yes like deleting your root folder.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.