750 likes | 972 Views
Filesystem management. Unit objectives Explain the function of the Filesystem Hierarchy Standard Find files, directories, and linked files Modify file and directory ownership Identify the default permissions and apply special permissions. Topic A:The filesystem hierarchy standard.
E N D
Filesystem management Unit objectives • Explain the function of the Filesystem Hierarchy Standard • Find files, directories, and linked files • Modify file and directory ownership • Identify the default permissions and apply special permissions
Topic A:The filesystem hierarchy standard • 2.3 Create files and directories and modify files using the CLI commands • Creating Directories
Filesystem Hierarchy Standard • Thousands of common files across Unix and Linux distributions • FHS • Outlines standard locations for files and directories • Gives software developers a consistent context regardless of the distribution • Helps users of one system work on another
FHS directories continued
Managing files and directories • File Management Tasks • Create directories • Copy and move files • Delete files
Managing files and directories • mkdir command • Create subdirectories • like windows folders • Takes arguments specifying the absolute or relative pathnames of the directories to create • Example • mkdir mysamples • Will create a directory called mysamples
Managing files and directories • mv command • Moves a files from one directory to another • requires two arguments at a minimum • Source file/directory • Target file/directory • Example • mv project* proj_files • Move all files starting with project to the proj_files folder
Managing files and directories • mv command • If target is directory • Source files moved to that directory • If target is existing filename and only one source file • Target file will be overwritten with source • If target is filename of non existent file • Source file is moved and renamed
Managing files and directories, continued • cp command • Command used to create copies of files and directories • Two argurments • Source file/directory • Target file/directory
Managing files and directories, continued • rm commands • Takes absolute or relative path • Can use wildcards • NO RECOVERY • User rm -r to remove all files in a directory • -r is recursive (searches through all subdirectories) • -f will force delete • rmdir command • Removes an EMPTY directory
Activity A 2-5 A-2 Pg 4-6 Create directories A-3 pg 4-8 Move files A-4 pg 4-12 Copy files A-5 pg 4-14 rm and rmdir
Which of the following commands will create the directory /home/gawd/tools/security regardless of the existence of its parent directories? A. md m /home/gawd/tools/security B. mkdir m /home/gawd/tools/security C. mkdir p /home/gawd/tools/security D. mkdir makepath /home/gawd/tools/security
Which of the following commands will create the directory /home/gawd/tools/security regardless of the existence of its parent directories? A. md m /home/gawd/tools/security B. mkdir m /home/gawd/tools/security C. mkdir p /home/gawd/tools/security D. mkdir makepath /home/gawd/tools/security Answer: C
Which of the following commands can be used to create new directories? A. rm B. ls C. mv D. mkdir
Which of the following commands can be used to create new directories? A. rm B. ls C. mv D. mkdir Answer: D.
Which of the following commands can be used to hide the file "help.new"? A. atrrib h help.new B. chmod 4000 help.new C. mv help.new .help.new D. cp help.new .help.new
Which of the following commands can be used to hide the file "help.new"? A. atrrib h help.new B. chmod 4000 help.new C. mv help.new .help.new D. cp help.new .help.new Answer: C
Topic B: Searching and linking files • 2.4 Execute content an directory searches using find and grep • Find • Create linked files using CLI commands
Finding files • locate command • Fastest method to search for files • A shortcut to the slocate (or secure locate) command • Example • locate filename
Finding files • find command • Used to find files using various criteria • Searches the directory tree recursively, starting from a certain directory, for files that meet criteria • Example • find /etc –name inittab • Find files names inittab in the etc directory
Which command and PATH variable • which command • Used to locate files within directories listed in the PATH variable • PATH variable • Stores list of directories searched when commands are executed without an absolute or relative pathname
Linking files • On a structural level, a filesystem has three main sections • The superblock • Number of inodes and data blocks • The inode table • Each inode desrcibes a file or directory and has unique inode number • Data blocks • Allocation units-actual storage locations on the HD • Only device files have no data blocks • Hard link, two files share the same data
Linking files • Hard link, two files share the same data • File references the same inode and inode number • Must be in same filesystem
In command • ln (link) command • Used to create hard and symbolic links • two arguments • The existing file to hard-link • The target file that will be created as a hard link to the existing file • Will up the link count in ls –l by number of hard links
In command • Example • ls –l of my directory -rw-r--r-- 1 epapates epapates 0 Feb 26 04:40 file1 -rwxrwxr-x 1 epapates users 548 Feb 26 03:59 Highland_Inn • Create linked file [epapates@localhost Unit_03]$ ln file1 file2 [epapates@localhost Unit_03]$ ls -l total 16 -rw-r--r-- 2 epapates epapates 0 Feb 26 04:40 file1 -rw-r--r-- 2 epapates epapates 0 Feb 26 04:40 file2 -rwxrwxr-x 1 epapates users 548 Feb 26 03:59 Highland_Inn • Link count went up!
Linking files • Symbolic link • Different inode number • One file is pointer to other • Files have different sizes • Data blocks in symbolic file are only a pathname to target • When editing symbolic file, you are editing the original
Which of the following commands can be used to create a link to the file /home/joe/help in /tmp/help.old? A. ln s help help.old B. ln s /home/joe/help /tmp/help.old C. ln s /tmp/help.old /home/joe/help D. ln v /home/joe/help /tmp/help.old
Which of the following commands can be used to create a link to the file /home/joe/help in /tmp/help.old? A. ln s help help.old B. ln s /home/joe/help /tmp/help.old C. ln s /tmp/help.old /home/joe/help D. ln v /home/joe/help /tmp/help.old Answer: B
A Linux user wants to create a hard link named file2 in the current directory that points to /usr/var/file. Which of the following commands can be used? A. ln file2 /usr/var/file B. ln /usr/var/file file2 C. ln h file2 /usr/var/file D. ln h /usr/var/file file2
A Linux user wants to create a hard link named file2 in the current directory that points to /usr/var/file. Which of the following commands can be used? A. ln file2 /usr/var/file B. ln /usr/var/file file2 C. ln h file2 /usr/var/file D. ln h /usr/var/file file2 Answer: B
Usernames and group membership • Login identifies user by • Username • Group membership • Access to commands, files and directories are dependent on this information
File and directory ownership • When a user creates a file or directory, that user’s name and primary group become the owner and group owner of the file • Primary group • Default group to which a user belongs • whoami • Show your username • groups • Shows group membership and primary group
chown commands • chown (change owner) command • Used to change the owner and group owner of a file or directory • Two arguments • New owner • File or directory to change • -R option is recursive for subdirectories and files
chgrp commands • chgrp (change group) command • Change the group owner of a file or directory • Takes two arguments at a minimum • The new group owner • The files or directories to change • Also can use the –R switch
Managing file and directory permissions • Mode • The section of the inode that stores permissions • Divided into three sections based on the user(s) that receive(s) the permission to that file or directory • User (owner) permissions • Group (group owner) permissions • Other (everyone on the Linux system permissions
Regular permissions • There are three regular permissions that you might assign to a user • Read • Write • Execute
chmod command • Used to change the mode (permissions) of a file or directory • Takes two arguments at a minimum • The first specifies criteria used to change permissions • The remaining arguments indicate the filenames to change
Default permissions • Umask • Used to alter the permissions on all new files and directories • Takes select default file and directory permissions away • Only applies to newly created files and directories • Never used to modify existing files or directories