Hour 4

Listing Files and Managing Disk Usage

Some useful flags to ls

Flag Meaning
-a
-F
-m
-s
-C
-1
List all files, including any dot files.
Indicate file types
Show files as a comma-separated list.
Show size of files, in blocks
Force multiple-column output on listings
Force single-column output on listings

4.1.1)  Tried ls in my home directory and it listed all the files and directories of the present working directory.

internet$ ls

README       cis325    cis377    m1feedback test
bugTrack     cis327    cis396q   prokids
cis316       cis328    m13com    public-web 



4.1.2)  I used command touch to create two files: test and TEST. Then i used ls to list the content of the directory and noticed that it listed both far from each other due to the fact that Unix sort system differentiates between uppercase and 
lowercase letters.


internet$ ls
README    cis316   cis328   m13com        public-web
TEST      cis325   cis377   m1feedback    test
bugTrack  cis327   cis396q
    prokids


4.2.1)  ls -s indicates the size of the files in kilobytes rounded upward.

Note: A kilobyte is 1,024 bytes of information, a byte being a single character

internet$ ls -s
total 15
2 README     2 cis325   1 cis396q       1 public-web
0 TEST       1 cis327   1 m13com        0 test
1 bugTrack   1 cis328   1 m1feedback
1 cis316     1 cis377   2 prokids
 


4.2.2)  ls -s does not show the size of the subdirectories. Directory cis316 has 1 as size but its contents when added are equal to 39.

internet$ ls -s
total 15
2 README   2 cis325   1 cis396q      1 public-web
0 TEST     1 cis327   1 m13com        0 test
1 bugTrack 1 cis328   1 m1feedback
1 cis316   1 cis377   2 prokids

internet$ cd cis316
internet$ ls -s
total 39
1 createAll.sql           1 makeDB.sql
1 ctCustomer.sql          1 ptAll.sql
1 ctOrderLines.sql        1 ptCustomer.sql
1 ctOrders.sql            1 ptOrderLines.sql
1 ctProduct.sql           1 ptOrders.sql
1 ctSequences.sql         8 ptProduct.sql
1 ctShippingAddress.sql   8 ptProductDesc.sql
1 ctShippingMethod.sql    2 ptShippingAddress.sql
1 descAll.sql             1 ptShippingMethod.sql
4 detailDB.txt            1 selectAll.sql
1 dropAll.sql



4.2.3)  ls -s followed by a file name displays the size of the specified file.

internet% ls -s ptProduct.sql
8 ptProduct.sql 



4.2.4)  To EASILY estimate the size of file ptProduct.sql: 8 X 1000 = 8000 bytes (this is not good for big files)
           To PRECISELY estimate the size of file ptProduct.sql: 8 X 1024 = 8192 bytes



4.2.5) ls -s allows you to specify as many files or directories as you like. Do it by separating them by a space as follow:

internet$ ls -s createAll.sql ptAll.sql selectAll.sql
1 createAll.sql 1 ptAll.sql 1 selectAll.sql

ls -a to show all files including hidden files (begins with a dot).

internet$ ls -a
.          .sh_history   cis316     cis377     prokids
..         README         cis325    cis396q     public-web
.jetadmin  TEST          cis327     m13com     test
.login     bugTrack      cis328     m1feedback



4.2.6)  ls -F appends suffixes to certain filenames so that you can identity more easily what types of files they are.

internet$ ls -F
README*    cis316/   cis328/    m13com/        public-web/
TEST       cis325/   cis377/     m1feedback/   test
bugTrack/  cis327/   cis396q/   prokids/



4.2.7) ls -F did not show any link in my home directory.


4.2.8)  The -m flag outputs the files as a comma separator list. And the -1 flag shows the output in one column only.

internet$ ls -m
README, TEST, bugTrack, cis316, cis325, cis327, cis328, cis377, cis396q,
m13com, m1feedback, prokids, public-web, test

internet$ ls -1
README
TEST
bugTrack
cis316
cis325
cis327
cis328
cis377
cis396q
m13com
m1feedback
prokids
public-web
test



4.3.1) This is a combination of falgs -a and -F put together. It will list all the files and their type.

internet$ ls -aF
./           .sh_history  cis316/     cis377/     prokids/
../          README*       cis325/    cis396q/     public-web/
.jetadmin/   TEST         cis327/     m13com/     test
.login       bugTrack/    cis328/     m1feedback/



4.3.2) This is a combination of falgs -s and -F put separately. It will list the files, their type, and their size.

internet$ ls -s -F
total 15
2 README*     2 cis325/    1 cis396q/       1 public-web/
0 TEST        1 cis327/    1 m13com/        0 test
1 bugTrack/   1 cis328/    1 m1feedback/
1 cis316/     1 cis377/    2 prokids/ 



