View Full Version : terminal tips and talk about it in general
howard
Apr 12, 2004, 01:31 PM
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
Apr 12, 2004, 01:53 PM
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
Apr 12, 2004, 02:04 PM
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
Apr 12, 2004, 02:17 PM
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
Apr 12, 2004, 02:25 PM
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
Apr 12, 2004, 03:19 PM
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
Apr 12, 2004, 03:22 PM
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
Apr 12, 2004, 10:32 PM
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 :)
cait-sith
Apr 12, 2004, 10:54 PM
http://www.isu.edu/departments/comcom/unix/workshop/unixindex.html
or google search for basic shell information. any unix docs will help out, since after all, it's just unix.
have fun in the best part of the os :)
Doctor Q
Apr 12, 2004, 10:55 PM
For more beginner info about Terminal, download the Terminal Basics guide here (http://homepage.mac.com/rgriff/index.html).
whocares
Apr 12, 2004, 11:05 PM
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:
cd /
Takes you to the drive's root.
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
Apr 12, 2004, 11:43 PM
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
Apr 13, 2004, 12:00 AM
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
Apr 13, 2004, 12:18 AM
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 (http://gcc.gnu.org).
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 (http://fink.sourceforge.net) or darwinports (http://darwinports.opendarwin.org/) 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
Apr 13, 2004, 12:45 AM
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:
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
Apr 13, 2004, 12:48 AM
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:
cd /Volumes/Backup
Counterfit
Apr 13, 2004, 01:05 AM
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: cd ..
Oh, and once you get fink, make sure you check out my favorite program: wtf :D
JFreak
Apr 13, 2004, 01:21 AM
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
Apr 13, 2004, 04:13 AM
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
Apr 13, 2004, 11:51 AM
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
Apr 13, 2004, 12:30 PM
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
Apr 13, 2004, 03:01 PM
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
Apr 13, 2004, 03:14 PM
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
Apr 13, 2004, 03:16 PM
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.
www.ncftp.org
xhost_plus
Apr 13, 2004, 03:17 PM
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.
Counterfit
Apr 14, 2004, 03:10 PM
Counterfit, i think that link's broken. i'm interested in this 'wtf' now. :D That's because it's not a link! :D :D :D
just install it, it's fun!
howard
Jul 18, 2004, 04:02 PM
hey,
back with another very simple question
how do you copy move and make new folders and files with the terminal?
Doctor Q
Jul 18, 2004, 04:53 PM
hey,
back with another very simple question
how do you copy move and make new folders and files with the terminal?The commands you want to know about are "mv" to move or rename a file, "cp" to copy a file, and "mkdir" and "rmdir" to create and remove directories, aka folders. If you want to create an empty file, you can use the "touch" command, as in "touch myfile.txt". You could also use "echo >myfile.txt".
Look at the manual (man pages) for a given command with the "man" command, e.g., "man cp".
jeremy.king
Jul 18, 2004, 09:30 PM
http://www.ss64.com/osx/index.html has come in handy more than once for me.
ingenious
Jul 18, 2004, 10:42 PM
how do i use the "talk" command? is that like the net command in DOS? like i could send a text message to someone else using the terminal?
GiantsFan
Jul 18, 2004, 10:55 PM
how do i use the "talk" command? is that like the net command in DOS? like i could send a text message to someone else using the terminal?
write username
vBulletin® v3.8.6, Copyright ©2000-2012, Jelsoft Enterprises Ltd.