Database Reference
In-Depth Information
Step 2: Add Permission to Execute
The reason we cannot execute our file directly is that we do not have the correct
access permissions. In particular, you, as a user, need to have the permission to exe‐
cute the file. In this section, we'll change the access permissions of our file.
In order to show the differences between steps, we copy the file to
top-words-2.sh using cp top-words-{1,2}.sh . You can keep work‐
ing with the same file if you want to.
To change the access permissions of a file, we use a command-line tool called chmod
(MacKenzie & Meyering, 2012), which stands for change mode . It changes the file
mode bits of a specific file. The following command gives the user, you, the permis‐
sion to execute top-words-2.sh :
$ cd ~/book/ch04/
$ chmod u+x top-words-2.sh
The u+x option consists of three characters: (1) u indicates that we want to change the
permissions for the user who owns the file, which is you, because you created the file;
(2) + indicates that we want to add a permission; and (3) x , which indicates the per‐
missions to execute. Now let's have a look at the access permissions of both files:
$ ls -l top-words- { 1,2 } .sh
-rw-rw-r-- 1 vagrant vagrant 145 Jul 20 23:33 top-words-1.sh
-rwxrw-r-- 1 vagrant vagrant 143 Jul 20 23:34 top-words-2.sh
The first column shows the access permissions for each file. For top-words-2.sh , this is
-rwxrw-r-- . The first character, - , indicates the file type. A - means regular file and a
d (not present here) means directory. The next three characters, rwx , indicate the
access permissions for the user who owns the file. The r and w mean read and write,
respectively. (As you can see, top-words-1.sh has a - instead of an x , which means that
we cannot execute that file.) The next three characters, rw- , indicate the access per‐
missions for all members of the group that owns the file. Finally, the last three charac‐
ters in the column, r-- , indicate access permissions for all other users.
Now you can execute the file as follows:
$ ~/book/ch04/top-words-2.sh
6441 and
5082 the
3666 i
3258 a
3022 to
2567 it
2086 t
2044 was
Search WWH ::




Custom Search