4.3.3) The result produced by ls with a -s flag is the same as -sss. Even if the flag is repated it doesn't matter.

internet$ ls -sss
total 15
2 README 2 cis325 1 cis396q 1 public-web
0 TEST 1 cis327 1 m13com 0 test
1 bugTrack 1 cis328 1 m1feedback
1 cis316 1 cis377 2 prokids

internet$ ls -sss -s
total 15
2 README 2 cis325 1 cis396q 1 public-web
0 TEST 1 cis327 1 m13com 0 test
1 bugTrack 1 cis328 1 m1feedback
1 cis316 1 cis377 2 prokids

internet$ ls -s
total 15
2 README   2 cis325  1 cis396q     1 public-web
0 TEST     1 cis327  1 m13com      0 test
1 bugTrack 1 cis328  1 m1feedback
1 cis316   1 cis377  2 prokids
 


4.4.1) It shows, from my home directory, the content of /usr directory and the type of the files.

internet$ ls -F /usr
4lib/       dict@      kvm/ oasys/    sadm/     ucbinclude/
5bin@       dt/         lib/ old/     sbin/      ucblib/
X@ games/   local/     openwin/       share/    vmsys/
adm@        include/   lost+found/    opt/      snadm/ xpg4/
aset/       java@      mail@          platform/ spool@
bin/        java1.1/   man@           preserve@ src@
ccs/        java1.2/   net/           proc/     tmp@
demo/       kernel/    news@          pub@       ucb/ 



4.4.2)  This shows the content of the two specified directories

internet$ ls /usr/local /home
/home:

/usr/local:
README.solaris.pine include man
README.solaris.top info mrtg
bin infotrac sbin
doc ld share
etc lib sparc-sun-solaris2.7
gd-1.7.3 libexec zlib
iac libpng 



4.4.3)  This shows, from my home directory,  the content of parent directory separated by comma.

internet$ ls -m ..
ajong, apak, blee, bluong, chlo, hehara, hkarakul, jwu, kannamal, kishiwat,
kmikawa, malferma, michikaw, naman, pwood, sansari, seli, spantaro, viwong,
ysoe
internet$ ls
README cis316 cis328 m13com public-web
TEST cis325 cis377 m1feedback test
bugTrack cis327 cis396q prokids
internet$ cd ..
internet$ ls
ajong bluong hkarakul kishiwat michikaw sansari viwong
apak chlo jwu kmikawa naman seli ysoe
blee hehara kannamal malferma pwood spantaro


or

internet$ ls
README cis316 cis328 m13com public-web
TEST cis325 cis377 m1feedback test
bugTrack cis327 cis396q prokids
internet$ ls ../../
OIT lost+found stud-12 stud-28 stud-44
STG quota.report stud-14 stud-30 stud-46
STI.orig quotas stud-16 stud-32 stud-48
TT_DB staf-10 stud-18 stud-34 stud-52
faculty staf-2 stud-2 stud-36 stud-6
inst-2 staf-4 stud-20 stud-38 stud-8
inst-4 staf-6 stud-22 stud-4 stud-96
inst-6 staf-8 stud-24 stud-40 stud-99
inst-8 stud-10 stud-26 stud-42 tech-2



4.4.4)  Displays only the names and types of the files.

internet$ ls -F
README* cis316/ cis328/ m13com/ public-web/
TEST cis325/ cis377/ m1feedback/ sort.manpage
bugTrack/ cis327/ cis396q/ prokids/ test

This command displays the specified file and the specified directory with all its content.

internet$ ls -s test public-web
0 test

public-web:
total 1
1 index.html
 


4.4.5)  This command displays only the name of the specified file and their type avoiding showing teir content when tehy are directories..

internet$ ls -ds test public-web
1 public-web 0 test


4.5 Changing the sort order in ls



4.5.1) Displays all the files including the hidden ones. Sort by column (down)

internet$ ls -a
. .sh_history cis316 cis377 prokids
.. README cis325 cis396q public-web
.jetadmin TEST cis327 m13com sort.manpage
.login bugTrack cis328 m1feedback test
 

Displays all the files including the hidden ones. Sort by row (across)

internet$ ls -x -a
. .. .jetadmin .login .sh_history
README TEST bugTrack cis316 cis325
cis327 cis328 cis377 cis396q m13com
m1feedback prokids public-web sort.manpage test 



4.5.2)  Sort by most recently accessed to least recently accessed

internet$ ls -a -t
.sh_history test .. cis327 cis377
sort.manpage cis396q cis328 m13com prokids
. .login cis316 m1feedback .jetadmin
TEST bugTrack public-web cis325 README

 

4.5.3) ls -r reverses any sorting order

internet$ ls
README cis316 cis328 m13com public-web
TEST cis325 cis377 m1feedback sort.manpage
bugTrack cis327 cis396q prokids test

