S E C T I O N O V E R V I E W

Size: px
Start display at page:

Download "S E C T I O N O V E R V I E W"

Transcription

1 FILES AND DIRECTORIES: ADVANCED CONCEPTS S E C T I O N O V E R V I E W In this section, we will learn about: understanding soft (symbolic) links; understanding hard links; working with soft and hard links; working with text files; finding files and directories. 4.1 HARD AND SOFT LINKS So far, we had the opportunity to work with two specific kinds of files known as regular files and directories. Typically, regular files may contain data that can be processed by various applications; media that allow us to watch video or listen to our favourite songs; text that may contain notes we keep so far in our machines; or other data required for the development of applications. These kinds of files are stored in various directories in a UNIX system and can be accessed when it is necessary. Typically, in order to work more efficiently with files, we keep them, in directories that contain related information. However, sometimes we use certain files more often and therefore we wish to have them in our working directory or in our home directory. In addition, sometimes there is a need to have multiple copies of the same file. A possible solution is the use of the cp UNIX command. This allows us to have identical instances of our often-used files placed in several directories. Although, this is efficient it is not very effective. For example, working with instances means that after finishing any work associated with an instance of our original file, we need to move it back to its original location. PAGE 1

2 Moreover, if we have multiple copies, we may need to repeat this step in order to have exact up-to-date copies of our file. Thus, we need to search for every location where our file exists and update it by replacing it. Although, this is a daunting and time-consuming task; we may also end up with dozens of copies. UNIX like other operating systems allows us to have shortcuts of these files. These are known as links and are not instances of our original files. They are just special kind of files that refer to the original file. This allows us to open a link and work with it. However, opening a link file means that we open the original file. Operations such as saving a file, updating the file and in general manipulating the corresponding file reflect to the original one and not to the linked one. In fact, UNIX refers to all files and directories by an inode number which is unique for each file. For example, every time you access a specific file system, the UNIX operating system determines which file allocation table should use and then determines which inode entry to use from the directory entry for that filename. This allows more than one file to be referenced by one inode identifier. To this extent, a file can have as many file names as its user wishes. FIGURE 4.1: HARD LINK REPRESENTATION Having several names that refer to the same file, each name associated with the corresponding file is known as hardlink. This is an efficient solution as you may need to have the same file into two different directories. For instance, you may have a directory called friends that contains information PAGE 2

3 about each of your friends. However, you may have some friends who are your colleagues, as well. Therefore, you may need to have a reference of the same file into a directory i.e. called colleagues. As these are not copies but references to the same file; by updating the one you also update the other one. Figure 4.1 illustrates this concept. Hard links can be used only in the same file system. As indicated previously, file systems maintain their own file allocation tables and therefore the same inode number may refer to different files in each individual file system. This can be considered as a shortcoming of the hard link artefact. However, we can use an alternative solution. This is known as soft link. In simple terms, a soft link is just a file that refers to the original file. Some information included to a soft link is the absolute path of the original file. This concept is similar in Windows family operating systems where these links are known as shorcuts. The advantage of soft links is that we can have many shortcuts placed in different directories in different file systems. Moreover, this also allows us to avoid using unnecessary disk space. Each link can have its own file name or the file name of the file it refers to. Note that we cannot have a file and a link of it with the same file name in same directories. CREATING HARD LINKS The command required for this task is known as: SYNTAX ln ln existed_file new_file_name COMMAND SYNTAX 4.1: ln Where the existed_file is the file you are going to refer to and new_file_name is the new name of the existed file. Both of these arguments can reflect the same directory or they can be absolute or relative pathnames. However, there is a requirement; both should be in the same file system. PAGE 3

4 ln 8 tiger% ln mynotes mynotes2 9 tiger% SAMPLE OUTPUT 4.1: CREATING HARD LINKS The sample output 4.1 illustrates an example of creating a hard link. In particular, the user created a hard link to a file known as mynotes. The name of the link is mynotes2. However, mynotes2 is not a copy but a reference to a file with the same inode as the file mynotes. 16 tiger% ls -il mynotes mynotes rw svigkoi staff 249 May 8 01:17 mynotes rw svigkoi staff 249 May 8 01:17 mynotes2 17 tiger% SAMPLE OUTPUT 4.2: LISTING INODE NUMBERS In sample output 4.2, we can see that both files, namely mynotes and mynotes2 are exactly identical. More precisely, they have the same inode identifier, the same access rights, group size, etc. IDENTIFYING HARD LINKED FILES In order to identify if a file is hard-linked, we use the ls l command. The integer number located after the access rights and before the group identifier of a file indicates that. For example, consider sample output 4.2. The integer 2 indicate that there are two hard links for the file with inode identifier ln ll sort pg 18 tiger% ls -il sort pg rw svigkoi staff 1702 Apr 20 21:40 dead.letter drwx svigkoi staff 512 Oct model rw svigkoi staff Jun Sent Items rw svigkoi staff 2376 Jul Drafts rw svigkoi staff 526 Dec 11 01:23 Personal 19 tiger% SAMPLE OUTPUT 4.3: IDENTIFYING LINKED FILES IN SAME DIRECTORY PAGE 4

5 Sample output 4.3 allows us to identify if there are linked files in the same directory. The options il of the ls command forces the shell to display a long list of the elements of the current directory by giving also the inode number of each file and directory. sort command sorts everything based on the inode number provided by the ls command. The last command pg forces the display output to be one per screen. If the output is more than a screen, in length, it prompts users to press the return key <Return>. This will show the next screen. The command will exit and will return us the command prompt when there is nothing else to output on the display. The previously elaborated approach allowed us to consider linked files that exist in our current directory. However, we may need to find all linked files that exist in a UNIX system. Therefore, we need to use the find command associated with specific options and arguments. Note that the output of the find command is subject to access rights, users have. The following sample illustrates this task. find / -inum print 21 tiger% find / -inum print SAMPLE OUTPUT 4.3: FINDING LINKED FILES After the command find there is a forward slash (/). This indicates the directory, find command will start searching and includes all sub-directories of it. The option inum is an option that reflects the inode number of a file, we wish to find. The inode identifier should be provided as an argument. In this case it is the integer The last option print requests that the output should include the absolute path name of the files found. LISTING HARD LINKS The regular ls UNIX command can be used for listing hard links while all the associated options with this command can be used as well. When listing hard links with ls l or ls -il, we can observe some differences in the output. In particular, at the start of the first column we can see the symbol (-) which indicates the element is a file. However, observing the third column, we can see that if the number shown is greater that 1 then there are more than one filenames that refer to the same file with the same inode number. PAGE 5

6 57 tiger% ls -il mynotes rw svigkoi staff 249 May 8 18:44 mynotes3 SAMPLE OUTPUT 4.4: LISTING HARD LINKED FILES As shown, the inode number for mynotes3 file is and the file is hard linked three times. DELETING HARD LINKS Hard links are particular files that refer to files; therefore if we wish to delete a hard link, the rm command is suffice. This actually will decrease the number that indicates the links of a linked file. If the number of links is equal to one, the use of rm command will delete the file. The following example will help you to understand this concept. 54 tiger% ln mynotes mynotes2 55 tiger% ls -il mynotes rw svigkoi staff 249 May 8 18:44 mynotes 56 tiger% ln mynotes2 mynotes3 57 tiger% ls -il mynotes rw svigkoi staff 249 May 8 18:44 mynotes3 58 tiger% rm mynotes rm: remove mynotes (yes/no)? y 59 tiger% ls -il mynotes rw svigkoi staff 249 May 8 18:44 mynotes2 60 tiger% rm mynotes2 rm: remove mynotes2 (yes/no)? y 61 tiger% ls -il mynotes rw svigkoi staff 249 May 8 18:44 mynotes3 62 tiger% rm mynotes3 rm: remove mynotes3 (yes/no)? y 63 tiger% ls -il mynotes3 mynotes3: No such file or directory SAMPLE OUTPUT 4.5: FINDING LINKED FILES The user created a hard link to mynotes file with name mynotes2. Next, the ls il command displayed information about the mynotes file. The user decided to create one extra link with name mynotes3. After entering the command ls il, we can see that mynotes3 file is linked 3 times. Now, if we remove our original file called as mynotes, we observe that our file exists with PAGE 6

