You are on page 1of 7

Linux Lesson 2

From digitalb0y
Filesystem Layout:
/home personal User data similar to /Users on windows
/etc all your configuration files
/var system logging /mail /print spooling.
/bin core user binary programs (used to booting system)
/sbin core Super User binary programs (used to booting system)
/usr/bin User binary programs
/usr/sbin - Super User binary programs
/opt/ - Third party software
Special directories
/dev -Device files of system hardware.
/proc Special files on containing information about system resources.
Navigation the shell prompt

pwd -

Shows the present working directory

[digitalb0y@linuxbox ~]$ pwd


/home/digitialb0y

cd

change directory

[digitalb0y@linuxbox ~]$ cd /usr/X11R6/bin6/bin


[digitalb0y@linuxbox bin]$ pwd
/usr/X11R6/bin
[digitalb0y@linuxbox bin]$ ls
Animate
AnotherLevel
Audio
Auto
Banner
Cascade
Clean
Form
Ident
Pager
Pager_noxpm

import
lbxproxy
listres
lndir
makedepend
makeg
mergelib
mkdirhier
mkfontdir
mkxauth
mogrify

xfwp
xg3
xgal
xgammon
xgc
xgetfile
xgopher
xhexagons
xhost
xieperf
xinit

RunWM
RunWM.AfterStep
RunWM.Fvwm95
RunWM.MWM

montage
mtv
mtvp
nxterm

xiterm
xjewel
xkbbell
xkbcomp

Important facts about file names


1. File names that begin with a period character are hidden. This only means that ls will not list them unless
you say ls -a. When your account was created, several hidden files were placed in your home directory
to configure things for your account. Later on we will take a closer look at some of these files to see how
you can customize your environment. In addition, some applications will place their configuration and
settings files in your home directory as hidden files.
2. File names in Linux, like Unix, are case sensitive. The file names "File1" and "file1" refer to different files.
3. Linux has no concept of a "file extension" like legacy operating systems. You may name files any way you
like. The contents/purpose of a file is determined by other means.

4. While Linux supports long file names which may contain embedded spaces and punctuation characters,
limit the punctuation characters to period, dash, and underscore. Most importantly, do not embed
spaces in file names. If you want to represent spaces between words in a file name, use underscore
characters. You will thank yourself later.

Looking Around
Now that you know how to move from working directory to working directory, we're going to take a tour of your
Linux system and, along the way, learn some things about what makes it tick. But before we begin, I have to teach
you some tools that will come in handy during our adventure. These are:

ls (list files and directories)


more and less (view text files)

ls
The ls command is used to list the contents of a directory. It is probably the most commonly used Linux
command. It can be used in a number of different ways. Here are some the switches

-l
-R
-r

Shows the long format list


Recursively list subdirectories encountered.
Reverse the order of the sort to get reverse lexicographical order
or the oldest entries first (or largest files last, if combined with
sort by size

-S

Sort files by size

-s

Display the number of file system blocks actually used by each file,
in units of 512 bytes, where partial units are rounded up to the
next integer value. If the output is to a terminal, a total sum for
all the file sizes is output on a line before the listing. The
environment variable BLOCKSIZE overrides the unit size of 512 bytes.

-T

When used with the -l (lowercase letter ``ell'') option, display


complete time information for the file, including month, day, hour,
minute, second, and year.

-t

Sort by time modified (most recently modified first) before sorting


the operands by lexicographical order.

-u

Use time of last access, instead of last modification of the file


for sorting (-t) or long printing (-l).

-U

Use time of file creation, instead of last modification for sorting


(-t) or long output (-l).

-v

Force unedited printing of non-graphic characters; this is the


default when output is not to a terminal.

-W

Display whiteouts when scanning directories. (-S) flag).

-w

Force raw printing of non-printable characters. This is the default


when output is not to a terminal.

A Closer Look At Long Format


If you use the -l option with ls, you will get a file listing that contains a wealth of information about the files being
listed. Here's an example:

-rw-------

1 bshotts

bshotts

drwxr-xr-x

6 bshotts

bshotts

-rw-rw-r--

1 bshotts

bshotts

-rw-------

1 bshotts

bshotts

----------

-------

-------

576 Apr 17
1024 Oct

1998 weather.txt

1999 web_page

276480 Feb 11 20:41 web_site.tar


5743 Dec 16

1998 xmas_file.txt

-------- ------------ -------------

File Name

+---

+-------------

+-----------------------

Group

+--------------------------------

Owner

Modification Time

Size (in bytes)

|
+----------------------------------------------

File Permissions

File Name
The name of the file or directory.
Modification Time
The last time the file was modified. If the last modification occurred more than six months in the past, the
date and year are displayed. Otherwise, the time of day is shown.
Size
The size of the file in bytes.
Group
The name of the group that has file permissions in addition to the file's owner.
Owner
The name of the user who owns the file.
File Permissions
A representation of the file's access permissions. The first character is the type of file. A "-" indicates a
regular (ordinary) file. A "d" indicates a directory. The second set of three characters represent the read,
write, and execution rights of the file's owner. The next three represent the rights of the file's group, and the
final three represent the rights granted to everybody else.

more
More is a program that lets you view text files This is very handy since many of the files used to control and
configure Linux are human readable.
more filename

less
less is like more. However ever to does additional things, so less is more :).

Controlling less
Once started, less will display the text file one page at a time. You may use the Page Up and Page Down keys to
move through the text file. To exit less, type "q". Here are some commands that less will accept:

Manipulating Files
This lesson will introduce you to the following commands:

cp - copy files and directories similar to dos's copy.


mv - move or rename files and directories similar to dos's move.
rm - remove files and directories similar to dos's delete.
mkdir - create directories similar to dos's mkdir.
These four commands are among the most frequently used Linux commands. They are the basic commands for
manipulating both files and directories.
Some of the tasks performed by these commands are more easily done with a graphical file manager. With a file
manager, you can drag and drop a file from one directory to another, cut and paste files, delete files, etc. So why
use these old command line programs?
The answer is power and flexibility. While it is easy to perform simple file manipulations with a graphical file
manager, complicated tasks can be easier with the command line programs. For example, how would you copy all
the HTML files from one directory to another, but only copy files that did not exist in the destination directory or
were newer than the versions in the destination directory? Pretty hard with with a file manager. Pretty easy with the
command line:

man

Standard Output
Most command line programs that display their results do so by sending their results to a facility called standard
output. By default, standard output directs its contents to the display. To redirect standard output to a file, the ">"
character is used like this:
ls > file.txt
Now lets view the file using less
less file.txt

Now we will run


ls -l >> file.txt
Now lets view the same file again
less file.txt
as we see Using two appends the file.

This function works with any command that displays output.

Next up MAN PAGES


man {program name}
example:
man pwd

All man pages have a common format. They begin with name (the name of the command) and a brief
description of what it does. For example the pwd command shows the following:

NAME
pwd -- return working directory name
SYNOPSIS
pwd [-L | -P]
DESCRIPTION
The pwd utility writes the absolute pathname of the current working directory to the standard
output.

Next comes synopsis, which shows the command any any options, or flags, that you can use with it.
For pwd, there are two options: -Land -P. These options are explained in the description section:
s you can see here, each of the two options is explained, and a final sentence tells you that the command
assumes that the -Loption is desired if no other option (and theres only one) is specified.
As you work from the command line, youll find that reading up on the options available for different
commands is really important. Youll learn the myriad ways you can use these tools, and some manpages
also contain examples to help you understand them.

There are MAN files for just about every program you can find.
Next Up Package Management:
Some parts
Ref http://linuxcommand.org/

You might also like