Navigation, changing file permissions and executing scripts: cd, chmod

11 minutes
Share the link to this page
Copied
  Completed
You need to have access to the item to view this lesson.
One-time Fee
$69.99
List Price:  $99.99
You save:  $30
€65.14
List Price:  €93.07
You save:  €27.92
£55.73
List Price:  £79.62
You save:  £23.88
CA$95.61
List Price:  CA$136.60
You save:  CA$40.98
A$106.30
List Price:  A$151.87
You save:  A$45.56
S$94.64
List Price:  S$135.20
You save:  S$40.56
HK$546.91
List Price:  HK$781.33
You save:  HK$234.42
CHF 63.50
List Price:  CHF 90.72
You save:  CHF 27.21
NOK kr764.69
List Price:  NOK kr1,092.46
You save:  NOK kr327.77
DKK kr485.92
List Price:  DKK kr694.20
You save:  DKK kr208.28
NZ$117
List Price:  NZ$167.15
You save:  NZ$50.15
د.إ257.06
List Price:  د.إ367.25
You save:  د.إ110.18
৳7,661.98
List Price:  ৳10,946.16
You save:  ৳3,284.17
₹5,839.65
List Price:  ₹8,342.71
You save:  ₹2,503.06
RM331.75
List Price:  RM473.95
You save:  RM142.20
₦86,437.65
List Price:  ₦123,487.65
You save:  ₦37,050
₨19,492.21
List Price:  ₨27,847.21
You save:  ₨8,355
฿2,575.56
List Price:  ฿3,679.53
You save:  ฿1,103.97
₺2,262.43
List Price:  ₺3,232.18
You save:  ₺969.75
B$357.76
List Price:  B$511.10
You save:  B$153.34
R1,296.01
List Price:  R1,851.52
You save:  R555.51
Лв127.38
List Price:  Лв181.98
You save:  Лв54.60
₩95,113.23
List Price:  ₩135,881.87
You save:  ₩40,768.63
₪260.11
List Price:  ₪371.60
You save:  ₪111.49
₱3,999.61
List Price:  ₱5,713.97
You save:  ₱1,714.36
¥10,715.43
List Price:  ¥15,308.41
You save:  ¥4,592.98
MX$1,185.45
List Price:  MX$1,693.57
You save:  MX$508.12
QR254.79
List Price:  QR364.01
You save:  QR109.21
P955.69
List Price:  P1,365.33
You save:  P409.64
KSh9,427.65
List Price:  KSh13,468.65
You save:  KSh4,041
E£3,355.67
List Price:  E£4,794.02
You save:  E£1,438.35
ብር3,989.43
List Price:  ብር5,699.43
You save:  ብር1,710
Kz58,616.62
List Price:  Kz83,741.62
You save:  Kz25,125
CLP$66,326.02
List Price:  CLP$94,755.52
You save:  CLP$28,429.50
CN¥506.51
List Price:  CN¥723.62
You save:  CN¥217.11
RD$4,049.59
List Price:  RD$5,785.38
You save:  RD$1,735.78
DA9,420.19
List Price:  DA13,457.99
You save:  DA4,037.80
FJ$157.70
List Price:  FJ$225.30
You save:  FJ$67.59
Q542.62
List Price:  Q775.21
You save:  Q232.58
GY$14,613.08
List Price:  GY$20,876.73
You save:  GY$6,263.64
ISK kr9,792.30
List Price:  ISK kr13,989.60
You save:  ISK kr4,197.30
DH706.05
List Price:  DH1,008.69
You save:  DH302.63
L1,239.86
List Price:  L1,771.31
You save:  L531.44
ден4,010.92
List Price:  ден5,730.13
You save:  ден1,719.21
MOP$562.15
List Price:  MOP$803.11
You save:  MOP$240.95
N$1,302.54
List Price:  N$1,860.85
You save:  N$558.31
C$2,571.43
List Price:  C$3,673.63
You save:  C$1,102.20
रु9,317.58
List Price:  रु13,311.40
You save:  रु3,993.82
S/262.81
List Price:  S/375.46
You save:  S/112.65
K268.53
List Price:  K383.63
You save:  K115.10
SAR262.51
List Price:  SAR375.03
You save:  SAR112.52
ZK1,879.71
List Price:  ZK2,685.42
You save:  ZK805.70
L324.19
List Price:  L463.14
You save:  L138.95
Kč1,629.65
List Price:  Kč2,328.17
You save:  Kč698.52
Ft25,373.17
List Price:  Ft36,248.95
You save:  Ft10,875.77
SEK kr758.75
List Price:  SEK kr1,083.98
You save:  SEK kr325.22
ARS$61,468.94
List Price:  ARS$87,816.53
You save:  ARS$26,347.59
Bs482.36
List Price:  Bs689.12
You save:  Bs206.75
COP$272,946.91
List Price:  COP$389,940.87
You save:  COP$116,993.96
₡35,623.88
List Price:  ₡50,893.45
You save:  ₡15,269.56
L1,732.95
List Price:  L2,475.75
You save:  L742.80
₲523,151.84
List Price:  ₲747,391.81
You save:  ₲224,239.96
$U2,683.09
List Price:  $U3,833.15
You save:  $U1,150.06
zł281.85
List Price:  zł402.67
You save:  zł120.81
Already have an account? Log In