7 file names mynotes2 and mynotes3. After removing mynotes2 and getting information about mynotes3, we can see that our file is now linked just once. As, we wish to delete this file the rm command deletes it, permanently. In sample output 4.4 observe that the inode number is exactly the same for all mynotes* files. COPYING AND MOVING HARD LINKS Hard links can also be copied using the regular cp command. In this case, a new file is created which is an exact copy of the original linked file. However, the copy does not refer to the original file as its inode number is different. mv can be used to move or move by renaming a hard link. Since, hard links are indistinguishable from regular files; UNIX commands handle them as regular files. FIGURE 4.2: SOFT LINKS REPRESENTATION CREATING SOFT LINKS The command required for this task is described as follows: SYNTAX ln -s ln s existed_file new_file_name COMMAND SYNTAX 4.2: ln -s In this case, the existed_file is the file you are going to refer to and new_file_name is the new name of existed file. Note that we used the option PAGE 7

8 s in order to indicate the shell that we wish to create a soft link for the corresponding file. As you guessed right, the letter s stands for soft. The arguments, as in hard links, can be absolute, relative pathnames or can correspond to the current directory. Soft links can exist between different file systems as they refer to a file using the notion of absolute or full paths. Soft links can also refer to directories as well. ln -s 14 tiger% ln s mynotes smynotes SAMPLE OUTPUT 4.6: CREATING SOFT LINKS The sample output 4.6 provides an example of creating a soft link. In this case, the user also enters the s option to indicate the creation of a soft link. The soft linked file that refers to the mynotes file, is called smynotes. LISTING SOFT LINKS In a similar fashion like listing all other files, soft links can be listed through the use of the ls command associated with various options. Typically, we use ls l as we can clearly see if a file corresponds to a soft link. ln il 15 tiger% ls -il mynotes smynotes rw svigkoi staff 249 May 8 19:15 mynotes lrwxrwxrwx 1 svigkoi staff 7 May 8 19:43 smynotes -> mynotes 16 tiger% SAMPLE OUTPUT 4.7: IDENTIFYING SOFT LINKS In sample output 4.7, we can clearly see that the first character from the string related with access rights indicates that file mynotes2 is a pointer to another file. Moreover, note that the size of this file is very small, 7 bytes only. It is also clear that soft-linked files have different numbers than the files, they refer to. Since, it is difficult to find out which files, soft links point to, we also need more information. This is shown at the end of the line where ls il command displays the name of the link file associated with the symbol (->) and the name of the file, the link points to (smynotes -> mynotes). PAGE 8

9 DELETING SOFT LINKS This task is quite different than the task of deleting hard links. In general, soft links are deleted with the rm command. However, an obvious question is that what happens if we delete a file that a soft link points to. Both of these cases are demonstrated by sample output tiger% ls -il mynotes mynotes rw svigkoi staff 249 May 8 21:08 mynotes lrwxrwxrwx 1 svigkoi staff 7 May 8 21:05 mynotes2 -> mynotes 50 tiger% rm mynotes rm: remove mynotes (yes/no)? y 51 tiger% ls -il mynotes lrwxrwxrwx 1 svigkoi staff 7 May 8 21:05 mynotes2 -> mynotes SAMPLE OUTPUT 4.8: DELETING SOFT LINKS Initially, we created a link to mynotes file and called it mynotes2. Then, as illustrated in sample output 4.8, we executed ls l command with arguments the mynotes file and its linked file. Then, we removed the source file. ls il command applied to mynotes2 file shows that the link file still exists and it is still pointing to the deleted source file. This means that an attempt to open the linked file with, for example, vi editor will give us nothing. In the case, we can create a new file with name mynotes then link will refer again to our newly created file. COPYING AND MOVING SOFT LINKS Soft links can be copied by using the cp command along with various supported options. However, when we apply the cp command, we copy the original file, the link file points to and not the link file. In the case, we have a link file that points to a file deleted previously; we will get an error message. mv command operates on a link file itself and not on the file the link file points to. Therefore, moving a link file to somewhere else means that you move the link file while the regular file, the link files points to, remains in its current location. PAGE 9

10 4.2 WORKING WITH TEXT FILES In UNIX operating systems, you can have many files. However, an important question corresponds to the contents of your files. Alternatively, many times we need to ask ourselves What does this file contain?. A smart answer could be that it contains a sequence of bytes. However, this answer is not very smart as we need to know the actual representation of those bytes. There are several approaches. First, for example, we can start examining the filename of the file. This may remind us something. Next, we may consider its suffix as some UNIX files are required to have one. However, again this is not an effective approach. It may be possible to infer from the file s suffix the actual content of the file. Sometimes, we may find a precise answer by using commands such as more or by using a text editor such as vi or emacs. As the content can infer the type of a file, the command file can be used to check a file s contents. 1 tiger% file mynotes mynotes: English text 2 tiger% file /bin/ls /bin/ls: ELF 32-bit MSB executable SPARC Version 1, dynamically linked, stripped 3 tiger% file libproject.so libproject.so: ELF 32-bit MSB dynamic lib SPARC Version 1, dynamically linked, not stripped 4 tiger% file public_html public_html: directory 5 tiger% SAMPLE OUTPUT 4.9: WORKING WITH FILE COMMAND Initially, in sample output 4.9, we tried to get more information about mynotes. The file command outputted that mynotes is an English text file. Moreover, we wanted to check the command ls which is an executable 32 bit file. Whilst, libproject.so contained in the /lib/ directory is a dynamic link library necessary for the development of various applications. The last file, we checked was public_html which is a directory according to file command output. PAGE 10

11 Typically, files can be categorized into two broad classes. The first includes those files which have text content. The second refers to those that do not contain text. The former class is known as text files while the latter is called non-text files. In the next subsection, we first consider text files and we will explore several commands associated with them. However, we omit any details regarding non-text files. WORKING WITH TEXT FILES Typically, text files contain printable characters and are divided into lines. These lines are separated by the newline control character. So far, we have worked with text files as we had the opportunity to create, open and edit them using the emacs or the vi editor. In later stages, we will see that text files can also contain scripts required for shell programming. Sometimes, it is necessary to find out more information about files without opening them, using text editors. This can be accomplished, for example, with the more command, we have seen in previous sections. However, this command usually prints out on screen the whole contents of a file given as argument. Instead, of using these traditional method, we will concentrate into easier methods, in order to examine specific parts of our text files. First, we need to use the file command in order to check the consents of our file. Then, and provided that our file is a text file, we can move forward by using some specific UNIX commands. For instance, we may need to see the first 5 lines of our text file. This can be accomplished by the UNIX command head. Its syntax is shown bellow. SYNTAX head -n head n 5 myfilename COMMAND SYNTAX 4.3: head -n <number> <argument> The head command will allow us to display the contents of myfile on the standard output. The option n associated with an integer e.g. 5 forces the command to display the first five lines of the file given as argument. This command also can be used without the argument n; the execution of it without any option will instruct the shell to output no more that 10 lines of our PAGE 11

12 file. Note that we can substitute the option n <number> with -<number> i.e. -4 if we wish to display the first four lines our text file. In addition, we can use absolute or relative path names and we can also enter multiple arguments. This will force head to place a small banner before displaying the contents of each file given as an argument. The following sample output (4.10) illustrates this. head 12 tiger% head mytext L1 L2 L3 L4 L5 L6 L7 L8 L9 L10 13 tiger% head -n 5 mytext L1 L2 L3 L4 L5 14 tiger% head n 4 mynotes mytext ==> mynotes <== Hello, ==> mytext <== L1 15 tiger% SAMPLE OUTPUT 4.10: WORKING WITH head COMMAND As shown, mytext file contains text that consists of lines numbered with an alphanumeric identifier. Although, the file contains more than 10 lines, the execution of head command without arguments showed only 10 lines. However, as we wanted to display exactly 5 lines, we used the n 5 option. The execution of this command using more than one given arguments, namely mynotes and mytext, displayed the first line of each text file separated by a banner i.e. ==> mytext <==. Note that, these commands allow us to work with text files but also can be very useful for other purposes if they are used with input/output redirection PAGE 12

