Beginner’s guide to Apple Terminal, part 2

In the previous article in the series you learned what Terminal.app is, what it does, how to start it and a couple of basic tasks to do with it(move around folders – the cd command, look what’s inside folders – the ls command, opening up files – the open command and how to remove files – the rm command). Today you’ll learn how to remove entire folders, how to copy files or folders, how to move them somewhere else, how to create aliases to files or folders and even a bit more.

How to delete an entire folder
You already know how to remove a file. Just type rm followed by the name of the file and you’re set. To remove an entire folder, you’d have to type rm -rf followed by the name of the folder. What this actually does is to remove all the contents of the folder and eventually the folder as well. You should use this carefully, ’cause unlike removing a folder from the Finder, this command doesn’t move anything into Trash. You can’t recover things deleted using rm. The good part, though, is that, whenever you are stuck with some file or folder that simply won’t let itself be erased in the classic ways, you can try removing it from the Terminal command line.

How to rename a file/folder in Apple Terminal
The command to rename a file or folder starts to show its strength. All you have to do is type “mv” followed by the name of the file/folder to rename and the new name you want to call it.
mycomputer:~ Alex$ mv Research/ Research1
Typing this (using the shortcut with the “Tab” key mentioned last time) is actually faster for experienced users than opening up Finder, browsing around to find the folder/file in question, Ctrl+Clicking it, selecting Rename and eventually typing the new name.

How to copy a file/folder from Apple Terminal
You already guess the answer to this one, as it combines what you learned in the previous tips: the command for it is “cp” (as in CoPy), it takes two parameters at the minimum – the name of the file to be copied, and the name of the new file. However, if you want to copy a folder, you’ll have to add the extra parameter “-rf” right after the “cp” command.

The IP address
I promised last time that I would teach you how to check out your IP address. That’s the address your computer has on the internet/local network, and sometimes you need to know it. One way to do it would be to open up System Preferences, then Network, then Configure, then TCP/IP. One other way would be to open up the System Profile utility (available in Applications/Utilities or by clicking on the apple icon in the top menu bar, chosing “About this Mac” and “More Info..”) and look into the Network menu for the IPv4 Addresses values.
The Terminal way to do this is much simpler: just type ifconfig in the command line. You’ll be presented with a long list with information on all the network devices present in your computer. The one of interest for now is en1 (might be different in your case), namely the one with information on the inet address. The value of inet is the IP address of your computer.

Aliases
Aliases are shortcuts to existing files or folders on your system. You can create them by right-clicking(Ctrl+Click) in the Finder on an existing file/folder, selecting the option “Make Alias”. This creates a shortcut that you can rename or move around without messing with the original.
Creating aliases in Terminal is extremely easy – just type in ln -s followed by the name of the file/folder you want to create the shortcut to, and by the name you want to give to the shortcut.

mycomputer:~ Alex$ ln -s Research/ Researchalias

What about stubborn commands?
Let’s say you just want to remove or rename a system file or folder. If you don’t know what you’re doing, you probably shouldn’t. Still, you might at times need to do some stuff that your system won’t let you(it would say “Permission denied”). The solution is the sudo command – you prefix the command you want to run by the sudo word. When you press enter, you’ll be asked to type the Administrator password. On most computers this password is absent, so pressing the Enter key is enough. Sudo is a powerful command that shouldn’t be taken lightly, or you risk messing up your system.

I think you already feel the scary power hidden beneath the Terminal application. Off course, we’ve only scratched the surface of a vast subject. Trying to initiate you further might be a bit out of our goal. That’s why I’m going to stop here and point you to a couple of resources around the web:

Next week, we’ll show you how to do the same things from within Quicksilver – a bit less powerful than Terminal, but with a much more beautiful user interface.


Similar Posts:

Leave a Reply