Transcript

In this lecture we'll create our first transcript. But before let's get familiarized ourselves first navigation in the file system. In the moment we're located in our home directory which we can see by executing pwd. The path consists of several paths. The first slash denotes the so called root directory, the highest level path on the file system. Then comes sub paths slash home slash my username.

We can change our directory to root directory by executing CD slash and see where we are pwd. We can go back to our home directory by executing CD without arguments. We could also change the home directory using special notation for the cd space Tilda and this will have the same effect as CD with no arguments. Let's not create a new directory here. Let's call it the work Know that names in Linux are case sensitive, and so word capitalized and work with small letters would be different directories. So this succeeded in if I tried to create it again this will fail Of course, because it exists and now we can remove the redundant directory by executing remove directory command RM dir work and on the RM dir command only works on empty directories and in our case it was empty so it succeeded.

Let's go inside work CD work and see the current location in the file system pwd again. You can also see that my prompt which is the first part of every line in the terminal is changing to reflect my current location. How prompt looks very much depends on your local configuration. In my case that I'm using Linux Mint. It contains the user name Add my machine name, which I call local, and then followed by the current path. This will most probably look different for you if you use a different distribution type, but you can change it to your liking.

In our current directory, we'll create a new shell script called run.sh. Using editor called nano, will type nano run.sh to create our first script, but we'll cover nano in the next section more details, most probably it is already available for your distribution. If not, we will need it for the next lectures. So it is a good time to install it using your package manager. I will execute the command now and it opens me the editor view. We will start with the shebang sequence which is a hash followed by exclamation mark.

This will tell the interpreter that full read my program that I'm going to use the executable slash bins Shell the application that will run my script. slash bin slash sh is the file in slash bin directory. That is a symbolic link to my corresponding shell application that I use. Let's finish our script and I will show you what I mean by the symbolic link. In general, the shebang sequence has a few more usages, which you may encounter in other scripts, feel free to search for its usages underneath an ad. For this script, we will add one command to print a string.

We will use the command echo with the argument Hello World Of course. We'll put the argument to the echo command in quotation marks. But strictly speaking in this example, we could skip that also. script in Linux helped automate routine work. He would use them if you plan to execute a set of commands on a regular basis. Putting these commands in a script will save you a lot of time.

An example usage for shell scripts and its configuration script that is run before compiling the source code of an application. The script will check that all dependencies are in place for your computer without the need to run these kinds of commands manually. Or maybe you want to rename a bunch of files. doing it manually for each file might be a very cumbersome job. But with a script, you will be able to iterate over each file easily. We can now save the file and pressing CTRL o to save enter to confirm and Ctrl X to quit.

