Tuesday, May 11, 2010

Linux 第一天

第一天当然是 ls 命令啦

ls [options] [names]

List contents of directories. If no names are given,list the files in the current directory.

The most useful options include -F, -R, -l, and -a. Some options don't make sense together(e.g.,-u and -c).

Options

-F,--classify,--indicator-style=classify
Flag filenames by appending:
/ to directories
* to executable
@ to symbolic links
| to FIFOs
= to sockets

-R,--recursive
List directories and their contents recursively

-l,--format=long,--format=verbose
Long format listing(includes permissions,owner,size,modification time,etc.).
for example:


total 36
drwxr-xr-x 2 royer royer 4096 2010-03-07 19:42 Desktop
drwxr-xr-x 2 royer royer 4096 2010-03-07 19:42 Documents
drwxr-xr-x 2 royer royer 4096 2010-03-07 19:42 Downloads
-rw-r--r-- 1 royer royer 167 2010-03-07 19:36 examples.desktop
drwxr-xr-x 2 royer royer 4096 2010-03-07 19:42 Music
drwxr-xr-x 2 royer royer 4096 2010-03-07 19:42 Pictures
drwxr-xr-x 2 royer royer 4096 2010-03-07 19:42 Public
drwxr-xr-x 2 royer royer 4096 2010-03-07 19:42 Templates
drwxr-xr-x 2 royer royer 4096 2010-03-07 19:42 Videos

This listing shows considerable information about every directory entry --- each of which can be a file or another directory. Looking at a line from the right column to the left,you see that the rightmost column shows the name of the directory entry.The date and time before the name show when the last modifications to that file were made.To the left of the date and time is the size of the file in bytes.

The file's group and owner appear to the left of the column that shows the file size.The next number to the left indicates the number of links to the file.(A link is like a shortcut in Windows.)Finally,the leftmost column shows the file's permission settings,which determine who can read,write,or execute the file.

The first letter of the leftmost column has a special meaning,as the following list shows:
  • l,the file is a symbolic link to another file.In other words,it's a shortcut to something else.
  • d,the file is directory.It will appear as a folder in GUI.
  • -,the file is normal.
  • b,the file represents a block device,such as a disk drive.
  • c,the file represents a character device,such as a serial port or a terminal.
After that first letter,the leftmost column shows a sequence of nine characters, which appear as rwxrwxrwx when each letter is present.Each letter indicates a specific permission.A hyphen (-) in place of a letter indicates no permission for a specific operation on the file.Think of these nine letters as three groups of three letters (rwx), interpreted as follows:
  • the leftmost group of rwx controls the read,write and execute permission of the file's owner.Although executable programs(including shell programs) typically have execute permission,directories treat execute permission as equivalent to use permission: A user must have execute permission on a directory before he or she can open and read the contents of the directory.
  • The middle three rwx letters control the read,write and execute permission of any user belonging to that file's group.
  • The rightmost group of rwx letters controls the read,write and execute permission of all other users(collectively thought of as the world).
Thus,a file with the permission setting rwx------ is accessible only to the file's owner,whereas the permission setting rwxr--r-- makes the file readable by the world.

-a,--all
List all files,including the normally hidden files whose names begin with a period.

-A,--almost-all
List all files,including the normally hidden files whose names begin with a period.Does not include the . and .. directories.

-h,--human-readable
Print sizes in kilobytes and megabytes

No comments:

Search This Blog