linux lesson 2

7
Linux Lesson 2 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 import xfwp AnotherLevel lbxproxy xg3 Audio listres xgal Auto lndir xgammon Banner makedepend xgc Cascade makeg xgetfile Clean mergelib xgopher Form mkdirhier xhexagons Ident mkfontdir xhost Pager mkxauth xieperf Pager_noxpm mogrify xinit RunWM montage xiterm RunWM.AfterStep mtv xjewel

Upload: james-stokes

Post on 18-Jul-2016

216 views

Category:

Documents


0 download

DESCRIPTION

Lesson for my friends at WP.

TRANSCRIPT

Page 1: Linux Lesson 2

Linux Lesson 2

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 softwareSpecial 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 import xfwp

AnotherLevel lbxproxy xg3

Audio listres xgal

Auto lndir xgammon

Banner makedepend xgc

Cascade makeg xgetfile

Clean mergelib xgopher

Form mkdirhier xhexagons

Ident mkfontdir xhost

Pager mkxauth xieperf

Pager_noxpm mogrify xinit

RunWM montage xiterm

RunWM.AfterStep mtv xjewel

Page 2: Linux Lesson 2

RunWM.Fvwm95 mtvp xkbbell

RunWM.MWM nxterm xkbcomp

Important facts about file names1. 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 AroundNow 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)

lsThe 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 Shows the long format list

-R Recursively list subdirectories encountered.

-r 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,

Page 3: Linux Lesson 2

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:

Page 4: Linux Lesson 2

-rw------- 1 bshotts bshotts 576 Apr 17 1998 weather.txt

drwxr-xr-x 6 bshotts bshotts 1024 Oct 9 1999 web_page

-rw-rw-r-- 1 bshotts bshotts 276480 Feb 11 20:41 web_site.tar

-rw------- 1 bshotts bshotts 5743 Dec 16 1998 xmas_file.txt

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

| | | | | |

| | | | | File Name

| | | | |

| | | | +--- Modification Time

| | | |

| | | +------------- Size (in bytes)

| | |

| | +----------------------- Group

| |

| +-------------------------------- Owner

|

+---------------------------------------------- File Permissions

File NameThe name of the file or directory.

Modification TimeThe 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.

SizeThe size of the file in bytes.

GroupThe name of the group that has file permissions in addition to the file's owner.

OwnerThe name of the user who owns the file.

File PermissionsA 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.

moreMore 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

Page 5: Linux Lesson 2

lessless 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 FilesThis 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 thecommand line:

man

Standard OutputMost 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 lessless file.txt

Now we will runls -l >> file.txt

Page 6: Linux Lesson 2

Now lets view the same file againless 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 there’s only one) is specified.

As you work from the command line, you’ll find that reading up on the options available for different commands is really important. You’ll 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.

Page 7: Linux Lesson 2

Next Up Package Management:

Some parts Ref http://linuxcommand.org/