Bash - who, where and what

In this introduction to Bash we will enter simple commands and find out who we are, who they are, where we are and what is there.

These simple commands are a great way to start using the terminal.

Now we've logged in to our VPS (see SSH Login from Linux and Windows articles), we need to get comfortable using Bash.

Bash is simply the mechanism for 'talking' to the server and the way the server responds to our questions.

In your terminal you should see some sort welcome message, even if it simply tells you who logged on last:

As you can see, my VPS is called 'shallot' (all my servers have an onion theme!) and I last logged in on Sat May 12 at 12:07:35.

You should know what username you have logged in as but if you administer many servers you may need a quick reminder. The command for this is 'whoami', so enter the command:

whoami

No real surprises there, from the Ubuntu Setup articles we know I created the user called 'paul' .

It's your VPS and no one else should be here but let's have a look to see. There are two options here: the 'who' command and the 'w' command. try the 'who' command first:

who

This gives brief details such as username, when they logged on and from what IP (I blanked that bit in the image).

The 'w' command gives more information:

w

This is getting better, we are getting some real feedback - it tells us much more such as what they're doing. In this case we see they are giving the command 'w' i.e. what we were doing right now.

Try the same command but with sudo privileges.

sudo w

Have a look at the difference in output. There is more information available to you. Open another connection to your VPS and try again: It will show two users. Get used to interpreting the text output.

Now we need to know where we are in the file system. After a bit of navigating around it is easy to forget exactly what directory we are in. This is not as minor a detail as you might think: deleting the files in the wrong directory can mean disaster. Enter the command 'pwd':

pwd

the pwd command is short for 'Print Working Directory'. In other words, where am I? As seen, I am safely in my home directory.

Lastly let's have a look to see what is in this directory by using the 'ls' command:

ls

No real surprises there - you can see I have four directories (bin, configs, public_html and sources - all straight from the install and Litespeed articles).

During the install we created some directories with a period in front of them (such as .ssl and .ssh). Where have they gone?

They are still there but the period in front of a file or directory means it is 'hidden' from normal viewing. Most configuration files and directories would be named in this manner - do you really want your screen littered up with these files?

No magic is need to read these directories. We simply add conditions to the 'ls' command as such:

ls -al

Lots more information there. You can see the .ssl and .ssh directories that were made during the install. You can also see some 'hidden' files such as .screenrc and .toprc. These are configuration files for screen and top so I don't have to configure them each time they are used. Now you can see why we have these 'hidden' items: I have no need to see the screenrc file everytime I log on.

That's it for now. The next article will have a look at the 'man' command and find out where I got the '-al' from at the end of the ls command.

PickledOnion.

Digg it | del.icio.us | reddit | StumbleUpon

Comments are closed for this article.