190 likes | 301 Views
Agenda. The Linux File System (chapter 4 in text) Directory Structures / Navigation Terminology File Naming Rules Relative vs Absolute pathnames Unix Commands df, du, mkdir, mkdir -p, rmdir, rm –r. rm -rf ls, ls -a, ls -F, ls -l, ls -ld. File System.
E N D
Agenda The Linux File System (chapter 4 in text) • Directory Structures / Navigation • Terminology • File Naming Rules • Relative vs Absolute pathnames • Unix Commands • df, du, mkdir, mkdir -p, rmdir, rm –r. rm -rf • ls, ls -a, ls -F, ls -l, ls -ld
File System • A File System is a structure used to organize programs and data on a computer’s storage device • Linux (Unix) OS has a special file called a directory file used to store ordinary files as well as other "directories" • Directories allow a computer’s file system to be better organized.
root / home public user1 user2 user3 ipc144 nled Hierarchical File System • In the Linux (Unix) OS, the "root directory" /is the starting directory, and other "child directories", "grandchild directories”,etc. are created • The hierarchical structure resembles an "upside-down tree"
Typical UNIX Directories • Directory PathDescription/Root directory (ancestor to all directories). • /home Used to store users’ home directories. • /home/account Your home directory (where account is name you use to login). This is your working directory after you login. • /bin Common system binaries (commands). • /usr/bin Common utilities (commands) for users. • /usr/sbin Common utilities for user administration. • /etc General System Admin. Files (eg passwd) • /varDynamic files(log files)/tmp, /var/tmpTemporary files for programs • /dev Device files (terminals, printers, etc.)
File Naming Rules • The following rules apply to naming ordinary files or "directory files": • Some older file systems restrict filename size to 14 characters, most file systems allow for 255 characters (safest to select filename size of 14). • Can use letters (upper & lower case), numbers, period , comma or underscore _ characters. • Upper case is different than lower case. • A period at beginning of filename hides file. • Avoid spaces and other punctuation in filenames.
Pathnames • A pathname is a listing of directories that will lead to a directory or a file. • The concept of a pathname relates to every operating system including Unix, Linux, MS-DOS, MS-Windows, Apple-Macintosh, etc.! • Examples: • Directory pathname: • /home/username/ics124/assignments • File pathname: • /home/username/ops224/assignments/assn1.txt
Absolute vs Relative Pathnames • Absolute Pathname • A pathname that begins from root. • The pathname begins with a slash • eg. /home/msaul/unx122 • Relative Pathname • A pathname that is "relative" to the location of the current or "working" directory. • Use cd to set the current directory, pwd to display the working (current) directory.eg. unx122 (i.e. we are already in /home/msaul)
Relative Pathnames • Rules: • A relative pathname does NOT begin with a slash. • Following symbols can be used: • .. parent directory • . current directory Warning:When using relative pathname, always make certain you know your present working directory!
Relative Pathnames • Examples: • Change to another directory branch from parent directory: cd ../unx122 • copy sample.c file from your professor’s directory to your current directory:cp /home/msaul/ipc144/sample.c .
Relative-to-Home Pathnames • You can specify a pathname as relative-to-home by using a tilde and slash at the start, e.g.,~/unx122/notes.html • The tilde ~ is replaced by your home directory (typically /home/your.account/) to make the pathname absolute.
Why Learn File Management? • To keep your home directory organized (less searching to find your files) • If files are not FTP’d to other locations and removed, you will run out of disk space.Consequences of Not Removing Unused Files:- Programs such as cc will not run properly- Your account may be suspended!
df / du commands • The df command reports file space usage on entire Linux system. This gives an “overall” picture of free disk space remaining on the system. • dfFilesystem 1k-blocks Used Available Use% Mounted on/dev/hda2 18943504 2405792 15575420 14% //dev/hda1 38859 2360 34493 7% /bootshmfs 1194164 0 1194164 0% /dev/shmserver8:/home/ 18843056 2325416 15544912 14% //server8/home • The du command reports file space usage on any directory path you specify (eg. Your home directory). All directories and files that are contained within the specified directory and related sizes will be displayed • Du /home/matrixid100 ./nled_tutorial1048 ./KDesktop/Trash2116 ./Kdesktop4164 . DiskPartitions Directory paths and related sizes Total size (in bytes) of current directory (matrixid)
Making Directories • Building directories is similar in approach to building a house • Begins from a foundation (eg home directory). • Need to build in proper order (add on addition to house in right location). Use a logical scheme. • When building directories from different locations, must provide proper absolute or relative pathname!!
Planning Directories • Good directory organization requires planning • Group information together logically. • Plan for the future: use dated directories where appropriate (~/christmas/2001, ~/christmas/2002) • Too few directories = excessive number of files in each; too many directories = long pathnames.
Where do we want to build directory? • Want to build a directory calledtmp that branches-off of your home directory • Verify which directory you are located (either look at directory from command prompt or issue the command pwd) • Type mkdir tmp at the Unix prompt, followed by ENTER • Always verify that directory has been created (e.g. use lsor ls -ld command)
Creating Parent Directories • To create directory paths with parent directories that do not exist you can use the command • mkdir -p pathname • eg. mkdir -p mur/dir1 • (This would create the parent directory mur and then the child directory dir1. The -p means "create all the directories in the Path").
Removing Directories Removing directories is reverse order of building directories • Issue command rmdir directory • rmdir cannot remove directories containing files or other subdirectories. • rmdir cannot remove directories that are anyone's current directory. • Need to step back to at least parent directory to remove an empty directory.
Removing Sub-trees • To remove a sub-tree (a directory and all of its contents including sub-directories) userm -rdirectory (or rm -R directory). The command rm –rf removes both subdirectories and files contained in a directory-path. • Caution! Back-up your files before removing. You can use the ftp application to transfer files to another server or your diskette. Refer to next set of notes to learn how to use command-line ftp. • Caution!rm -r can erase large numbers of files very quickly. Use with extreme care!
Listing Directory Contents • ls Compact listing of non-hidden files. • ls -aCompact listing of ALL files. • ls -l Detailed (long) listing of non-hidden files. • ls -F Displays symbols to mark directories (/) and executable files (*). • ls -ld Displays a detailed (long) listing of only directory file(s) rather than the contents of that directory.