Home
Module Two(Linux) - H3ABioNet training course material
Contents
1. Oyelade O J and Isewon I H3AbioNet Postgraduate course 2014 Page 12 4 Explore proc Display the contents of the files interrupts devices cpuinfo meminfo and uptime using cat Can you see why we say proc is a pseudo filesystem which allows access to kernel data structures 5 Change to the home directory of another user directly using cd username Change back into your home directory Make subdirectories called work and play Delete the subdirectory called work 9 Copy the file etc passwd into your home directory 10 Move it into the subdirectory play 11 What is the difference between listing the contents of directory play with 1s landls L 12 Create a file called hello txt that contains the words hello world Can you use cp using terminal as the source file to achieve the same effect 13 Copy hello txt to terminal What happens 14 Imagine you were working on a system and someone accidentally deleted the 1s command bin 1s How could you get a list of the files in the current directory Try it 15 How would you create and then delete a file called SSHELL Try it 16 How would you create and then delete a file that begins with the symbol Try it 17 How would you create and then delete a file that begins with the symbol Try it 18 Experiment with the options on the 1s command What do the d i R and F options do ona Oyelade O J and Isewon I H3AbioNet Postgraduate course
2. containing personal file homes space for each user Each directory is named after the login of the user dev Hardware devices A pseudo filesystem which is used as an interface to the kernel Includes a sub directory for each active program or process Fig 2 2 Typical Linux directories When you log into Linux your current working directory 1s your user home directory You can refer to your home directory at any time as and the home directory of other users as lt login gt So will play is another way for user jane to specify an absolute path to the directory homes will play User will may refer to the directory as play 2 4 Directory and File Handling Commands This section describes some of the more important directory and file handling commands pwd print current working directory Oyelade O J and Isewon I H3AbioNet Postgraduate course 2014 Page 4 pwd displays the full absolute path to the your current location in the filesystem So pwd usr bin implies that usr bin is the current working directory e ls list directory ls lists the contents of a directory If no target directory is given then the contents of the current working directory are displayed So if the current working directory is Is bin dev home mnt share usr var boot etc lib proc sbin tmp vol Actually Is doesn t show you all the entries in a directory fi
3. files matches all files with containing a e Characters enclosed in square brackets and will match any filename that has one of those characters in that position e A list of comma separated strings enclosed in curly braces and will be expanded as a Cartesian product with the surrounding characters For example Oyelade O J and Isewon I H3AbioNet Postgraduate course 2014 Page 11 1 2 matches all three character filenames 2 e11 matches any five character filenames with e11 in the middle 3 he matches any filename beginning with he 4 m z a 1 matches any filename that begins with a letter from m to z and ends in a letter from a to 1 usr bin 1ib file expands to usr bin file usr lib file bin file and lib file nN Exercises Two 1 Try the following command sequence ed pwd ls al cd pwd where did that get you cd pwd is al ed pwd ls al ca pwd what happens now cd etc ls al more cat passwd ca o pwd 2 Continue to explore the filesystem tree using cd 1s pwd and cat Look in bin usr bin sbin tmp and boot What do you see 3 Explore dev Can you identify what devices are available Which are character oriented and which are block oriented Can you identify your tty terminal device typing who am i might help who is the owner of your tty use 1s 1 oO 0 0 0 0 oo oO oOo O 0O Q O o O0 O
4. 2014 Page 13
5. Postgraduate course Covenant University Ota Nigeria Oyelade O J PhD ola oyelade covenantuniversity edu ng Isewon I itunu isewon covenantuniversity edu n Module Two Filesystem 2 1 Objectives In this module we will covers The Linux filesystem and directory structure File and directory handling commands How to make symbolic and hard links How wildcard filename expansion works What argument quoting is and when it should be used 2 2 The Linux Filesystem The Linux operating system is built around the concept of a filesystem which is used to store all of the information that constitutes the long term state of the system This state includes e the operating system kernel itself e the executable files for the commands supported by the operating system such as o configuration information o temporary workfiles o user data and various special files that are used to give controlled access to system hardware and operating system functions Every item stored in a Linux filesystem belongs to one of four types 1 Ordinary files e Ordinary files can contain text data or program information Oyelade O J and Isewon I H3AbioNet Postgraduate course 2014 Page 1 e They can contain any keyboard character except for and be up to 256 characters long note that characters such as and amp have special meaning in most shells and should not therefore be used
6. destination directory To copy a file e g Hello txt in oyelade directory into the oyelade ade directory as Hello bak cp home oyelade Hello txt home oyelade ade H llo bak 7 cp r myfolder destionation S Here all folders and files will be copied recursively Copying multiple files cp home usr dir filel file2 file3 file4 home usr destination e mv move rename mv is used to rename files directories and or move them from one directory into another Exactly one source and one destination must be specified Oyelade O J and Isewon I H3AbioNet Postgraduate course 2014 Page 8 S mv source destination N B if destination is an existing file it will be destroyed and overwritten by source you can use the i option if you would like to be asked for confirmation before a file is overwritten in this way e rm remove delete rm target file s removes the specified files Unlike other operating systems it is almost impossible to recover a deleted file unless you have a backup there is no recycle bin so use this command with care If you would like to be asked before files are deleted use the i option rm i myfile rm remove myfile rm can also be used to delete directories along with all of their contents including any subdirectories they contain To do this use the r option To avoid rm from asking any questions or giving errors e g if the file doesn t exist you used the f
7. force option Extreme care needs to be taken when using this option consider what would happen if a system administrator was trying to delete user will s home directory and accidentally typed S rm rf home will instead of rm rf home will rm r myfolder To remove a folder e cat catenate type cat target file s Oyelade O J and Isewon I H3AbioNet Postgraduate course 2014 Page 9 displays the contents of target file s on the screen one after the other You can also use it to create files from keyboard input as follows gt is the output redirection operator cat gt hello txt hello world ctrl d 16 h llo txt hello txt cat hello txt hello world e more and less catenate with pause more target file s displays the contents of target file s on the screen pausing at the end of each screenful and asking the user to press a key useful for long files It also incorporates a searching facility press and then type a phrase that you want to look for You can also use more to break up the output of commands that produce more than one screenful of output as follows is the pipe operator which will be discussed in the next module S 1s 1 more less is just like more except that has a few extra features such as allowing users to scroll backwards and forwards through the displayed file less not a standard utility however and may not be present on a
8. gh the tree e The path to a location can be defined by an absolute path from the root or as a relative path from the current working directory e To specify a path each directory along the route from the source to the destination must be included in the path with each directory in the sequence being separated by a slash e To help with the specification of relative paths Linux provides the shorthand for the current directory and for the parent directory o For example the absolute path to the directory play is home will play while the relative path to this directory from zeb is will play Fig 2 2 below shows some typical directories you will find on Linux systems and briefly describes their contents Note that these subdirectories appear as part of a Oyelade O J and Isewon I H3AbioNet Postgraduate course 2014 Page 3 logical filesystem they do not need be present on the same hard disk device some may even be located on a remote machine and accessed across a network Directory Typical Contents The root directory bin Essential low level system utilities usr bin Higher level system utilities and application programs Superuser system ties for performing system administra tasks Program libraries collections of system calls that can be included in programs by a compiler for low level system utilities tmp Temporary file storage space can be used by any user home or User home directories
9. in filenames e Putting spaces in filenames also makes them difficult to manipulate rather use the underscore 2 Directories e Directories are containers or folders that hold files and other directories 3 Devices e To provide applications with easy access to hardware devices Linux allows them to be used in much the same way as ordinary files e There are two types of devices in Linux o block oriented devices which transfer data in blocks e g hard disks and o character oriented devices that transfer data on a byte by byte basis e g modems and dumb terminals 4 Links A link is a pointer to another file There are two types of links a hard link to a file is indistinguishable from the file itself A soft link or symbolic link provides an indirect pointer or shortcut to a file A soft link is implemented as a directory file entry containing a pathname 2 3 Typical UNIX Directory Structure e The Linux filesystem is laid out as a hierarchical tree structure which is anchored at a special top level directory known as the root designated by a slash e Because of the tree structure a directory can have many child directories but only one parent directory e Fig 2 1 illustrates this layout Oyelade O J and Isewon I H3AbioNet Postgraduate course 2014 Page 2 Fig 2 1 Part of a typical UNIX filesystem tree e To specify a location in the directory hierarchy we must specify a path throu
10. les and directories that begin with a dot are hidden this includes the directories and which are always present The reason for this is that files that begin with a usually contain important configuration information and should not be changed under normal circumstances If you want to see all files Is supports the a option Is a 4 Even this listing is not that helpful there are no hints to properties such as the size type and ownership of files just their names To see more detailed information use the l option long listing which can be combined with the a option as follows ls a 1 or equivalently ls al Each line of the output looks like this Oyelade O J and Isewon I H3AbioNet Postgraduate course 2014 Page 5 permissions owner type links size where o typeis a single character which is either d directory ordinary file l symbolic link b block oriented device or c character oriented device o permissions is a set of characters describing access rights There are 9 permission characters describing 3 access types given to 3 user categories The three access types are read r write w and execute x and the three users categories are the user who owns the file users in the group that the file belongs to and other users the general public An r w or x character means the corresponding permission is present a means it is absent
11. ll Linux systems 2 5 Making Hard and Soft Symbolic Links Direct hard and indirect soft or symbolic links from one file or directory to another can be created using the In command Oyelade O J and Isewon I H3AbioNet Postgraduate course 2014 Page 10 1n filename linkname creates another directory entry for filename called linkname i e linkname is a hard link Both directory entries appear identical and both now have a link count of 2 If either filename or linkname is modified the change will be reflected in the other file since they are in fact just two different directory entries pointing to the same file In s filename linkname creates a shortcut called linkname i e linkname is a soft link The shortcut appears as an entry with a special type 1 In s hello txt bye txt 1s 1l bye txt lr rwWXrwxrwXx 1 will finance 13 bye txt gt hello txt The link count of the source file remains unaffected Notice that the permission bits on a symbolic link are not used always appearing as rwxrwxrwx Instead the permissions on the link are determined by the permissions on the target hello txt in this case 2 6 Specifying multiple filenames Multiple filenames can be specified using special pattern matching characters The rules are e matches any single character in that position in the filename e matches zero or more characters in the filename A on its own will match all
12. o links refers to the number of filesystem links pointing to the file directory see the discussion on hard soft links in the next section o owner is usually the user who created the file or directory o group denotes a collection of users who are allowed to access the file according to the group access rights specified in the permissions field o size is the length of a file or the number of bytes used by the operating system to store the list of files in a directory o dateis the date when the file or directory was last modified written to The u option display the time when the file was last accessed read o name is the name of the file or directory 1s supports more options To find out what they are type man ls man is the online Linux user manual and you can use it to get help with commands and find out about what options are supported It has Oyelade O J and Isewon I H3AbioNet Postgraduate course 2014 Page 6 quite a terse style which is often not that helpful so some users prefer to the use the non standard info utility if it is installed S info ls e cd change current working directory cd path changes your current working directory to path which can be an absolute or a relative path One of the most common relative paths to use is i e the parent directory of the current directory Used without any target directory S ea resets your current working directory to your home director
13. y useful if you get lost If you change into a directory and you subsequently want to return to your original directory use S cd 4 e mkdir make directory mkdir directory creates a subdirectory called directoryin the current working directory You can only create subdirectories in a directory if you have write permission on that directory e rmdir remove directory rmdir directory removes the subdirectory directory from the current working directory You can only remove subdirectories if they are completely empty i e of all entries besides the and directories Oyelade O J and Isewon I H3AbioNet Postgraduate course 2014 Page 7 e cp copy cp is used to make copies of files or entire directories To copy files use cp source file s destination where source file s and destination specify the source and destination of the copy respectively The behaviour of cp depends on whether the destination is a file or a directory If the destination is a file only one source file is allowed and cp makes a new file called destination that has the same contents as the source file If the destination is a directory many source files can be specified each of which will be copied into the destination directory Section 2 6 will discuss efficient specification of source files using wildcard characters To copy entire directories including their contents use a recursive Copy cp rd _ source directories
Download Pdf Manuals
Related Search
Related Contents
Catalogue Rytmica 2014/2015 f7d2102-user-manual-it SBC81822 Series User's Manual A5 9 - Bosch Security Systems PowerScale USER MANUAL Biostar Hi-Fi A85W Owner's Manual Samsung 냉장고 160 L Copyright © All rights reserved.
Failed to retrieve file