Site Logo
October 8, 2025
Wednesday   12:36 AM
 
 
 
 
 
 
 
 
 Introduction to Linux
It's simple really, a touch of DOS done the right way, a windows GUI for those not comfortable in the drivers seat, and the power of the Sun, pun intended.
How do I log in?
At the login prompt, enter your username if you have one. Otherwise type root. You'll then be prompted for a password, so enter that too.
linuxhost login: myusername
Password: mypassword
[myusername@linuxhost ~] $
How do I get a directory listing?
[myusername@linuxhost ~] $ ls
anaconda.ks.cfg   Desktop   install.log   minicom.log   sysstatus   tmp
The ls (list) command will show all the (non-hidden) files in the current directory. Very little information is presented, although the color does mean something on some Linux releases. Regular files are normally in a black font, subdirectories are blue by default. Executables (files with the execution bit set) are light green. There are other colors, all described in /etc/DIR_COLORS.

And yes, Linux is case-sensitive.

We'll expand on directory listings later in this page.
How do I change directories?
[myusername@linuxhost ~] $ cd newdir
[myusername@linuxhost newdir] $
The cd command will get you where you want to go. If you type it without a directory argument you'll wind up in your home directory. This is both a blessing and a curse, so be careful.

Notice that the last string in the brackets changed to the new directory name, this is a good way to keep up with where you are. Also, the '~' in the same position only means you are in your home directory.

You DOS and windows guys will need to reprogram your fingers to use the forward slash '/' as a directory separator instead of the backwards DOS method '\'.
How do I find out how a command works?
Look at its manual page.
[myusername@linuxhost ~] $ man ls
This will give you the manual page for the ls command. The man pages are arranged in groups based on the type of function or programming where it applies. The command above pulls the man page from section 1 by default. Section 1 is the user's section. Section 2 is the programmer's reference:
[myusername@linuxhost ~] $ man 2 chdir
will display the C language particulars for the chdir C function.
How do I found out what commands are related to an operation or device?
[myusername@linuxhost ~] $ apropos conf
.netrc (5)     -   user configuration file for ftp
/etc/ncsd.conf   (5)     -   name server cache daemon configuration file
mysql_config (1)     -   get compile options for compiling clients
next 283 lines ignored...
This searches through the man page database and lists everything related to the keyword 'conf'. With many commands you'll get a large list. The second column in the output tells you which section of the man pages where the entry was found, (1) for user commands, (5) for configuration data, (8) for admin commands, etc.
File and Filesystem Permissions

Linux (and UNIX, BSD, Solaris) are all based on the idea that a file's owner, group, and everyone else have different access needs. The simple overview is that there are different permissions for reading a file, writing a file, and executing a file; and there are three user types with each of these three permissions.

The file's owner can read, write and/or execute the file.
Members of the file's group can read, write and/or execute the file. 
Everyone else can read, write and/or execute the file.
If a user type does not have permission to r/w/e the file, then they cannot access it for that purpose. In the current state of our system we can't write the newly created file into the directory. To access a directory we must have permission to execute it. I know, it sounds weird, but that's one function of a directory, to collect/hold/organize files. To use that particular function you must be able to excute it. Clearer now?

Bring up a terminal shell on your desktop. Typically this will be a right-click on the desktop labeled something like "Open Terminal". When you see the prompt, type ls to get a simple directory listing.

[bob@linuxhost ~]$ ls
Desktop  Documents  Downloads  file.txt
The words in bold are directories, the not-so-bold is a filename. No hidden files are displayed. Now type ls -a to get a simple directory listing of all files and folders.
[bob@linuxhost ~]$ ls -a
. .. .bash_history .bash_logout .bash_profile .bashrc Desktop  Documents  Downloads  file.txt
The words in bold are still directories, the not-so-bold filename. This time the hidden files are displayed. They are named with a period at the start of the name like .bashrc. These are typically used for configuration and system files. The ls command doesn't show hidden files by default. Adding the option '-a' to the command tells ls to display 'all' files.

Let's expand a little. Let's look at a 'long' directory list. Type ls -al. You should see something like:

[bob@linuxhost ~]$ ls -al
total 16
drwxr-xr-x 2 bob bob   4096 Jan 21  2009 .
drwxr-xr-x 8 root root 4096 Jul  1 23:31 ..
-rw------- 4 bob bob   2189 Oct 21 10:15 .bash_history
-rw-r--r-- 4 bob bob     18 Oct 21 10:15 .bash_logout
-rw-r--r-- 4 bob bob    141 Oct 21 10:15 .bash_profile
-rw-r--r-- 4 bob bob    492 Oct 21 10:15 .bashrc
drwxr-xr-x 4 bob bob   4096 Oct 21 10:15 Desktop
drwxr-xr-x 4 bob bob   4096 Oct 21 10:15 Documents
drwxr-xr-x 4 bob bob   4096 Oct 21 10:15 Downloads
-rwxrwxrwx 4 bob bob    256 Oct 21 10:15 file.txt
This apparent gobbledygook is good information provided you understand what the fields mean. The first line can be ignored for now. The rest of the lines are important.
Note that they have 9 seperate (whitespace delimited) fields the way they are displayed.