internet$ ls -r
test prokids cis396q cis327 bugTrack
sort.manpage m1feedback cis377 cis325 TEST
public-web m13com cis328 cis316 README
 


4.5.4)  This command lists the contents of the directory that is one level above the current directory, sorted so the most 
recently accessed file is last in the list and at the same time, indicates which items are directories and the size of 
each file. Mine is the most recently accessed because I am currently working with it I guess.


internet$ ls -r -t -F -s ..
total 27
1 ajong/ 1 blee/ 1 chlo/ 2 hehara/ 2 hkarakul/
1 malferma/ 1 pwood/ 1 kmikawa/ 2 seli/ 1 jwu/
1 kannamal/ 1 naman/ 2 sansari/ 2 bluong/ 1 apak/
1 michikaw/ 2 ysoe/ 1 viwong/ 1 kishiwat/ 2 spantaro




4.6  Listing Directory Trees Recursivelly in ls

4.6.1)  ls -R Shows the whole tree

           ls ../seli Shows the content of seli's directory. This should be unreadable but at GGU it's perfectly readable.

4.7 Long Listing Format in ls

4.7.1)  Shows a long list of information on the specified file.

internet$ ls -l README
-rwx------ 1 spantaro students 1373 SSep 8 1999 README
 

4.8 Long Listing Format for Directories in ls

4.8.1)  Shows a long list of information on the specified directory.

internet$ ls -l -d cis316
drwx------ 2 spantaro students 1024 Apr 13 11:18 cis316 


4.8.2)  The above result shows that cis316 is a directory, With read/write/execute permissions only to the owner.


4.8.3)  Shows a long list with all information about the files stored in the current directory. Shows if they are directories or regular files. Also shows their permissions, size and date they were created.

internet$ ls -l
total 35
-rwx------ 1 spantaro students 1373 SSep 8 1999 README
-rw-r--r-- 2 spantaro students 0 MMay 21 20:08 TEST
drwx------ 2 spantaro students 1024 May 9 16:50 bugTrack
drwx------ 2 spantaro students 1024 Apr 13 11:18 cis316
drwx------ 3 spantaro students 2048 Sep 19 2000 cis325
drwx------ 2 spantaro students 512 Oct 4 2000 cis327
drwx------ 2 spantaro students 1024 Apr 16 23:10 cis328
drwx------ 2 spantaro students 512 Sep 19 2000 cis377
drwx------ 2 spantaro students 512 May 16 17:20 cis396q
drwx------ 2 spantaro students 512 Sep 19 2000 m13com
drwx------ 2 spantaro students 512 Sep 19 2000 m1feedback
drwx------ 2 spantaro students 1536 Apr 28 2000 prokids
drwx------ 2 spantaro students 512 Mar 30 13:06 public-web
-rw-r--r-- 1 spantaro students 19804 MMay 22 16:59 sort.manpage
-rw-r--r-- 2 spantaro students 0 MMay 21 20:08 test 



4.8.4)  Shows a list with all files (including hidden ones) stored in the current directory and their types.

internet$ ls -Fa
./           .sh_history     cis316/    cis377/         prokids/
../          README*         cis325/    cis396q/        public-web/
.jetadmin/   TEST            cis327/     m13com/        sort.manpage
.login       bugTrack/      cis328/     m1feedback/    test



4.8.5)  Correctly identifies the number of directories in your home or current directory

internet$ ls -ld
drwx------ 14 spantaro students 1536 May 22 16:59 .



4.9 Creating Files with the touch Command

4.9.1)  The flag -t shows files based on modification time. After creating file README, the same command shows it in the beginning of the list.

internet$ ls -t
sort.manpage cis396q cis316 m13com cis377
TEST bugTrack public-web m1feedback prokids
test cis328 cis327 cis325 README
internet$ touch README
internet$ ls -t
README test cis328 cis327 cis325
sort.manpage cis396q cis316 m13com cis377
TEST bugTrack public-web m1feedback prokids 



4.9.2) The command touch creates the file called newfile because it did not exist previously.

internet$ ls
README     cis316   cis328    m13com          public-web
TEST       cis325   cis377     m1feedback     sort.manpage
bugTrack   cis327   cis396q   prokids test
internet$ touch newfile
internet$ ls
README     cis325   cis396q        prokids
TEST       cis327   m13com         public-web
bugTrack   cis328   m1feedback    sort.manpage
cis316     cis377   newfile test


4.10 Checking Disk Space Usage with du


4.10.1)  Lists the size, in kilobytes, of all directories at or bellow the current point in the file system.

internet$ du
8   ./m1feedback
4   ./m13com
10  ./cis327
4   ./public-web
86  ./cis328
80  ./cis316
50  ./bugTrack
2   ./cis396q
256 ./prokids
12  ./.jetadmin
12  ./cis377
172 ./cis325/dirExams
616 ./cis325
1196 .