13 and piping. Although, we will consider these concepts in later stages, at this point we can consider an example. Assuming that we want to find out the most recently modified file in our current directory, we can combine this command with the command ls tl. In fact, we can execute this command and send any data obtained as an output from ls tl directly to command head n 2 as input. The outcome will reflect displaying the first file that has been recently changed. head 15 tiger% ls -tl head -n 1 total tiger% ls -tl head -n 2 total rw svigkoi staff 17 tiger% 44 May 11 16:09 mytext SAMPLE OUTPUT 4.10: WORKING WITH head COMMAND The command ls tl head n 1 consists of two simpler UNIX commands combined with the pipe character ( ). The execution of it starts with the execution of the most left hand side command (ls tl) which should display on screen the contents of our current directory. However, in this case we forced the output of the ls tl command to the input of the head n 1. Then the last command displayed the first line of the ls output. As shown, the first line was total 1448 which is not our desirable outcome. This happened because ls tl displays first an integer that shows the number of elements contained in our current directory. Therefore, we changed slightly this composite command and instead of displaying only the first line by using the number 1, we forced this command to display the first two lines as output. This resulted having as output the total number of elements contained in our current directory and the most recently modified file which is mytext. In a similar fashion like the head command, we can use the tail command. However, the tail command will display the last lines of a text file. The syntax is similar to the head command. PAGE 13

14 SYNTAX tail tail n <number> myfilename COMMAND SYNTAX 4.4: tail -n <number> <argument> The only difference with head is that when we enter a number for displaying a specific number of lines, we start counting from the end. For example, 5 will give us the last 5 lines of a text file. We can use multiple arguments associated with absolute and relative names. tail 17 tiger% tail -3 mytext L12 L13 18 tiger% SAMPLE OUTPUT 4.11: WORKING WITH head COMMAND In sample output 4.11, we executed tail command with option -3 given the argument mytext. The execution of this command displayed the last three lines of the contents of our file. The last command, we consider in this section is the wc command associated with several options. The importance of this command is that it allows us to get an estimate of how big in size is a file placed in our UNIX account. The different options accepted by this command can show us the number of lines, option l, the number of words, option w and the numbers of characters (bytes), option c. SYNTAX wc wc [lwc] <filename> COMMAND SYNTAX 4.5: wc [twc] <fileneme> If it is used without any options, it will display information that reflects these three options together. Remember that wc cannot be used with directories as arguments. PAGE 14

15 COMPARING TEXT FILES Sometimes, we also need to compare two files in order to see if there are any differences between them. Typically, this situation arises when we have two similar files and need to identify any changes. For example, we may have two shell script files, one older that the other one edited several times. As we may have lost track of any changes made, we can use the diff command to compare these files. SYNTAX diff diff <file1> <file2> COMMAND SYNTAX 4.6: diff <file1> <file2> When two files compared are identical there is no output. The more output means that more lines are not identical. This is an indicator that your files are very different. In case there are differences, you usually get an output like that 2c2. This actually indicates that the line number in the first file differs from its counterpart, also at line 2 in the second file. The character between the numbers lines which can be c, d, or a means that for c the numbered lines in the first file should be changed to become the numbered lines of the second file; a indicates that lines must be added and d means that lines must be deleted in order to transform the first file into the second one. Lines outputted by the diff command with the sign < indicate output from the first file while > indicate output from the second file. Let us assume we have two files called file1 and file2 with contents: file1: file2: This is my file1 file and here I am going to keep some notes That is my file2 file and there I am going to keep some notes FIGURE 4.1: CONTENTS OF FILE1 AND FILE2 Having these two files, we can apply the diff command and then we can describe its output. PAGE 15

16 diff 67 tiger% diff file1 file2 2,3c2,3 < file1 file and < here I am going to --- > file2 file and > there I am going to 68 tiger% SAMPLE OUTPUT 4.12: WORKING WITH head COMMAND The string 2,3c2,3 indicates that lines 2, 3 from the first file must be changed to match lines 2, 3 from the second file. Note that when diff command finds any differences, it starts checking ahead in both files, in order to find if there are further differences. This mechanism allows this command to be able to find out added lines, deleted or changed lines. Although, this command can provide to us with some help in comparing files, perhaps its directives for making changes to the first argument (file) in order to match the second one can be ignored. This is very common as users look only at the differences of each line instead of dealing with the directives. Other options of this command include b that discards any spaces or any tabs in each line. Whilst, the option c allows diff to display three lines before and three lines after a line that should be changes. FILTERING TEXT FILES Sometimes, the task of processing text files requires that we wish to find patterns of repeated data that should be located and removed. The command that deals with this task is known as uniq. SYNTAX uniq uniq option filename COMMAND SYNTAX 4.7: uniq -option <argument> PAGE 16

17 For example, we may have a file with contents like the one described below. ffff zzzz rrrr tttt bbbb bbbb bbbb ffff ffff FIGURE 4.2: CONTENTS OF patterns As, we can see there are several strings that are identical. If we wish to filter out any consecutive strings, we can use uniq without any options. If we wish to count how many times each string has been repeated, we need the option c, as shown below. uniq 6 tiger% uniq patterns ffff zzzz rrrr tttt bbbb ffff 7 tiger% uniq -c patterns 1 ffff 1 zzzz 1 rrrr 1 tttt 3 bbbb 2 ffff 8 tiger% SAMPLE OUTPUT 4.13: WORKING WITH uniq COMMAND PAGE 17

18 How, we assume that we need to find out only those strings that are repeated. This is carried out by the option d that stands for duplicate. On the contrary, we may wish to find out only those that are not repeated at all. Then, the option u that stands for unique is suffice. uniq 3 tiger% uniq -d patterns bbbb ffff 4 tiger% uniq -u patterns ffff zzzz rrrr tttt 5 tiger% SAMPLE OUTPUT 4.14: WORKING WITH uniq COMMAND If we will try to compare the output of uniq d patterns with the file contents shown previously (figure 4.2), we can see that this option showed us only the duplicates. Whilst, the option u allowed us to see those contents that have not been repeated in the file patterns. In case, we need to sort any contents included in a file, we can use the command sort. SYNTAX short short <filename> COMMAND SYNTAX 4.8: short <filename> An example is given bellow: sort 17 tiger% sort patterns bbbb bbbb bbbb ffff ffff ffff rrrr tttt zzzz PAGE 18

19 18 tiger% SAMPLE OUTPUT 4.15: WORKING WITH short COMMAND It is clear that the contents of file patterns were processed and sorted out in an alphabetical order starting from string bbbb and finishing at zzzz. The syntax of command short is illustrated bellow. Files may contain data that should be concatenated in order to construct tables of probably related data. In this case, we need to use the command paste. In fact, this command accepts as an argument two or more files and concatenates each line of each corresponding file. The outcome is a table in which continents are placed in columns separated by the character TAB. SYNTAX paste paste <file1> <file2> COMMAND SYNTAX 4.9: paste <file1> <file2> Let us assume that we have two files with filenames file1 and file2 and contents: file1: file2: one three five seven two four six eight FIGURE 4.3: CONTENTS OF file1 and file2 Applying the paste command to file1 and file2, the output of the corresponding command should be: paste 14 tiger% more file1 one three five seven PAGE 19

