Linux/Unix command line. Part 2 - moving on
Sunday, November 26, 2006 5:24:00 PM
In some cases you can't avoid command line. Ubuntu for example has good graphical administration utilities, but if you search for instructions or ask for help all you get is cryptic commands. Some think it's frustrating and others like me don't mind. Graphical tools are great when you don't have much time or just don't feel like reading manuals. Why using command line is better is personal thing, but maybe you find your own reasons once you get bit more comfortable with it. But if you're planning to script some common tasks, command line teaches you many useful commands that you can use.To follow this tutorial, you need access to Unix/Linux system. You can get one for free for example at http://www.ubuntu.com/. Once you burn the CD, just boot from it and you should have working system without messing up your current operating system.
If you have used DOS command line before, there are few important differences. Everything is case sensitive and commands are in lowercase. Environment variables are usually in uppercase, but you can use lowercase names with your own custom environment variables. Also, don't use \ as a directory separator, in Unix it's /. \ is used as a escape character, you need it when you have to use some character that has special meaning, but you need to use it as normal character.
Another peculiarity is that everything is treated as a file, you can all sorts of things with files in /dev directory. Files in there actually represent devices on your system.
Some commands also have different function, for example find is used to find files, not to find strings inside a file. If you need to find strings, use grep. Some commands have the same name, but vowels are removed, for example copy is cp in Unix.
If you didn't understand much about previous paragraphs, don't worry, I'll explain those things later on, so DOS knowledge is not necessary.
Let's assume that you're in graphical environment. You can usually find terminal from menus, but if you can't see it anywhere just find run dialog and type xterm there. There are many different terminal emulators out there, xterm is just one that's usually already installed.
Most basic thing is moving around. It's hard to do anything if you're stuck in your home directory. Default shell prompt depends on shell you're using. Some of them don't show where you are, just on what computer you are. You can see where you are by typing following command:
pwd
If you want to know more about pwd coommand (you can use this for other commands too), type:
man pwd
What you can see on your desktop is actually just small part of the filesystem, it's not even your whole home directory. Here's how Linux filesystem is organized, some distributions have different practices how to use certain directories, but at least it gives good overview what those directories are. If you're using FreeBSD, man hier has good overview of the filesystem hierarchy.
Unix doesn't use drive names like a: or c:, everything is attached to root directory which is called /. Look what is in your root directory by typing:
ls /
Lot's of cryptic directories there, especially if you didn't open that earlier link. Let's try moving to one of those directories. First thing you can do is to move to root directory:
cd /
The you can move to for example var:
cd var
You can also combine those two:
cd /var
If you want to move up in directory hierarchy:
cd ..
Whoops, a mistake. Let's move back to previous directory:
cd -
Now can try some combining again. Let's move up in hierarchy and then to another directory with one command:
cd ../etc
If you're planning on editing your systems configuration files by hand, they're here. But let's not do any damage to your system and move safely back to home. There's no need to write full path to your home directory, all you need to write is:
cd
Home directory has also a special character that you can use. So for example if you want to move to Desktop directory (everything you put there shows up on your desktop) in your home directory, this command works, no matter where you are:
cd ~/Desktop
Now you should know how to move around. You can experiment as much as you want and home is always one command away.
But wait, before you start typing long filenames (or directory names), there's a shortcut. You don't have to write long filenames all by yourself, your shell can help. In most shells you can complete filenames and directories by pressing tab key when you have typed enough characters to find unique filename. Otherwise you'll just get list of possible files. There are some old shells that don't support that, but it's quite likely that you're using Bash. It's usually default on Linux systems, but on other systems it could be something else. You can check what shell you are using with following command:
echo $SHELL
You can display text with echo, it may not seem very useful right now, but it has its uses.
For me it displays:
/usr/local/bin/zsh
So that last word tells that I'm using ZSH.
That's all for now, we'll see what next part brings up. You can't do much just by moving around. As always, please leave a comment if you didn't understand something or have some ideas about what you would like to know.








Unregistered user # Sunday, June 17, 2007 5:54:45 AM
Antero Hytönenanzah # Sunday, June 17, 2007 9:56:06 AM
But at least if you want to know what terminal you are using (or at leas operating system thinks you're using) you can type:
echo $TERM
IF you want to know if your terminal is supported by the operating system, look at /etc/termcap
In some cases vt100 works as good enough fallback, but it's possible to supply your own termcap entry. I just can't remember how right now.