h4

The system differentiates between uppercase and lowercase letters, unlike DOS.

 

Having ls Tell You More

$ ls -s                   indicate the file size

$ ls -s [filename1 filename2...]

$ ls -a                   contains more dot files than regular files and directories

$ ls -F                  appends suffixes to certain filenames so that you can ascertain more easily

 

what types of files they are

       /      mail/       directory

       *     prog*     executable program

       @   bin@      a symbolic link to another file or directory

 

$ ls -m                  outputs the files as a comma-separated list. If there are many files, -m can be a quick and easy way to see what’s available.

$ ls -1

 

-a    List all files, including any dot files.

-F   Indicate file types; / = directory, * = executable.

-m   Show files as a comma-separated list.

-s    Show size of files, in blocks (typically, 1 block = 1,024 bytes).

-C   Force multiple-column output on listings.

-1    Force single-column output on listings.

 

Very few UNIX commands care about the order in which flags are listed. Because it’s the presence or absence of a flag that’s important, listing a flag more than once doesn’t make any difference.for instance, ls -sss -s

 

Listing Directories Without Changing Location

$ ls [path1 path2...]

$ ls -m ..

$ ls -s ../../

 

$ ls -s [path1 path2...]

$ ls -ds [path1 path2...]

To list a file or directory, you can specify it to ls. Directories, however, reveal their contents, unless you also include the -d flag.

 

Special ls Command Flags

Changing the Sort Order in ls

$ ls -a            column-first order

$ ls -ax          row-first order

$ ls -at           most-recently-accessed-first order

$ ls -r            reverses any sorting order

 

Listing Directory Trees Recursively in ls

$ ls -R           lists the current directory and then alphabetically lists the contents of all subdirectories

 

Viewing all files and directories below a certain point in the file system can be a valuable way to look for files (although you’ll soon learn better tools for finding files). If you aren’t careful, though, you may get hundreds or thousands of lines of information streaming across your screen. Do not enter a command like ls -R / unless you have time to sit and watch information fly past.

 

Long Listing Format in ls

$ ls -l

drwxr-xr-x           6     miscall           miscall           512 Jul 25  2008                     boss

access permission links       owner            group            size  access times and dates        filename

 

----------      file type|owner|group|everyone else

-rw-r--r--

drwxr-x---    I’ve never seen a directory on a UNIX system that was anything other than ---, r-x, or rwx

 

$ ls -Fl

total 1525

drwx------   2 root     other        512 Jan 20  2007 Mail/

drwxr-xr-x   2 root     root         512 Nov 30  2006 TT_DB/

drwxrwxrwx   3 oracle   oinstall    6144 Dec 13  2007 archdata1/

drwxrwxrwx   3 oracle   oinstall    3584 Dec 13  2007 archdata2/

lrwxrwxrwx   1 root     root           9 Jun 13  2006 bin -> ./usr/bin/

 

The size of a directory is usually in increments of 512 bytes.

The link indicates the number of directories that are contained in that specific directory. Remember, all directories have dot and dot-dot, so the minimum value is always 2.

 

$ ls -ld

$ ls -ld .

Try entering ls -ld. and see if it correctly identifies the number of directories in your home directory.

 

Summary of command flags for ls.

Flag Meaning

-1    Force single-column output on listings.

-a    List all files, including any dot files.

-C   Force multiple-column output on listings.

-d    List directories rather than their contents.

-F   Indicate file types; / = directory, * = executable.

-l     Generate a long listing of files and directories.

-m   Show files as a comma-separated list.

-r    Reverse the order of any file sorting.

-R   Recursively show directories and their contents.

-s    Show size of files, in blocks (typically 1 block = 1,024 bytes).

-t     Sort output in most-recently-modified order.

-x    Sort output in row-first order.

 

 

Creating Files with the touch Command

$ touch old.file

changes modification times of files, anything that sorts files based on modification time will, of course, alter the position of that file when the file is altered by touch.

$ touch new.file

The new file has zero bytes, as can be seen by the ls -l output. Notice that by default the files are created with read and write permission for the user and anyone in the user’s group.

 

 

Check Disk-Space Usage with du

$ du [path]           lists the size, in kilobytes, of all directories at or below the current point in the file system

$ du -s   [path]            output only the grand total

$ du -a   [path]            lists all files

 

Check Available Disk Space with df

$ df -k

 

Shrink Big Files with the compress Program

$ compress filename

$ uncompress filename

$ compress -v filename

 

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章