20 15 tiger% more file2 two four six eight 16 tiger% paste file1 file2 one two three four five six seven eight 17 tiger% SAMPLE OUTPUT 4.16: WORKING WITH short COMMAND As illustrated, paste concatenated each line of file1 with each line of file2 and then outputed the result in columns. Typically, the uniq and paste commands are not used regularly. However, if used they allow us to save a great amount of time on editing files. Moreover, we can also extract data from tables. For example, consider that we need to extract only the inode identifiers from the output given by the command ls il. This can be accomplished by the command cut. SYNTAX cut cut [c]-[f] <filename> COMMAND SYNTAX 4.9: cut [c]-[f]<file> Supposing that we have a file mytable that contains data arranged in columns and we need to extract any data stored in the second column. In the sample output (4.17), we will see how we can do this. However, first let us introduce a table contained in file mytable Ioannis Debit Tom Debit Tom Credit Ioannis Debit FIGURE 4.4: CONTENTS OF mytable PAGE 20

21 At this stage, we wish to know the names of people that debited or credited a shared account held in bank XYZ plc. cut 20 tiger% cut -f3 -d' ' bank Ioannis Tom Tom Ioannis 21 tiger% SAMPLE OUTPUT 4.17: WORKING WITH cut COMMAND Option f followed by number 3 indicated that we are looking for data contained in column (field) 3. Moreover, as columns may be separated by spaces, the control character TAB or any other characters; we had to indicate the delimiter by using the option d to indicate that columns are separated by spaces. An alternative method would be that to select a range of characters. Although, we provide an example, this method is not very flexible when the length of data stored in columns is not of fixed size. cut 21 tiger% cut -c1-8 bank tiger% SAMPLE OUTPUT 4.18: WORKING WITH cut COMMAND By executing cut -c1-8 bank, we managed to see all the transaction dates regarding the shared account referred in the previous example. The option c followed by the range 1-8 corresponds to characters 1 until 8 of each line included in the bank file. The last command, we will consider is known as fold. In general, we may need to process all of our input included in a file. However, we need our output to fit in specific width determined by a number of characters. Note that PAGE 21

22 sometimes we may have text files that consist of many hundreds of characters per line. Therefore, reformatting output is an essential process. SYNTAX fold fold w <number> <file> COMMAND SYNTAX 4.10: fold w <number> <file> 4.3 FINDING FILES Finding files stored in various directories can be considered as a daunting and time consuming task. This situation is worse in the UNIX operating system as it is usually shared among hundred users. For instance, consider the University of Westminster UNIX system with thousands of users including academic staff and students. The find command allows us to find files and directories dispersed over the whole UNIX directory structure. SYNTAX find find <directory> -option <filename> -print COMMAND SYNTAX 4.11: fold w <number> <file> The <directory> indicates the directory in which the find command will start searching. This may be a subdirectory in our current directory, it can be the root directory or another one specified by an absolute or relative path. Moreover, we can also enter multiple directories. option corresponds to several options available for searching. For instance, we can search for files based on a given inode number or we may need to find empty directories or files and so on. <filename> corresponds to the name of a file and can also contain wildcards. In this case the argument should be included in apostrophes. Whilst print will instruct the find command to print out the full path of each file found. PAGE 22

23 OPTION -empty -gid n -group name -unum n -links n -name pattern -perm -size n -user name DESCRIPTION Searches for empty files and directories Search for a file with a specific group ID Indicates file s group name Indicated inode identifier Seraching for a file with a specified number of links Seraches for a file name with a certain pattern Searches for specific permissions Searches based on file size Searches for files of a given user TABLE 4.1: FIND COMMAND OPTIONS Assuming that we wish to find the exact location of all mynotes files stored in our current directory and in any subdirectories contained in it; we need to enter the following described in sample output tiger% find ~ -name mynotes -print /home/impala/u1/staff01/svigkoi/one/mynotes /home/impala/u1/staff01/svigkoi/mynotes 6 tiger% SAMPLE OUTPUT 4.18: FIND COMMAND As shown, mynotes files can be found in our current directory and in /one/ subdirectory of our current directory. Note that this does not imply that both files are identical. They may have different content, they may be just links. PAGE 23

24 4.5 EXERCISES 1. Using vi editor create a file named mypatterns and enter the following text: aaaa zzzz 1111 oo 8888 aaaa aaaa wwww wwww dddd oo kkk LLLL qqqqq LLLL Use the file command to find out about the contents of mypatterns file; - Use wc in order to find out: o The number of lines o The number of bytes (characters) used; o The number of words contained. o Display all this information at once. - Filter this file and discard any duplication contained - Count ho many times each pattern is repeated - List all duplicate patterns - List all patterns that are unique 2. Create a directory named patterns and then copy mypatterns file into it. PAGE 24

25 - From your $HOME create a soft link to mypatterns contained in the patterns directory. The link file should be named as smypatterns and be located in your $HOME. - Check with ls l to see if the link has been created and find out if it points to the correct file in the subdirectory provided. - Use the vi editor and open the link file (smypatterns). Then, o Add the string hhhh at the end of this file. Save your file and close vi editor. o Go to patterns directory: use the more command to make sure your file has been updated. Or stay in your $HOME and use the more command with a relative path that corresponds to smypatterns file. 3. Create a directory called table. Move in this directory and create two files file1 and file2 with contents file1 contents: Line 1.1 Line 1.2. Line 1.3 Line 1.4 Line 1.5 file2 contents: Line 2.1 Line 2.2. Line 2.3 Line 2.4 Line 2.5 Generate a table that consists of the concatenation of these two files [HINT: Use the paste command] PAGE 25

26 Create a hard links for both files with names hfile1 and hfile2, respectively. Check if the number of links has been increased to number 2. [HINT: Use ls with the appropriate option. Make sure it will also display the inode number of each file] Move the hard link files into your current directory. Open each of them using vi editor and enter at the end that: o For hfile1 add Line 1.6, save and close file; o For hfile2 add Line 2.6, save and close file. Generate a table that consists of the concatenation of these two files. 4. Find if you have any mynotes files in your $HOME directory or in any subdirectories of it. 5. In $HOME create a file with filename bankacc. The contents should be: Debit $200 Tom Credit $100 Tom Debit $100 Sarah Credit $100 Tom Debit $200 Helen List all names that have used this shared bank account. List all the amounts that have been credited or debited so far. List all dates by using two approached as described in an example elaborated previously. The first approach should be character based and the second should be field based. 6. List all inode identifiers of all your files included in your $HOME. [HINT: Use the notion of creating a pipe of UNIX commands] 7. Repeat exercise 6 and put in order (sort) inode numbers. PAGE 26

S E C T I O N O V E R V I E W

S E C T I O N O V E R V I E W AN INTRODUCTION TO SHELLS S E C T I O N O V E R V I E W Continuing from last section, we are going to learn about the following concepts: understanding quotes and escapes; considering the importance of

More information

S E C T I O N O V E R V I E W

S E C T I O N O V E R V I E W PROGRAM CONTROL, FILE ARCHIVING, ENVIRONMENT AND SCRIPTS S E C T I O N O V E R V I E W Continuing from last section, we are going to learn about the following concepts: controlling programs; working with

More information

Table of contents. Our goal. Notes. Notes. Notes. Summer June 29, Our goal is to see how we can use Unix as a tool for developing programs

Table of contents. Our goal. Notes. Notes. Notes. Summer June 29, Our goal is to see how we can use Unix as a tool for developing programs Summer 2010 Department of Computer Science and Engineering York University Toronto June 29, 2010 1 / 36 Table of contents 1 2 3 4 2 / 36 Our goal Our goal is to see how we can use Unix as a tool for developing

More information

S E C T I O N O V E R V I E W

S E C T I O N O V E R V I E W INPUT, OUTPUT REDIRECTION, PIPING AND PROCESS CONTROL S E C T I O N O V E R V I E W In this section, we will learn about: input redirection; output redirection; piping; process control; 5.1 INPUT AND OUTPUT

More information

Files and Directories

Files and Directories CSCI 2132: Software Development Files and Directories Norbert Zeh Faculty of Computer Science Dalhousie University Winter 2019 Files and Directories Much of the operation of Unix and programs running on

More information

Chapter-3. Introduction to Unix: Fundamental Commands

