Gizmo's Freeware Forum

Gizmo's Freeware Forum (
-   Linux (
-   -   Linux command line intro (

debtboy 24. May 2009 02:38 AM

Linux command line intro
OK, here goes...
No matter what distro your using, you will have the ability to open a shell terminal or console
(may have different names such as Term, Xtrem, ETerm, Console, Konsole, etc...)
I believe every distro will open to a BASH Shell (Born Again SHell), next generation of the old Bourne Shell.
Open the shell terminal/console and you should see your login name "@" the computer or domain name.
This is what mine looks like:
Sorry, while posting here, I can only use 4 images, so to see the image, use this link:

This is where the real power of Linux comes from, but for this intro we will discuss only 2 or 3 basic commands.
The first command we will try is ls, this command stands for listing, similar to the old DOS dir command.
It gives us a listing of file/directory names but nothing else.
What we want is a long listing with owner, group, size, etc...
so we add the -l switch. see image:

How are we supposed to remember what "switch" to use like -l,
well there are thousands of commands and most have many switch options,
so a built-in manual was included in every Unix and Linux.
It's called man pages (sorry ladies Ha! Ha! Ha!) you type man and then the command your inquiring about.
For example, in our situation, we would type man ls see image:

I've already scrolled down to the area I'm interested in, to scroll down you can use the enter key (line by line) or spacebar (page down) see image:

NOTE: now to make matters worse, after you scroll or page to the bottom, you can't get out... WTH!!
enter the letter q which stands for quit. (you will get used to it)

When we use the ls -l command we see a full listing which includes the owner, the group and access permissions
(we'll worry about this later, in another post).

Now lets do a listing ls and then cd (change directory) into one of the directories available.
Once you've gone into the directory, do a long listing of the files within.
see image:

Two more commands you can try is clear
this command will clear the terminal window and
exit this command will exit the terminal.

ls -l

debtboy 24. May 2009 01:03 PM

moving around with cd (change directory)
Hi everyone :)

Now that your able to cd down into your home directory,
you might want to move up directory by directory or jump directly
to a particular location.
cd .. this will bring you UP one directory

cd ~ or cd ~/ will bring you to your home directory
(if your username is debtboy, it will take you here /home/debtboy)

cd / will bring you directly to the root directory
(the root directory is the uppermost or top directory of the filesystem,
everything resides inside/below the root directory,
do not get this confused with the user root
which is all powerful like OZ (ha! Ha! Ha! :p))

Lets say your in the root directory and you want jump directly to the /usr/share directory, how would you do it?
cd /usr/share
Now you realize you really wanted to go to the /sbin directory so...
cd /sbin

Lets say your not sure where you are, try this command.
pwd I believe it stands for (print working directory)

Now with cd and ls or ls -l you have the ability move all around the filesystem and list files.

The filesystem IS CASE SENSITIVE so keep this in mind.

Next we'll go over that strange looking but all important
permissions structure we see when doing ls -l

wdhpr 24. May 2009 02:48 PM

Hello Debtboy
I was on mepis this morning walking through the line commands as per your example. Not so intimidating after you see the logic in what its doing. Its not that much differant than dos commands which also uses switches.
The permissions are important. They can be a real head scratcher. :O

Again thanks for sharing


debtboy 24. May 2009 04:18 PM

Thanks for the positive feedback,
I've never tried explaining this stuff before.


here is a typical example of a ls -l listing:
drwxr-xr-x 2 debtboy users 4096 2009-05-23 20:17 Documents

d This character means directory, you might see - (file), l (link) or d (directory)

Now you have 3 sets of 3 permissions each, always in the exact same order.
The 3 permissions are rwx (Read, Write, Execute) and they can be in any combination, the - hyphen means you don't have this permission.

rwx The first set of 3 are owner permissions, if you created the file you are the owner.

r-x The second set of 3 are group permissions, everyone in the group will have these permissions unless your the owner which gives you additional permissions.

r-x The third 3 are other permissions, I like to think of these permissions as everyone else.

In the listing above you have the owner debtboy
then you also have the group users
so you can determine who has what permissions
(no who is on first :p, what's on second :p Ha! Ha! Ha!)

There are 3 basic manipulation commands:
chown Which changes the owner
chgrp Which changes the group
chmod Which can change permissions for all 3 (owner, group, other)

We are only worried about permissions in this post so:
There are different ways use chmod so I will go over how I use it.
Permissions equate to numbers (octal actually)
r equates to a 4
w equates to a 2
x equates to a 1

I give 3 numbers after chmod the first for the owner, the second for the group and the third for other.

Just add up the equated numbers of the permissions you wish to grant.

For example (using the same listing above):

chmod 777 Documents would produce:

chmod 724 Documents would produce:
drwx-w-r-- (not your typical permissions but a good example)

The 7 is really rwx or (4 read + 2 write + 1 execute)
A 6 is really rw- or (4 read + 2 write)
A 5 is really r-x or (4 read + 1 execute)
A 4 is really r-- or (4 read)
A 3 is really -wx or (2 wite + 1 execute)
A 2 is really -w- (2 write)
A 1 is really --x (1 execute)
A 0 is really --- or no permissions

All permissions can be manipulated by the user root (all powerful OZ!!) :eek:

This was just a basic overview of permissions (no extended details to confuse),
I'll show 4 images in my next post,
sometimes a picture is worth a thousand words.

debtboy 24. May 2009 05:04 PM

Permissions w/ Images
Open up a console/terminal and you should be in your home directory.
If not that would be easy enough to fix cd ~/ remember.

I'm using your home directory, because this is where you have
permission to change permissions (if that makes sense??).
If we were elsewhere in the OS then we would need to
be the user root (all powerful OZ!!) to change permissions.

As you can see from the image, I've done a ls -l command

See the change in permissions for Documents.

Now I've done a chmod 777 Documents command
Keep in mind the following are the same commands:
chmod 777 /home/debtboy/Documents
chmod 777 ~/Documents

Here is the result:

See the change in permissions for Documents.

Now I've done a chmod 724 Documents command
so the defined permissions were assigned to the directory.
Did I say directory... yes I did!!
I like to think of it as Linux treats everything as a file,
the hard drive, cdrom drive, directories, etc.. (everything as a file)

Here is the image:

See the change in permissions for Documents.
Practice will make these commands almost second nature.

Now just for fun, make sure your in you home directory pwd
if not get there you know how...
now type in firefox and hit enter, I believe this will work on most current distros depending on configuration.
Did the browser pop up??? (from the command line, Ha! Ha! Ha!)

bk_7312 25. May 2009 10:29 AM

I was understanding them well enough to navigate using Konsole using cd, ls - l etc but you kinda lost me on the second part, the part with drwxr stuff. Still, I was able to launch Firefox from Konsole, I got this great feeling when Firefox popped out.

I found that you can type in ls -1 to list directories a bit similar to ls -l but less informative by accident:D.

Thanks for sharing this cool piece of info!

debtboy 25. May 2009 03:55 PM

Viewing a file's contents
Hi everyone,

Now that your starting to move around the filesystem with cd,
list files with ls, you may want to view the contents of some of these files.
I generally use more but there are some who prefer less,
either way you can view the contents of selected files which is very handy!!

The key word here is view, so you can NOT change the contents of
any of these files as you could with an editor like vi or emacs.

First lets create a text file named my_text.txt
The .txt extension is meaningless in Linux, but I'm sure
long time Windows user's feel better with it there.

Try this command:
echo "this is a test file" > my_text.txt

Now lets do a listing ls -l and see the file we just created.

Notice that default permissions were issued to the file automatically.

Now lets look inside the file we created.
more my_text.txt

The contents of the file are dumped right into the console.
If you looking at a file that's larger than the console window
you can navigate the same as you would with man pages (Linux manual)
enter key to scroll through line by line
spacebar to scroll page by page
q to quit out of viewing

Now you can change directories cd, list files ls
and view the contents of those files with more.
Start looking around the filesystem and start view the contents of files.
Don't try to view binary files which are normally located in /bin or /sbin directories.

more is especially useful for viewing network config files located in /etc
Try this to view the contents of your resolv.conf file which should call out
the DNS nameservers. (ref: other post about openDNS)
more /etc/resolv.conf

more is used to view files, to make changes you will need permissions and an editor.

debtboy 25. May 2009 05:47 PM

root su sudo
Hi everyone,

As you move around the filesystem and view the contents of files
with more, you will eventually run into permission issues.
For example there is a file /etc/sudoers that can only be viewed by root (all powerful OZ!!!).

First we'll cd /etc then ls -l sud* notice the (*) it's a wildcard.
In english I'm asking to change the directory to /etc and then
I want a listing of everything starting with sud

Now I try to view this file with more and WTH!!!
Notice the permissions, according to those permissions,
Only root or anyone in the root group can read this file.
If this doesn't make sense read Permissions a few posts back on this thread.

So I need root permissions to view this file...
There are many ways to handle this, but I'm going to demonstrate 2.
sudo this is a good way to substitute the user on a command by command basis
The user is based on the sudoers file (the very one we're trying to open),
but root is the default.

sudo more sudoers
It will ask for the root password, once supplied it will execute as root and you will remain as your normal user.

Now I'm kind of old school, and I have always used the su command.
The su command allows you to become any (substitute user) and remain that
user until your finished.
For example:
su root allows you to become root after the root password is supplied.
You are now root and can do anything within the system, BE CAREFUL!!!

There is no protection from root messing the system up
so proceed with caution as the root user.

Let's say you finished being root and want to return as your normal user...
just type exit in the console and you will exit root and be the normal user again.
If you get confused as to who you are because of su,
just type whoami and it tells you who you are logged in as.
For networking purposes, who shows you everyone who is logged into the system.

We need to start combining commands soon, and using pipes.
Once you get used to piping, you'll understand how linux can
be much easier to use than Windows (Ha! Ha! Ha!).

Any question so far??
I'm not very good at explaining things.

wdhpr 27. May 2009 02:09 AM

Thanks debtboy
I think you have done a great job on this thread. I have read it carefully and Learned some really cool and powerful stuff. As you also caution, one MUST be careful using it

again thanks


debtboy 28. May 2009 01:14 AM

wget grep pipe
OK Everyone,

Before we get into the pipe...
Here are a few more standard commands you might already be using:
cp (copy)
rm (remove)
mkdir (make directory)
rmdir (remove directory)
mv (move)
find (find pattern)
sort (sort)
Look them up in the man pages.

Now lets look at wget (web get)
wget allows you to extract files/webpages from the internet,
and save them locally. It will recursively extract the hierachy of
files and directories in a domain name and also follow links.
It does respect the robots.txt file.

Now I know what your thinking and yes you could put this command into a
subnet loop and your 3/4's of the way through creating a robot or spider,
but that is not what it was designed for so it's not very fast.

I'm going to extract the default page of
from my Linux command line and for purposes of demonstration, I'm going
to force the output into this terminal instead of saving the file.
Now here is the command:
wget -qO - ""
The options I'm using are quite mode and file output to - the terminal
This is the very same command with the options/switches separated:
wget -q -O - ""

Now if you've been following this thread, yes I changed my background.
It's one of those free ones from Digital Blasphemy.

Now here is some of the output from that command, it's really about 13 pages long.

On to grep, I use this command quite often to extract matching patterns within files and I also use it to count occurrences within the input.

Here I'm going to pipe the output of wget directly into the input of
grep using the pipe character (it looks like 2 hyphens turned vertical on the keyboard).
grep will extract all lines with the pattern <title>

wget -qO - "" | grep -e "<title>"

Here is the result of that piped command:

This was only a single pipe, but you can have multiple pipes connecting
many outputs to inputs which is called what else... a pipeline.

I know what your thinking, you could create a bot looping through subnets
extracting anything with an "@" for email addresses. Yes it's possible,
but we've decided to use what we've learned for good and not evil!!

Hope this post wasn't too confusing...
Are you begining to see the power of the command line yet??
We haven't even created a script or even mentioned PERL.

debtboy 31. May 2009 10:08 PM

compile and install from source
OK, how about we install a 3rd party application from source.

First of all, you should always install software from packages (.rpm, .deb, etc...),
Packages automatically take care of dependencies.
Packages are usually available for most mainstream applications, but not all.

If a package isn't available for download, or your distro package doesn't match
what's available, then installing from source is always an option.

Source is almost always available, can be compiled on most systems
and is usually always in a zipped file tar.gz or tar.bz2
It's actually zipped (gzip) tar (tape archive) file, typically referred to as a tarball.

So lets get started...
I've chosen a third party application called conky (evolved from torsmo).
Here is the download link:

Clicking the Latest Release "Get Conky" takes you to the page below.
We want the conky-1.7.0.tar.gz file.

save the file to your home directory.

No lets look at the downloaded package with ls -l

see next post

debtboy 31. May 2009 10:26 PM

Now it's time to unarchive these files.
Use the following command
tar -xvf conky.1.7.0.tar.gz

It should start unpacking...
many directory and file names will scroll by.

Now so you can see,
clear which will clear the screen and do a
ls -ld conky* I've added the d so it would list the directory
and not the contents of the directory and the conky* will list
starting with conky.
We see the original tarball and a new directory

Now we'll enter that directory cd conky-1.7.0
We expect a README and INSTALL file for additional instructions
from the author.

see next post

debtboy 31. May 2009 10:37 PM

Now we do a listing of the new directory ls,
I'm not using the -l long format, because I want to see all the files.

Now we do a more README, the person who created the files
might leave special instructions for configuring or compiling the files.

Here I've scrolled down to a more important part of the file.

I don't see anything special, so lets move on.
It's time to run the configure file.
try ./configure the ./ just say the directory your currently in.

see next post

debtboy 31. May 2009 10:49 PM

When running the config file, any dependency or other problems
will be displayed. It checks your system for everything it needs.
If it needs something like a compiler, it will tell you now.

Running the config didn't turn up any problems for me (see image).

Here I've just scrolled down to the bottom

Now I need to become root, only root can install software.
su root
then I ran clear to clear the screen.

It's time to compile the source code.
make that's all it takes to compile.

You will see all kinds of text scroll by.

see next post

debtboy 31. May 2009 10:56 PM

Now I normally clear the screen and run:
make install that's all it takes to install the program.

Again lots of text scrolling by.

Now I again clear the screen, and run:
make clean which cleans up all the temporary files and such.

Guess what... more text scrolling by (Ha! Ha! Ha!)

see next post

debtboy 31. May 2009 11:26 PM

Now lets see if it works,
exit root, making your the regular user.
Type conky and hit enter to see if it works.

A display of PC information should appear on your desktop.

To end the program I just enter <ctrl> c in the shell.

The conky program can be configured to run many different ways,
(I think, this is the first I've used it)
but this post was about installing from source not how to use conky.

It's not difficult to install from source, here is a summary:

1.) download tarball (*.tar.gz)
2.) unarchive using tar -xvf filename
3.) Enter directory and read README (possible special instructions)
4.) run ./configure
5.) switch to root
6.) run make
7.) run make install
8.) run make clean optional