4.10.2)  Displays only the grand total.

internet$ du -s
1196 .
 


4.10.3)  Displays the grand total of a specific directory.

internet$ du -s /etc
38660 /etc 



4.10.4)  Computes the size of all files due to the -a flag.

internet$ cd cis316
internet$ du -a
2  ./createAll.sql
2  ./ctCustomer.sql
2  ./ctOrderLines.sql
2  ./ctOrders.sql
2  ./ctProduct.sql
2  ./ctSequences.sql
2  ./ctShippingAddress.sql
2  ./ctShippingMethod.sql
2  ./descAll.sql
8  ./detailDB.txt
2  ./dropAll.sql
2  ./makeDB.sql
2  ./ptAll.sql
2  ./ptCustomer.sql
2  ./ptOrderLines.sql
2  ./ptOrders.sql
16 ./ptProduct.sql
16 ./ptProductDesc.sql
4  ./ptShippingAddress.sql
2  ./ptShippingMethod.sql
2  ./selectAll.sql
80 .
 


4.11.1)  Displays information on how much disk space is available on the overall UNIX System.

internet$ df
/proc (/proc ): 0 blocks 7853 files
/ (/dev/dsk/c0t0d0s0 ): 834208 blocks 237362 files
/usr (/dev/dsk/c0t0d0s5 ): 2188332 blocks 298333 files
/dev/fd (fd ): 0 blocks 0 files
/var (/dev/dsk/c0t0d0s4 ): 1250942 blocks 244312 files
/opt (/dev/dsk/c0t0d0s3 ): 1064876 blocks 241921 files
/tmp (swap ): 4709872 blocks 55106 files
/apps (/dev/dsk/c0t0d0s7 ): 3654278 blocks 481561 files
/home1 (/dev/md/dsk/d0 ): 4599140 blocks 628192 files
/web (/dev/md/dsk/d1 ): 773166 blocks 423257 files
/home2 (/dev/md/dsk/d2 ): 6862240 blocks 635803 files
/home3 (/dev/md/dsk/d3 ): 7142182 blocks 674765 files
/home4 (/dev/md/dsk/d4 ): 6789388 blocks 457297 files
/var/mail (c3po.ggu.edu:/var/mail): 1888270 blocks 424097 files
 


4.11.2)  Display the current working directory path

internet$ pwd
/home2/stud-30/spantaro/cis316



4.11.3)  The following line is one of the lines displayied in action 4.1.10. It shows:

the device name: /home2 (/dev/md/dsk/d2 )
total size of blocks: 6862240
total size of files: 635803

/home2 (/dev/md/dsk/d2 ): 6862240 blocks 635803 files


4.12.1)  This shows file sort.manpage initially with size of 20 kilobytes, and then with size of 8 kilobytes after being compressed.

internet$ ls -s
total 35
2 README     2 cis325   1 cis396q        2 prokids
0 TEST       1 cis327   1 m13com         1 public-web
1 bugTrack   1 cis328   1 m1feedback   20 sort.manpage
1 cis316     1 cis377   0 newfile        0 test


internet$ compress sort.manpage
internet$ ls -s
total 23
2 README    1 cis328      2 prokids
0 TEST      1 cis377      1 public-web
1 bugTrack  1 cis396q     8 sort.manpage.Z
1 cis316    1 m13com      0 test
2 cis325    1 m1feedback
1 cis327    0 newfile
 


4.12.2)  Same above except that I don't have a huge file


4.12.3) This shows the initial size of file sort.manpage after being uncompressed.

internet$ uncompress sort.manpage
internet$ ls -s
total 35
2 README     2 cis325   1 cis396q        2 prokids
0 TEST       1 cis327   1 m13com         1 public-web
1 bugTrack   1 cis328   1 m1feedback   20 sort.manpage
1 cis316     1 cis377   0 newfile        0 test



4.12.4) Flag -v informs how well the compress program shrank your files.

internet$ compress -v sort.manpage
sort.manpage: Compression: 60.07% -- replaced with sort.manpage.Z
internet$ ls -s
total 23
2 README     1 cis328     2 prokids
0 TEST       1 cis377     1 public-web
1 bugTrack   1 cis396q    8 sort.manpage.Z
1 cis316     1 m13com     0 test
2 cis325     1 m1feedback
1 cis327     0 newfile 



Exercise 3

First created three files, then listed then acording to creation date, then used command touch to update the modification date of file2, and the file1 and again listed them sorted by modification date.

internet$ touch file1
internet$ touch file2
internet$ touch file3

internet$ ls -t f*
file3 file2 file1

internet$ touch file2
internet$ ls -t f*
file2 file3 file1

internet$ touch file1
internet$ ls -t f*
file1 file2 file3

1