Chapter-3. Introduction to Unix: Fundamental Commands Chapter-3 Introduction to Unix: Fundamental Commands What You Will Learn The fundamental commands of the Unix operating system. Everything told for Unix here is applicable to the Linux operating system

More information

18-Sep CSCI 2132 Software Development Lecture 6: Links and Inodes. Faculty of Computer Science, Dalhousie University. Lecture 6 p.

18-Sep CSCI 2132 Software Development Lecture 6: Links and Inodes. Faculty of Computer Science, Dalhousie University. Lecture 6 p. Lecture 6 p.1 Faculty of Computer Science, Dalhousie University CSCI 2132 Software Development Lecture 6: Links and s 18-Sep-2017 Location: Goldberg CS 127 Time: 14:35 15:25 Instructor: Vlado Keselj Previous

More information

CSE 390a Lecture 2. Exploring Shell Commands, Streams, and Redirection

CSE 390a Lecture 2. Exploring Shell Commands, Streams, and Redirection 1 CSE 390a Lecture 2 Exploring Shell Commands, Streams, and Redirection slides created by Marty Stepp, modified by Jessica Miller & Ruth Anderson http://www.cs.washington.edu/390a/ 2 Lecture summary Unix

More information

A Brief Introduction to the Linux Shell for Data Science

A Brief Introduction to the Linux Shell for Data Science A Brief Introduction to the Linux Shell for Data Science Aris Anagnostopoulos 1 Introduction Here we will see a brief introduction of the Linux command line or shell as it is called. Linux is a Unix-like

More information

LAB 8 (Aug 4/5) Unix Utilities

LAB 8 (Aug 4/5) Unix Utilities Aug 4/5 Due: Aug 11 in class Name: CSE number: LAB 8 (Aug 4/5) Unix Utilities The purpose of this lab exercise is for you to get some hands-on experience on using some fundamental Unix utilities (commands).

More information

CSE 303 Lecture 2. Introduction to bash shell. read Linux Pocket Guide pp , 58-59, 60, 65-70, 71-72, 77-80

CSE 303 Lecture 2. Introduction to bash shell. read Linux Pocket Guide pp , 58-59, 60, 65-70, 71-72, 77-80 CSE 303 Lecture 2 Introduction to bash shell read Linux Pocket Guide pp. 37-46, 58-59, 60, 65-70, 71-72, 77-80 slides created by Marty Stepp http://www.cs.washington.edu/303/ 1 Unix file system structure

More information

Unix as a Platform Exercises. Course Code: OS-01-UNXPLAT

Unix as a Platform Exercises. Course Code: OS-01-UNXPLAT Unix as a Platform Exercises Course Code: OS-01-UNXPLAT Working with Unix 1. Use the on-line manual page to determine the option for cat, which causes nonprintable characters to be displayed. Run the command

More information

CSE 390a Lecture 2. Exploring Shell Commands, Streams, Redirection, and Processes

CSE 390a Lecture 2. Exploring Shell Commands, Streams, Redirection, and Processes CSE 390a Lecture 2 Exploring Shell Commands, Streams, Redirection, and Processes slides created by Marty Stepp, modified by Jessica Miller & Ruth Anderson http://www.cs.washington.edu/390a/ 1 2 Lecture

More information

Files

Files http://www.cs.fsu.edu/~langley/cop3353-2013-1/reveal.js-2013-02-11/02.html?print-pdf 02/11/2013 10:55 AM Files A normal "flat" file is a collection of information. It's usually stored somewhere reasonably

More information

Introduction: What is Unix?

Introduction: What is Unix? Introduction Introduction: What is Unix? An operating system Developed at AT&T Bell Labs in the 1960 s Command Line Interpreter GUIs (Window systems) are now available Introduction: Unix vs. Linux Unix

More information

CSC209. Software Tools and Systems Programming. https://mcs.utm.utoronto.ca/~209

CSC209. Software Tools and Systems Programming. https://mcs.utm.utoronto.ca/~209 CSC209 Software Tools and Systems Programming https://mcs.utm.utoronto.ca/~209 What is this Course About? Software Tools Using them Building them Systems Programming Quirks of C The file system System

More information

LAB 8 (Aug 4/5) Unix Utilities

LAB 8 (Aug 4/5) Unix Utilities Aug 4/5 Due: Aug 11 in class Name: CSE number: LAB 8 (Aug 4/5) Unix Utilities The purpose of this lab exercise is for you to get some hands-on experience on using some fundamental Unix utilities (commands).

More information

Unix as a Platform Exercises + Solutions. Course Code: OS 01 UNXPLAT

Unix as a Platform Exercises + Solutions. Course Code: OS 01 UNXPLAT Unix as a Platform Exercises + Solutions Course Code: OS 01 UNXPLAT Working with Unix Most if not all of these will require some investigation in the man pages. That's the idea, to get them used to looking

More information

Introduction to Linux

Introduction to Linux Introduction to Linux M Tech CS I 2015-16 Arijit Bishnu Debapriyo Majumdar Sourav Sengupta Mandar Mitra Login, Logout, Change password $ ssh, ssh X secure shell $ ssh www.isical.ac.in $ ssh 192.168 $ logout,

More information

5/8/2012. Exploring Utilities Chapter 5

5/8/2012. Exploring Utilities Chapter 5 Exploring Utilities Chapter 5 Examining the contents of files. Working with the cut and paste feature. Formatting output with the column utility. Searching for lines containing a target string with grep.

More information

UNIX files searching, and other interrogation techniques

UNIX files searching, and other interrogation techniques UNIX files searching, and other interrogation techniques Ways to examine the contents of files. How to find files when you don't know how their exact location. Ways of searching files for text patterns.

More information

Practical Session 0 Introduction to Linux

Practical Session 0 Introduction to Linux School of Computer Science and Software Engineering Clayton Campus, Monash University CSE2303 and CSE2304 Semester I, 2001 Practical Session 0 Introduction to Linux Novell accounts. Every Monash student

More information

Shell Programming Overview

Shell Programming Overview Overview Shell programming is a way of taking several command line instructions that you would use in a Unix command prompt and incorporating them into one program. There are many versions of Unix. Some

More information

5/8/2012. Creating and Changing Directories Chapter 7

5/8/2012. Creating and Changing Directories Chapter 7 Creating and Changing Directories Chapter 7 Types of files File systems concepts Using directories to create order. Managing files in directories. Using pathnames to manage files in directories. Managing

More information

QUESTION BANK ON UNIX & SHELL PROGRAMMING-502 (CORE PAPER-2)

QUESTION BANK ON UNIX & SHELL PROGRAMMING-502 (CORE PAPER-2) BANK ON & SHELL PROGRAMMING-502 (CORE PAPER-2) TOPIC 1: VI-EDITOR MARKS YEAR 1. Explain set command of vi editor 2 2011oct 2. Explain the modes of vi editor. 7 2013mar/ 2013 oct 3. Explain vi editor 5

More information

On successful completion of the course, the students will be able to attain CO: Experiment linked. 2 to 4. 5 to 8. 9 to 12.

On successful completion of the course, the students will be able to attain CO: Experiment linked. 2 to 4. 5 to 8. 9 to 12. CIE- 25 Marks Government of Karnataka Department of Technical Education Bengaluru Course Title: Linux Lab Scheme (L:T:P) : 0:2:4 Total Contact Hours: 78 Type of Course: Tutorial, Practical s & Student

More information

CSCI 2132 Software Development. Lecture 4: Files and Directories

CSCI 2132 Software Development. Lecture 4: Files and Directories CSCI 2132 Software Development Lecture 4: Files and Directories Instructor: Vlado Keselj Faculty of Computer Science Dalhousie University 12-Sep-2018 (4) CSCI 2132 1 Previous Lecture Some hardware concepts

More information

Scripting Languages Course 1. Diana Trandabăț

Scripting Languages Course 1. Diana Trandabăț Scripting Languages Course 1 Diana Trandabăț Master in Computational Linguistics - 1 st year 2017-2018 Today s lecture Introduction to scripting languages What is a script? What is a scripting language

