Archive

Posts Tagged ‘Linux’

Beginner’s Guide to Command Line: Part 1

August 9, 2008 Leave a comment

The command line interface will either be from a terminal or a SSH window like putty. Here is an example of the Gnome terminal (Applications/Accessories/Terminal from the menu). You can see that it is only text but it does have a menu system for modifying the color of the screen and text or allowing you to open multiple terminals at one time.

If you login from a putty session from a Windows machine or if you are logged into a TTY session on the Linux box you will not have the option of a terminal and so you will be using text only as there will be no menus or graphics of any kind. Text is exactly the same as you can see in the next example. The biggest difference is that it will typically be a black screen with white text.

As you change users the prompt will show the change in user as you can see from these examples:

fred@ub:~$
mary@ub:~$
tom@ub:~$
jane@ub:~$

As you change to different servers the hostname will change. The hostname is a name that is applied to a server so that users and applications may refer to the server with a name and not an IP Address. An example would be of a hostname of ub instead of the IP Address 192.168.5.43. As you connect to different servers or workstations, this name will change. These names can be anything the system administrator would like to assign.

fred@mail:~$
fred@ftp:~$
fred@ubuntuserver:~$
fred@mystuff:~$

As you change locations in the file system the location will change. The ~ symbol indicates that a user is located in their home directory. The home directory in Linux is located in a directory, Windows calls them folders, labeled /home. So if fred is in his home directory he is really located in /home/fred. Each user has a home directory named for the user. If fred changes location in the directory system to /var, his prompt will reflect that change.

fred@ub:/var$

If mary changes to the /usr/share directory it will reflect that change.

mary@ub:/usr/share$

If tom changes to the /usr/bin directory it will reflect that change.

tom@ub:/usr/bin$

And finally if jane moves to the / directory it will reflect that change.

jane@ub:/$

Changes in location in the file system will list the location in the prompt. It is important that you use this as a clue to location especially when you begin to issue commands.

Working Directory

The Working Directory is the location of the directory that you are currently in. For example if you log into the system, it is designed so that you will begin in your home directory. For example, if your username was tom then your home directory by default would be /home/tom. When tom logs into the system it places him in the /home/tom directory, which is the current working directory. So if tom issues the command ls, then it will list the contents of /home/tom. If tom moves to the /usr directory by using the command cd /usr (which means change directories to /usr) then the current working directory is /usr Current working directory is the current directory that a command will interact with. Now, that does not mean that you have to be located in a directory to issue a command in the shell. Regardless of your current working directory you can use a command that interacts with any directory by using a path. For example, if you were located in the /home/tom directory you could list the contents of the /usr/share directory by using the path of that directory so the command would look like this:
ls /usr/share

One command that will verify your working directory is the command pwd, which stands for print working directory.

Moving Around in Directories

The cd command is the basic way to move around in the directory system. Cd followed by the directory location will move the users current working directory. For example,
cd /home

This command moves a user to the /home directory where all user directories are located. If the user fred wanted to move to their /home directory they would use:
cd /home/fred

There is a shortcut to moving to your home directory. The ~ is equivalent to the home directory. As a result fred can move to his home directory with this command:
cd ~

This makes it easier than typing the full path.

Follow

Get every new post delivered to your Inbox.

Join 53 other followers