The first field (drwxr-xr-x) is the file permissions field. Don't worry about the filename yet, we'll get to that.

There are 4 main components within the file permissions field. The first character 'd' tells us this points to a directory or a standard file '-' in the example, or several forms of special file not discussed here.

There next three fields are repetitions of the Read, Write, eXecute permissions described earlier.
The first block of three 'rwx' are for the file's owner.
The second block of three 'r-x' are for members of the group. The third block of three 'r-x' are for everyone else.

If the character shows a dash (-), then that permission is disabled for that collection of users. In the example above the owner (rwx) can read, write and execute the directory. The group and others are allowed only to read and execute.

Key Takeaway: Remember the orders: Read-Write-eXecute, and Owner-Group-Everyone

So who owns the file or directory? The 3rd and 4th fields both say 'root'. The 3rd field is the owner's name, and the 4th field is the name of the group.

-rwxrwxrwx 4 root   root  256 Oct 21 10:15 file.txt
             ^owner ^group

So who am I and what group am I associated with? Sounds like a '60s flashback, but let's answer these age-old questions so you can find yourself.

[bob@linuxhost ~]$ whoami
bob
[bob@linuxhost ~]$ groups
bob apache
Maybe that's not quite the existential resolution you were hoping for but it is quite useful when running a server. By default every account will be a member of a self-named group. In the example, bob is also a member of the apache group, so bob can read and write files with apache group permission.

Try this, and type in your root password when prompted:

[bob@linuxhost ~]$ su -
Password:
[root@linuxhost ~]#

Several key things to notice. The prompt changed reflecting the new user (root) and the new current directory (~). The tilde means you are now in root's home directory. The dash (-) in the su command means to source the user's entire envinronment not just substitute the new user's identity. Had you left off the dash (-), the prompt would be root@www html]# instead. Minor pont at this case, but I always use su - to make sure I adopt root's PATH.

So cd /var/www/html/ to get back to where you want to work for now. Type the following commands exactly as listed:

[root@linuxhost ~]# cat > myinfo.php
<?php
phpinfo();
?>
Then type a Control-D to end the file. This should bring up a prompt: [root@www html]# . Congratulatiuons, you just created a new file using some high falutin' console redirection! Don't worry, let's go see what happened.
[root@linuxhost ~]# ls -al
total 28
drwxr-xr-x 2 root root 4096 Jan 21  2009 .
drwxr-xr-x 8 root root 4096 Jul  1 13:31 ..
-rw-r--r-- 1 root root   20 Jul  1 14:22 myinfo.php
Ah, now the location of the filename field is obvious. And now we know that root owns it and has read and write permission, and that everyone else (including the root group) can only read it. More detail on the output: the 20 is the filesize in bytes and the date and time are the modification time and date. The '1' after the permissions on the new file is the number of inodes associated with the file. Don't worry about it, that will be in the Advanced Linux section. For now, think of is as related to the size of the file. The '20' in field 5 is the byte count filesize. The 4096 bytes in field 5 for the directories is how large the record is to contain the directory information.

This all begs the question, so what are the (.) and (..) in the filename entries for the directories? Simple, (.) is a generic shorthand for the current directory and (..) is shorthand for one directory level up. In this case, . refers to /var/www/html/ and .. refers to /var/www/ NOTE: These are always relative paths, they always refer to the current directory and one above it. You can't move somewhere else and expect . to refer to /var/www/html/

So what do we do with this lengthy discussion? Let's change the permissions to allow user 'bob' to write into the directory.

There are several ways to enable bob, we could open up the permission and let anyone write into the directory, obviously less than optimal from a security standpoint. We could add bob to the root group, again, not a very secure thing to so. We could give bob permission to write to one single file, that's not too bad, so here's the way this will work. Let's move the new file to bob.php and give bob complete ownership of it.

[root@linuxhost ~]# cp myinfo.php bob.php
[root@linuxhost ~]# chown bob bob.php
[root@linuxhost ~]# ls -al bob.php
-rw-r--r-- 1 bob root 20 Jul  1 14:25 bob.php
This all assumes you have a user account named bob. If not, use your own normal (non-root) account name for the argument in the chown command: chown your-username bob.php.

So in closing, go back to the gedit editor and close the file without saving it. Open up the new file (bob.php) and modify it to your heart's content. You should be able to save it as /var/www/html/bob.php

Bonus: (needs verified) How can I run a shell command to burn a CD?
[myusername@linuxhost ~] $ cdrecord -v -tao -data speed=8 \ dev=/dev/hdc image.iso

OR

In Nautilus or the file browser:
right click on "image.iso" and select "Write to Disc..."
"If politicians don't respect the law, why should citizens respect politicians?"
- Debra Saunders
 
 
 
 
 
all original content ©1994-2025 Yes, that means 30+ years on the web
An exercise in truly free free-speech. No license required, no training wheels available.
"When words lose their meaning, people will lose their liberty." -- Confucius
vincit omnia veritas