More information

Practical 4. Linux Commands: Working with Directories

Practical 4. Linux Commands: Working with Directories Practical 4 Linux Commands: Working with Directories 1. pwd: pwd stands for Print Working Directory. As the name states, command pwd prints the current working directory or simply the directory user is,

More information

commandname flags arguments

commandname flags arguments Unix Review, additional Unix commands CS101, Mock Introduction This handout/lecture reviews some basic UNIX commands that you should know how to use. A more detailed description of this and other commands

More information

Using UNIX. -rwxr--r-- 1 root sys Sep 5 14:15 good_program

Using UNIX. -rwxr--r-- 1 root sys Sep 5 14:15 good_program Using UNIX. UNIX is mainly a command line interface. This means that you write the commands you want executed. In the beginning that will seem inferior to windows point-and-click, but in the long run the

More information

Unix/Linux Primer. Taras V. Pogorelov and Mike Hallock School of Chemical Sciences, University of Illinois

Unix/Linux Primer. Taras V. Pogorelov and Mike Hallock School of Chemical Sciences, University of Illinois Unix/Linux Primer Taras V. Pogorelov and Mike Hallock School of Chemical Sciences, University of Illinois August 25, 2017 This primer is designed to introduce basic UNIX/Linux concepts and commands. No

More information

Operating Systems, Unix Files and Commands SEEM

Operating Systems, Unix Files and Commands SEEM Operating Systems, Unix Files and Commands SEEM 3460 1 Major Components of Operating Systems (OS) Process management Resource management CPU Memory Device File system Bootstrapping SEEM 3460 2 Programs

More information

A Big Step. Shell Scripts, I/O Redirection, Ownership and Permission Concepts, and Binary Numbers

A Big Step. Shell Scripts, I/O Redirection, Ownership and Permission Concepts, and Binary Numbers A Big Step Shell Scripts, I/O Redirection, Ownership and Permission Concepts, and Binary Numbers Copyright 2006 2009 Stewart Weiss What a shell really does Here is the scoop on shells. A shell is a program

More information

CSC209H Lecture 1. Dan Zingaro. January 7, 2015

CSC209H Lecture 1. Dan Zingaro. January 7, 2015 CSC209H Lecture 1 Dan Zingaro January 7, 2015 Welcome! Welcome to CSC209 Comments or questions during class? Let me know! Topics: shell and Unix, pipes and filters, C programming, processes, system calls,

More information

Introduction to Linux

Introduction to Linux Introduction to Linux The command-line interface A command-line interface (CLI) is a type of interface, that is, a way to interact with a computer. Window systems, punched cards or a bunch of dials, buttons

More information

2) clear :- It clears the terminal screen. Syntax :- clear

2) clear :- It clears the terminal screen. Syntax :- clear 1) cal :- Displays a calendar Syntax:- cal [options] [ month ] [year] cal displays a simple calendar. If arguments are not specified, the current month is displayed. In addition to cal, the ncal command

More information

Oxford University Computing Services. Getting Started with Unix

Oxford University Computing Services. Getting Started with Unix Oxford University Computing Services Getting Started with Unix Unix c3.1/2 Typographical Conventions Listed below are the typographical conventions used in this guide. Names of keys on the keyboard are

More information

Introduction to Unix: Fundamental Commands

Introduction to Unix: Fundamental Commands Introduction to Unix: Fundamental Commands Ricky Patterson UVA Library Based on slides from Turgut Yilmaz Istanbul Teknik University 1 What We Will Learn The fundamental commands of the Unix operating

More information

AC109/AT109 UNIX & SHELL PROGRAMMING DEC 2014

AC109/AT109 UNIX & SHELL PROGRAMMING DEC 2014 Q.2 a. Explain the principal components: Kernel and Shell, of the UNIX operating system. Refer Page No. 22 from Textbook b. Explain absolute and relative pathnames with the help of examples. Refer Page

More information

Chapter 4. Unix Tutorial. Unix Shell

Chapter 4. Unix Tutorial. Unix Shell Chapter 4 Unix Tutorial Users and applications interact with hardware through an operating system (OS). Unix is a very basic operating system in that it has just the essentials. Many operating systems,

More information

Essentials for Scientific Computing: Bash Shell Scripting Day 3

Essentials for Scientific Computing: Bash Shell Scripting Day 3 Essentials for Scientific Computing: Bash Shell Scripting Day 3 Ershaad Ahamed TUE-CMS, JNCASR May 2012 1 Introduction In the previous sessions, you have been using basic commands in the shell. The bash

More information

IMPORTANT: Logging Off LOGGING IN

IMPORTANT: Logging Off LOGGING IN These are a few basic Unix commands compiled from Unix web sites, and printed materials. The main purpose is to help a beginner to go around with fewer difficulties. Therefore, I will be adding to this

More information

CHAPTER 1 UNIX FOR NONPROGRAMMERS

CHAPTER 1 UNIX FOR NONPROGRAMMERS CHAPTER 1 UNIX FOR NONPROGRAMMERS The man command is used to display the manual entry associated with word entered as argument. The -k option is used displays a list of manual entries that contain entered

More information

CSN08101 Digital Forensics. Module Leader: Dr Gordon Russell Lecturers: Robert Ludwiniak

CSN08101 Digital Forensics. Module Leader: Dr Gordon Russell Lecturers: Robert Ludwiniak CSN08101 Digital Forensics Lecture 2: Essential Linux for Forensics Module Leader: Dr Gordon Russell Lecturers: Robert Ludwiniak Essential Linux for Forensics You will learn in this lecture: Essential

More information

PESIT Bangalore South Campus

PESIT Bangalore South Campus INTERNAL ASSESSMENT TEST - 2 Date : 20/09/2016 Max Marks : 0 Subject & Code : Unix Shell Programming (15CS36) Section : 3 rd Sem ISE/CSE Name of faculty : Prof Ajoy Time : 11:30am to 1:00pm SOLUTIONS 1

More information

Unix/Linux Basics. Cpt S 223, Fall 2007 Copyright: Washington State University

Unix/Linux Basics. Cpt S 223, Fall 2007 Copyright: Washington State University Unix/Linux Basics 1 Some basics to remember Everything is case sensitive Eg., you can have two different files of the same name but different case in the same folder Console-driven (same as terminal )

More information

Mills HPC Tutorial Series. Linux Basics I

Mills HPC Tutorial Series. Linux Basics I Mills HPC Tutorial Series Linux Basics I Objectives Command Line Window Anatomy Command Structure Command Examples Help Files and Directories Permissions Wildcards and Home (~) Redirection and Pipe Create

More information

CST8207: GNU/Linux Operating Systems I Lab Six Linux File System Permissions. Linux File System Permissions (modes) - Part 1

CST8207: GNU/Linux Operating Systems I Lab Six Linux File System Permissions. Linux File System Permissions (modes) - Part 1 Student Name: Lab Section: Linux File System Permissions (modes) - Part 1 Due Date - Upload to Blackboard by 8:30am Monday March 12, 2012 Submit the completed lab to Blackboard following the Rules for

More information

Scripting. Shell Scripts, I/O Redirection, Ownership and Permission Concepts, and Binary Numbers

Scripting. Shell Scripts, I/O Redirection, Ownership and Permission Concepts, and Binary Numbers Scripting Shell Scripts, I/O Redirection, Ownership and Permission Concepts, and Binary Numbers Adapted from Practical Unix and Programming Hunter College Copyright 2006 2009 Stewart Weiss What a shell

More information

genome[phd14]:/home/people/phd14/alignment >

genome[phd14]:/home/people/phd14/alignment > Unix Introduction to Unix Shell There is a special type of window called shell or terminalwindow. Terminal windows are the principal vehicle of interaction with a UNIX machine. Their function is to perform

More information

Principles of Bioinformatics. BIO540/STA569/CSI660 Fall 2010