No big deal, it's easy.

make uninstall to remove it, provided you kept your makefile
For info on make, check the man pages.

I've left out minor details and such as this was only
an introduction. Hope it was easy to understand.

This thread went over some of the basics to get you started,
now it's fun time!! :D

wdhpr 02. Jun 2009 01:37 AM

Great tutorial
This was going really great until the ./configure part. I then got this error


checking for X... no
configure: error: Can't locate your X11 installation
I am using mepis and only have the basic x11 package installed. Looked for the x installation pkg. thinking it might be a x package i could install. No joy :(
I will try to install another source package

PS again.........great tutorial :)

debtboy 02. Jun 2009 02:17 AM


Originally Posted by wdhpr (Post 5990)
This was going really great until the ./configure part. I then got this error

I am using mepis and only have the basic x11 package installed. Looked for the x installation pkg. thinking it might be a x package i could install. No joy :(
I will try to install another source package

PS again.........great tutorial :)

Wow, sorry to hear that.
You are right about the x package, but it is a development library you need.
I'm not familiar with Mepis, but you should be able to install the needed library through synaptic.
It will have (x or x11 or xorg or libx) and (devel or develop or dev) in the name.

When things break or don't work is when we learn the most! ;)

wdhpr 02. Jun 2009 11:25 PM

Hey guy

Its hard trying encompass all the variables when writing things like this. Its like trying to make something human proof and knowing its impossible. I understand the library part of your response. Again not too different from Amiga's library requirements. I sometimes wonder if any of Amiga's scripting was used in the development of the Linux kernel.


debtboy 03. Jun 2009 01:00 AM

Well, packages do simplify installs and if you get a large full blown distro
most everything you'll need will already be included.
Just install as needed via package manger.

This was only a How-To with screenshots,
showing that you can install apps directly from source code.

There doesn't seen to be much activity here in the
Linux portion of the forum. :confused:

Twenty years from now people will laugh, saying...
These were the horrible years of,
Windows Operating Systems :eek: and Rap music :eek:

wdhpr 03. Jun 2009 02:32 AM

Keep the Faith
You were very correct about the library thing.

I don't want anyone to think Microsoft is bad. "Their not" I want people to think linux is as well, also good. Microsoft ......... They are truly the pioneers. On the other hand........Linux ..... Its mostly used as servers. I want the world to want what it wants.
I want people to think for themselves.

PS Conky is a nice app. Kde has something very similar.


All times are GMT +1. The time now is 07:36 AM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2020, vBulletin Solutions, Inc.