Let's have a quick look at the shell executable that we put in the first line of our script. It is a symbolic link to bash shell executable that I'm using by default it is shown by the arrow sign symbolic links help to manipulate filenames without changing the original files. It is very useful when you will be Dealing with versions of libraries, or in the case like hours, when you might have several shell executables installed, and you want to switch between them. In my case, the file links to bash executable. And if you use a different type of shell like TC shells, that shell or something else, it will probably lead to that shell executable. Let's now try to execute our script.

It is now in our current directory. We see the file exists. And we can run the script by executing dot slash and the name of our script. But oops, it failed. The reason is that by default, newly created files only have permissions on reading and writing. They do not have executable permissions, something that we need to run shell scripts.

We can easily fix that by using the change mode ch mod command ch mod plus x run.sh. This will add the executable permission to our script and now we can run that And this time it succeeded and prints the hello world. As you may notice, CH mod command has a different set of arguments compared to the ls command that we discussed in the previous lecture. The first argument plus x specifies the changes in permissions for the file. And the last argument is the filename for which we want to change permissions. We want to add executable permissions, which is denoted by a plus sign, followed by the permissions x in our case, we could also remove this permission by typing ch mod minus x run.sh.

And this will now remove the executable permissions. Now let's make the file executable only for the owner of the file, which is you. We can do it by typing ch mod user plus x run.sh. Where are you in front of the plus sign says permissions for the user of the file. Other options include setting permission For group G, and others, oh, such as I could do ch mod, user group other plus x executable Rondo this age. Now let's have a look at our permissions.

And now it has executable for all type of users. We can remove the executable permission for only group and other ch mod G or minus x run.sh. let's print it again. And the permissions changed. And you might add or remove, read and write permissions in the same manner. Ch mod.

Other group minus right rando this age. It might be a bit confusing in the beginning that you didn't notice the owner of the file and older and older other users. Remember this difference? That's fun. That was cryptic. NCO hello world.

Now that we typed similar commands several times, let's have a look at useful tips on using the terminal. First thing is called top outer completion. When you start typing a command such as ch mod, or executing a script such as run.sh, you can type a few first characters and press tab and this will complete my line. Let's try this on change mode command. I start typing ch m, press the tab and nothing happens. The reason for this is that there are multiple commands starting with the CH m sequence.

If I press the Tab once again, it will show me the list of available commands starting with the sequence. If you use another shell such as that shell may behave slightly different. You could search in the internet for top outcompete. For your shell, and get familiar with how it works for you. Another useful feature is the history of command to run. So far, we typed a bunch of commands already and they all saved in the internal history, we can run the command that you executed just a few minutes ago without typing all the arguments.

Again, by navigating into history. We can press up or down to navigate in the history. I can go down and going down the history. We can also search in the history by pressing Ctrl r combination and start typing the text that we want to search for. This will find my text and the latest command that I typed in. If I press Ctrl r again, I will go back to the next occur to the previous occurrence of the text.

We could also scroll the terminal window up and down either by using the mouse Or I can use the key combination shift page up and page down. Now we can also copy paste a string, I can double click on some command that I used before. Ch modern our case and press the middle button to paste. Alternatively, I can of course select the selection with the mouse and use the same middle click to paste. If I triple click on some space in the terminal, it will select the whole line. It isn't really useful in the terminal usage, but it might be useful elsewhere.

In the current line where I'm typing in my commands, I can go to the beginning of my line by pressing Ctrl A. And I can go to the end of the line by pressing Ctrl E combination. I can go one word left with Ctrl left and I can go one word right pricing control right. You could also find many more useful shortcuts in the attached cheat sheet, make sure to check it out. In this section you learn how to create directories navigating the file system using cd command, how to create an edit file in changes permissions. You also learn how to use the terminal window to execute scripts use top auto completion and keyboard shortcuts.

In the next lecture, we will look at most common file viewers and editors that can be used from the terminal

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.