Principles of Bioinformatics. BIO540/STA569/CSI660 Fall 2010 Principles of Bioinformatics BIO540/STA569/CSI660 Fall 2010 Lecture Five Practical Computing Skills Emphasis This time it s concrete, not abstract. Fall 2010 BIO540/STA569/CSI660 3 Administrivia Monday

More information

Laboratory 1 Semester 1 11/12

Laboratory 1 Semester 1 11/12 CS2106 National University of Singapore School of Computing Laboratory 1 Semester 1 11/12 MATRICULATION NUMBER: In this lab exercise, you will get familiarize with some basic UNIX commands, editing and

More information

CSC UNIX System, Spring 2015

CSC UNIX System, Spring 2015 CSC 352 - UNIX System, Spring 2015 Study guide for the CSC352 midterm exam (20% of grade). Dr. Dale E. Parson, http://faculty.kutztown.edu/parson We will have a midterm on March 19 on material we have

More information

UNIX Shell Programming

UNIX Shell Programming $!... 5:13 $$ and $!... 5:13.profile File... 7:4 /etc/bashrc... 10:13 /etc/profile... 10:12 /etc/profile File... 7:5 ~/.bash_login... 10:15 ~/.bash_logout... 10:18 ~/.bash_profile... 10:14 ~/.bashrc...

More information

Links, basic file manipulation, environmental variables, executing programs out of $PATH

