Dr. Mark Humphrys

School of Computing. Dublin City University.

Online coding site: Ancient Brain

coders   JavaScript worlds

Search:

Free AI exercises


Disks and file system



du


du                      Space used by me

du | sort -n		# why -n?

default is k

listing in M  
du -BM

listing in G  
du -BG

top-level only
--max-depth=1 


Disk usage by folder on Windows:
  

df

df -h                   Show space on all disks
df -k                   exact kilobytes
  
Filesystem                                          Size  Used Avail Use% Mounted on
/dev/sda1                                           696M   65M  632M  10% /boot/efi
/dev/sda8                                            96G   46G   46G  51% /
/dev/sda9                                            96G  1.5G   90G   2% /DATA
kita.computing.dcu.ie:/local2/home/student/student  2.0T  1.2T  770G  60% /users/student
kita.computing.dcu.ie:/local2/home/tutors           2.0T  1.2T  770G  60% /users/tutors
tmpfs                                               3.9G  115M  3.8G   3% /dev/shm
tmpfs                                               783M  2.3M  780M   1% /run
...

On lab PCs, shows local (PC, non-shared) install of Linux, plus the shared disk with home directories.
Shared disk is 60% full.
  

Filesystem                                          Size  Used Avail Use% Mounted on
/dev/sda1                                            71G   33G   35G  49% /
kita.computing.dcu.ie:/local2/home/student/student  2.0T  1.2T  770G  60% /users/student
kita.computing.dcu.ie:/local2/home/tutors           2.0T  1.2T  770G  60% /users/tutors
tmpfs                                               3.9G   16M  3.9G   1% /dev/shm
tmpfs                                               795M  1.8M  793M   1% /run
udev                                                3.9G     0  3.9G   0% /dev

On ssh to student server, shows local (server, non-shared) install of Linux, plus the shared disk with home directories.
Same shared disk (60% full).
  


df to see file system type

See all disks and their file system type:
df -Th 
On DCU Linux you will see these:



Absolute and relative paths


Relative path of a file

index.html
What file that refers to depends on what directory you are in now.
It looks for index.html in the current directory.
../index.html
is also relative path. It looks for index.html in the parent of the current directory.


Directory before Command Directory after
/users/gdf cd users/ec2 /users/gdf/users/ec2
/users/gdf cd ../ec2 /users/ec2
/users/gdf cd ec2 /users/gdf/ec2



Absolute path of a file

/dir/dir/dir/public_html/index.html
Gives the full "path" from the root down to the file.
Refers to the same file no matter what directory you are in.


Directory before Command Directory after
/users/gdf cd /users/ec2 /users/ec2




Case sensitivity

Case matters in filenames in UNIX (this is why case often matters on Web).

Question: Is case sensitivity a good thing? Or is it a flaw in UNIX?

Advantages of case sensitivity:

  1. More readable code. You know what to expect.
  2. More variables. num and NUM and Num
  3. Set up conventions, so that NUM probably refers to a compile-time-coded constant, num is a real-time-changing variable, etc.
  4. Quicker/simpler searches on strings and changes of strings, since can just search for the literal string.
  5. Better to be case-sensitive for passwords. - Larger space to pick from. Harder to guess. Good to be "unforgiving" for security.
Not much return for such huge disadvantages:
  1. Millions of programmer and user hours lost on case not right.
  2. Millions of failed "404 Not Found" website hits because of wrong case in the URL.

  
Solutions to "404 Not Found" because of case:
  1. Set up program to handle 404. See My "404 Not Found" Handler
  2. Detach website URLs from underlying (case sensitive) file system.
    e.g. Content Management System.



Filenames and Special Characters

Long file names and multiple periods OK.
e.g. product.4652.suppliers.us.html


Limits


Avoid these chars

If the command-line is used to address files, it is best to avoid many special characters in filenames.

Avoid these chars in filenames, because they have meaning to the Unix command-line and utilities:

space (separate arguments)
# comment
< redirection
> redirection
` result of a program
| pipe
& detach process
; separate multiple commands on the same line

* wildcard
? wildcard
^ start of line
$ end of line / variable value
[ pattern matching
] pattern matching
\ "quoted" character
/ should be in pathname, not filename
' string delimiter
" string delimiter
! shell history



Stick to these chars

If you're going to use the command-line, best to just use these chars in filenames:

 0-9
 a-z
 A-Z 

Use these inside filename only, not at start or end:
 .  
 -  
 _




ancientbrain.com      w2mind.org      humphrysfamilytree.com

On the Internet since 1987.      New 250 G VPS server.

Note: Links on this site to user-generated content like Wikipedia are highlighted in red as possibly unreliable. My view is that such links are highly useful but flawed.