260 likes | 415 Views
Linux. Files. Files and directories. As in Windows directories are structures which contain Other directories Files. Root directory. Base directory All others are contained within this directory Not to be confuse with /root This is the home directory of the root user.
E N D
Linux Files
Files and directories • As in Windows directories are structures which contain • Other directories • Files
Root directory • Base directory • All others are contained within this directory • Not to be confuse with /root • This is the home directory of the root user
Typical directories • /etc configuration • /var files that change (vary) such as logs • /home structure containing user home directories • /bin executables • /sbin root user executables • /usr regular user files • /tmp • /root • /boot • /dev used to access hardware resources • /lib system libraries
Shell • Command line environment • Like the Windows “DOS command line” • Prompt displayed • Enter a command and bit [enter] • Result (if any) returned, and next prompt displayed • Or.. Error message
Commands • pwd • print working directory • cd • change directory • mkdir • rmdir • ls • touch
cd • cd name • changes to the name directory • uses relative and absolute names • one dot refers to current directory • two dots refers to parent directory • forward slash ( / ) indicates a directory name • no slash indicates a subdirectory in the current directory
ls • lists the names of files in a directory • ls –l • long listing
touch • updates the time stamp of a file to that time • creates a new file (0 bytes) if the file does not exist
cp • copy cp file1 file2
rm • remove rm file1 • no “undelete” • file is not placed into a ‘recycle’ bin as in Windows
mv • move mv file1 file2 • can be used to rename a file • move it to a file with a different name
file • displays the type of file file myfilename • can be used to determine if the file is an executable or a “text” file which can be displayed using cat, more or less
cat • views the contents of a file • will scroll off the screen • use the “ | “ (pipe) to the more command cat | more • displays a screen, then stops • spacebar will bring up next screen • enter key brings up next line • ctrl-x will exit the cat command
zcat • “cats” a compressed file to the screen
less • displays a screen at a time • use “Q” to exit • pageUp and pageDown as well as arrow keys can navigate the file
more • displays a screen at a time
Filenames • Length can be 256 characters • upper or lower case • peridos, numbers, punctuation marks • NO SLASHES!
File Properties ls test -rwxr-xr-x 1 cmalinow users 1839423 Apr 1 15:12 test • permissions • user, group, other • user • group • timestamp • size
File Properties ls test -rwxr-xr-x 1 cmalinow users 1839423 Apr 1 15:12 test first character indicates type - regular file d directory user permission rwx group permission “other” permission
Changing owner • chown username.groupname filename • chown cmalinow.faculty testfileA • command is invoked by root
chmod • Changes permissions assigned to the file or directory • used by root • uses “g”, “u”, or “o” for group, user and other • chmod o+w test • allows “other” to write to file • chmod g=rw test • allows the group to read and write
chmod • read, write and execute assigned • 4, 2, 1 respectively • chmod 640 test • user has “6” 4 and 2 (read and write) • group has “4” (read) • others have “0” no access
File permissions • When creating a file, permission are assigned • umask determines the permissions to assign • umask 022 • same pattern as permission in chmod • umask executed as part of logging in
What’s a “sticky bit”? • Dilemma • depending on permissions set, any user in the group might be able to delete a file of another group member • setting the sticky bit on a directory only allows the owner, the directory owner, or root to rename or delete the file • set the sticky bit by chmod 1nnn • 1 indicates to put a sticky bit on the directory chmod 1777 mydir ls –ld mydir drwxrwxrwxt 2 cmalinow faculty … etc… • “t” indicates the ‘sticky bit’ is on