Links, basic file manipulation, environmental variables, executing programs out of $PATH Links, basic file manipulation, environmental variables, executing programs out of $PATH Laboratory of Genomics & Bioinformatics in Parasitology Department of Parasitology, ICB, USP The $PATH PATH (which

More information

Part I. Introduction to Linux

Part I. Introduction to Linux Part I Introduction to Linux 7 Chapter 1 Linux operating system Goal-of-the-Day Familiarisation with basic Linux commands and creation of data plots. 1.1 What is Linux? All astronomical data processing

More information

The Unix Shell & Shell Scripts

The Unix Shell & Shell Scripts The Unix Shell & Shell Scripts You should do steps 1 to 7 before going to the lab. Use the Linux system you installed in the previous lab. In the lab do step 8, the TA may give you additional exercises

More information

Contents. Note: pay attention to where you are. Note: Plaintext version. Note: pay attention to where you are... 1 Note: Plaintext version...

Contents. Note: pay attention to where you are. Note: Plaintext version. Note: pay attention to where you are... 1 Note: Plaintext version... Contents Note: pay attention to where you are........................................... 1 Note: Plaintext version................................................... 1 Hello World of the Bash shell 2 Accessing

More information

More Scripting Techniques Scripting Process Example Script

More Scripting Techniques Scripting Process Example Script More Scripting Techniques Scripting Process Example Script 1 arguments to scripts positional parameters input using read exit status test program, also known as [ if statements error messages 2 case statement

More information

Introduction to Linux

Introduction to Linux Introduction to Linux University of Bristol - Advance Computing Research Centre 1 / 47 Operating Systems Program running all the time Interfaces between other programs and hardware Provides abstractions

More information

COMS 6100 Class Notes 3

COMS 6100 Class Notes 3 COMS 6100 Class Notes 3 Daniel Solus September 1, 2016 1 General Remarks The class was split into two main sections. We finished our introduction to Linux commands by reviewing Linux commands I and II

More information

Reading and manipulating files

Reading and manipulating files Reading and manipulating files Goals By the end of this lesson you will be able to Read files without using text editors Access specific parts of files Count the number of words and lines in a file Sort

More information

The UNIX File System

The UNIX File System The UNIX File System Magnus Johansson (May 2007) 1 UNIX file system A file system is created with mkfs. It defines a number of parameters for the system as depicted in figure 1. These paremeters include

More information

Unix Introduction to UNIX

Unix Introduction to UNIX Unix Introduction to UNIX Get Started Introduction The UNIX operating system Set of programs that act as a link between the computer and the user. Developed in 1969 by a group of AT&T employees Various

More information

Table Of Contents. 1. Zoo Information a. Logging in b. Transferring files 2. Unix Basics 3. Homework Commands

Table Of Contents. 1. Zoo Information a. Logging in b. Transferring files 2. Unix Basics 3. Homework Commands Table Of Contents 1. Zoo Information a. Logging in b. Transferring files 2. Unix Basics 3. Homework Commands Getting onto the Zoo Type ssh @node.zoo.cs.yale.edu, and enter your netid pass when prompted.

More information

ITST Searching, Extracting & Archiving Data

ITST Searching, Extracting & Archiving Data ITST 1136 - Searching, Extracting & Archiving Data Name: Step 1 Sign into a Pi UN = pi PW = raspberry Step 2 - Grep - One of the most useful and versatile commands in a Linux terminal environment is the

More information

INSE Lab 1 Introduction to UNIX Fall 2017

INSE Lab 1 Introduction to UNIX Fall 2017 INSE 6130 - Lab 1 Introduction to UNIX Fall 2017 Updated by: Paria Shirani Overview In this lab session, students will learn the basics of UNIX /Linux commands. They will be able to perform the basic operations:

More information

Unix Internal Assessment-2 solution. Ans:There are two ways of starting a job in the background with the shell s & operator and the nohup command.

Unix Internal Assessment-2 solution. Ans:There are two ways of starting a job in the background with the shell s & operator and the nohup command. Unix Internal Assessment-2 solution 1 a.explain the mechanism of process creation. Ans: There are three distinct phases in the creation of a process and uses three important system calls viz., fork, exec,

More information

The Online Unix Manual

The Online Unix Manual ACS-294-001 Unix (Winter Term, 2018-2019) Page 14 The Online Unix Manual Unix comes with a large, built-in manual that is accessible at any time from your terminal. The Online Manual is a collection of

More information

Basic UNIX Commands BASIC UNIX COMMANDS. 1. cat command. This command is used to create a file in unix. Syntax: $ cat filename

Basic UNIX Commands BASIC UNIX COMMANDS. 1. cat command. This command is used to create a file in unix. Syntax: $ cat filename Basic UNIX Commands BASIC UNIX COMMANDS 1. cat This is used to create a file in unix. $ cat >filename This is also used for displaying contents in a file. $ cat filename 2. ls It displays the list of files

More information

File Commands. Objectives

File Commands. Objectives File Commands Chapter 2 SYS-ED/Computer Education Techniques, Inc. 2: 1 Objectives You will learn: Purpose and function of file commands. Interrelated usage of commands. SYS-ED/Computer Education Techniques,

More information

CST8207: GNU/Linux Operating Systems I Lab Ten Boot Process and GRUB. Boot Process and GRUB

CST8207: GNU/Linux Operating Systems I Lab Ten Boot Process and GRUB. Boot Process and GRUB Student Name: Lab Section: Boot Process and GRUB 1 Due Date - Upload to Blackboard by 8:30am Monday April 16, 2012 Submit the completed lab to Blackboard following the Rules for submitting Online Labs

More information

Introduction to UNIX. Logging in. Basic System Architecture 10/7/10. most systems have graphical login on Linux machines

Introduction to UNIX. Logging in. Basic System Architecture 10/7/10. most systems have graphical login on Linux machines Introduction to UNIX Logging in Basic system architecture Getting help Intro to shell (tcsh) Basic UNIX File Maintenance Intro to emacs I/O Redirection Shell scripts Logging in most systems have graphical

More information

The UNIX File System

The UNIX File System The UNIX File System Magnus Johansson May 9, 2007 1 UNIX file system A file system is created with mkfs. It defines a number of parameters for the system, such as: bootblock - contains a primary boot program

More information

Welcome to Linux. Lecture 1.1

Welcome to Linux. Lecture 1.1 Welcome to Linux Lecture 1.1 Some history 1969 - the Unix operating system by Ken Thompson and Dennis Ritchie Unix became widely adopted by academics and businesses 1977 - the Berkeley Software Distribution

More information

acmteam/unix.pdf How to manage your account (user ID, password, shell); How to compile C, C++, and Java programs;

acmteam/unix.pdf How to manage your account (user ID, password, shell); How to compile C, C++, and Java programs; Note: you can find this file under: http://www.cs.queensu.ca/ acmteam/unix.pdf Introduction to Unix Tutorial In this tutorial, you will learn: How to manage your account (user ID, password, shell); Navigating

More information

: the User (owner) for this file (your cruzid, when you do it) Position: directory flag. read Group.

: the User (owner) for this file (your cruzid, when you do it) Position: directory flag. read Group. CMPS 12L Introduction to Programming Lab Assignment 2 We have three goals in this assignment: to learn about file permissions in Unix, to get a basic introduction to the Andrew File System and it s directory

More information

Bioinformatics? Reads, assembly, annotation, comparative genomics and a bit of phylogeny.

Bioinformatics? Reads, assembly, annotation, comparative genomics and a bit of phylogeny. Bioinformatics? Reads, assembly, annotation, comparative genomics and a bit of phylogeny stefano.gaiarsa@unimi.it Linux and the command line PART 1 Survival kit for the bash environment Purpose of the

More information

Introduction to Unix CHAPTER 6. File Systems. Permissions

Introduction to Unix CHAPTER 6. File Systems. Permissions CHAPTER 6 Introduction to Unix The Unix operating system is an incredibly powerful and complex system that is ideal for running a distributed system such as ours, particularly since we use computers primarily

More information

Using LINUX a BCMB/CHEM 8190 Tutorial Updated (1/17/12)

Using LINUX a BCMB/CHEM 8190 Tutorial Updated (1/17/12) Using LINUX a BCMB/CHEM 8190 Tutorial Updated (1/17/12) Objective: Learn some basic aspects of the UNIX operating system and how to use it. What is UNIX? UNIX is the operating system used by most computers

More information

CSC209. Software Tools and Systems Programming. https://mcs.utm.utoronto.ca/~209

CSC209. Software Tools and Systems Programming. https://mcs.utm.utoronto.ca/~209 CSC209 Software Tools and Systems Programming https://mcs.utm.utoronto.ca/~209 What is this Course About? Software Tools Using them Building them Systems Programming Quirks of C The file system System

More information

Lab #2 Physics 91SI Spring 2013

Lab #2 Physics 91SI Spring 2013 Lab #2 Physics 91SI Spring 2013 Objective: Some more experience with advanced UNIX concepts, such as redirecting and piping. You will also explore the usefulness of Mercurial version control and how to

More information

Unix Filesystem. January 26 th, 2004 Class Meeting 2

Unix Filesystem. January 26 th, 2004 Class Meeting 2 Unix Filesystem January 26 th, 2004 Class Meeting 2 * Notes adapted by Christian Allgood from previous work by other members of the CS faculty at Virginia Tech Unix Filesystem! The filesystem is your interface

More information

Unix File System. Class Meeting 2. * Notes adapted by Joy Mukherjee from previous work by other members of the CS faculty at Virginia Tech

Unix File System. Class Meeting 2. * Notes adapted by Joy Mukherjee from previous work by other members of the CS faculty at Virginia Tech Unix File System Class Meeting 2 * Notes adapted by Joy Mukherjee from previous work by other members of the CS faculty at Virginia Tech Unix File System The file system is your interface to: physical

More information

UNIX File Hierarchy: Structure and Commands

UNIX File Hierarchy: Structure and Commands UNIX File Hierarchy: Structure and Commands The UNIX operating system organizes files into a tree structure with a root named by the character /. An example of the directory tree is shown below. / bin

More information

Useful Unix Commands Cheat Sheet

Useful Unix Commands Cheat Sheet Useful Unix Commands Cheat Sheet The Chinese University of Hong Kong SIGSC Training (Fall 2016) FILE AND DIRECTORY pwd Return path to current directory. ls List directories and files here. ls dir List

More information

Basic UNIX Commands BASIC UNIX COMMANDS. 1. cat command. This command is used to create a file in unix. Syntax: $ cat filename

Basic UNIX Commands BASIC UNIX COMMANDS. 1. cat command. This command is used to create a file in unix. Syntax: $ cat filename Basic UNIX Commands BASIC UNIX COMMANDS 1. cat command This command is used to create a file in unix. $ cat >filename This command is also used for displaying contents in a file. $ cat filename 2. ls command

More information

Permissions and Links

Permissions and Links Permissions and Links The root account Setuid and Setgid Permissions Setting Setuid and Setgid with chmod Directory Access Permissions Links o Two Types of Links o The ln command o Removing a link The

More information

Basics. I think that the later is better.

Basics.  I think that the later is better. Basics Before we take up shell scripting, let s review some of the basic features and syntax of the shell, specifically the major shells in the sh lineage. Command Editing If you like vi, put your shell

More information

Unix Guide. Meher Krishna Patel. Created on : Octorber, 2017 Last updated : December, More documents are freely available at PythonDSP

Unix Guide. Meher Krishna Patel. Created on : Octorber, 2017 Last updated : December, More documents are freely available at PythonDSP Unix Guide Meher Krishna Patel Created on : Octorber, 2017 Last updated : December, 2017 More documents are freely available at PythonDSP Table of contents Table of contents i 1 Unix commands 1 1.1 Unix

More information

Introduction p. 1 Who Should Read This Book? p. 1 What You Need to Know Before Reading This Book p. 2 How This Book Is Organized p.

Introduction p. 1 Who Should Read This Book? p. 1 What You Need to Know Before Reading This Book p. 2 How This Book Is Organized p. Introduction p. 1 Who Should Read This Book? p. 1 What You Need to Know Before Reading This Book p. 2 How This Book Is Organized p. 2 Conventions Used in This Book p. 2 Introduction to UNIX p. 5 An Overview

More information

Introduction to UNIX command-line II

Introduction to UNIX command-line II Introduction to UNIX command-line II Boyce Thompson Institute 2017 Prashant Hosmani Class Content Terminal file system navigation Wildcards, shortcuts and special characters File permissions Compression

More information

Exploring UNIX: Session 3

Exploring UNIX: Session 3 Exploring UNIX: Session 3 UNIX file system permissions UNIX is a multi user operating system. This means several users can be logged in simultaneously. For obvious reasons UNIX makes sure users cannot

More information

Introduction to UNIX Command Line

Introduction to UNIX Command Line Introduction to UNIX Command Line Files and directories Some useful commands (echo, cat, grep, find, diff, tar) Redirection Pipes Variables Background processes Remote connections (e.g. ssh, curl) Scripts

More information

Introduction To Linux. Rob Thomas - ACRC

Introduction To Linux. Rob Thomas - ACRC Introduction To Linux Rob Thomas - ACRC What Is Linux A free Operating System based on UNIX (TM) An operating system originating at Bell Labs. circa 1969 in the USA More of this later... Why Linux? Free

More information

CS Fundamentals of Programming II Fall Very Basic UNIX

CS Fundamentals of Programming II Fall Very Basic UNIX CS 215 - Fundamentals of Programming II Fall 2012 - Very Basic UNIX This handout very briefly describes how to use Unix and how to use the Linux server and client machines in the CS (Project) Lab (KC-265)

More information

6.033 Computer System Engineering

6.033 Computer System Engineering MIT OpenCourseWare http://ocw.mit.edu 6.033 Computer System Engineering Spring 2009 For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms. M.I.T. DEPARTMENT

More information

Open up a terminal, make sure you are in your home directory, and run the command.

Open up a terminal, make sure you are in your home directory, and run the command. More Linux Commands 0.1 wc The Linux command for acquiring size statistics on a file is wc. This command can provide information from line count, to bytes in a file. Open up a terminal, make sure you are

More information

This lab exercise is to be submitted at the end of the lab session! passwd [That is the command to change your current password to a new one]

This lab exercise is to be submitted at the end of the lab session! passwd [That is the command to change your current password to a new one] Data and Computer Security (CMPD414) Lab II Topics: secure login, moving into HOME-directory, navigation on Unix, basic commands for vi, Message Digest This lab exercise is to be submitted at the end of

More information