Create and Manipulate Files

14 minutes
Share the link to this page
Copied
  Completed
You need to have access to the item to view this lesson.
One-time Fee
$49.99
List Price:  $69.99
You save:  $20
€46.38
List Price:  €64.94
You save:  €18.55
£39.69
List Price:  £55.57
You save:  £15.88
CA$68.04
List Price:  CA$95.27
You save:  CA$27.22
A$77.05
List Price:  A$107.88
You save:  A$30.82
S$67.53
List Price:  S$94.55
You save:  S$27.01
HK$391.10
List Price:  HK$547.57
You save:  HK$156.47
CHF 45.30
List Price:  CHF 63.42
You save:  CHF 18.12
NOK kr542.56
List Price:  NOK kr759.63
You save:  NOK kr217.06
DKK kr345.97
List Price:  DKK kr484.38
You save:  DKK kr138.41
NZ$83.89
List Price:  NZ$117.46
You save:  NZ$33.56
د.إ183.57
List Price:  د.إ257.02
You save:  د.إ73.44
৳5,487.49
List Price:  ৳7,682.93
You save:  ৳2,195.43
₹4,169.34
List Price:  ₹5,837.41
You save:  ₹1,668.07
RM236.60
List Price:  RM331.26
You save:  RM94.66
₦70,914.31
List Price:  ₦99,285.71
You save:  ₦28,371.40
₨13,903.63
List Price:  ₨19,466.20
You save:  ₨5,562.56
฿1,823.66
List Price:  ฿2,553.28
You save:  ฿729.61
₺1,615.90
List Price:  ₺2,262.39
You save:  ₺646.49
B$249.58
List Price:  B$349.43
You save:  B$99.85
R954.17
List Price:  R1,335.92
You save:  R381.74
Лв90.31
List Price:  Лв126.45
You save:  Лв36.13
₩67,592.09
List Price:  ₩94,634.34
You save:  ₩27,042.24
₪184.30
List Price:  ₪258.03
You save:  ₪73.73
₱2,816.67
List Price:  ₱3,943.57
You save:  ₱1,126.89
¥7,571.47
List Price:  ¥10,600.67
You save:  ¥3,029.19
MX$829.61
List Price:  MX$1,161.53
You save:  MX$331.91
QR182.13
List Price:  QR255
You save:  QR72.86
P685.38
List Price:  P959.59
You save:  P274.21
KSh6,573.68
List Price:  KSh9,203.68
You save:  KSh2,630
E£2,364.52
List Price:  E£3,310.52
You save:  E£946
ብር2,840.03
List Price:  ብር3,976.27
You save:  ብር1,136.24
Kz41,802.18
List Price:  Kz58,526.41
You save:  Kz16,724.22
CLP$48,984.20
List Price:  CLP$68,581.80
You save:  CLP$19,597.60
CN¥361.44
List Price:  CN¥506.04
You save:  CN¥144.60
RD$2,960.45
List Price:  RD$4,144.87
You save:  RD$1,184.41
DA6,744.74
List Price:  DA9,443.17
You save:  DA2,698.43
FJ$113.05
List Price:  FJ$158.28
You save:  FJ$45.23
Q389.89
List Price:  Q545.87
You save:  Q155.98
GY$10,460.71
List Price:  GY$14,645.83
You save:  GY$4,185.12
ISK kr6,972.60
List Price:  ISK kr9,762.20
You save:  ISK kr2,789.60
DH506.54
List Price:  DH709.20
You save:  DH202.66
L881.58
List Price:  L1,234.28
You save:  L352.70
ден2,850.77
List Price:  ден3,991.30
You save:  ден1,140.53
MOP$402.90
List Price:  MOP$564.10
You save:  MOP$161.19
N$946.63
List Price:  N$1,325.35
You save:  N$378.72
C$1,840.39
List Price:  C$2,576.69
You save:  C$736.30
रु6,667.15
List Price:  रु9,334.54
You save:  रु2,667.39
S/185.40
List Price:  S/259.58
You save:  S/74.17
K191.34
List Price:  K267.89
You save:  K76.55
SAR187.48
List Price:  SAR262.49
You save:  SAR75
ZK1,261.25
List Price:  ZK1,765.85
You save:  ZK504.60
L230.69
List Price:  L322.98
You save:  L92.29
Kč1,175.26
List Price:  Kč1,645.46
You save:  Kč470.19
Ft18,362.67
List Price:  Ft25,709.21
You save:  Ft7,346.54
SEK kr535.59
List Price:  SEK kr749.87
You save:  SEK kr214.28
ARS$42,879.12
List Price:  ARS$60,034.20
You save:  ARS$17,155.08
Bs345.48
List Price:  Bs483.70
You save:  Bs138.22
COP$193,772.46
List Price:  COP$271,296.95
You save:  COP$77,524.48
₡25,413.63
List Price:  ₡35,581.11
You save:  ₡10,167.48
L1,234.27
List Price:  L1,728.07
You save:  L493.80
₲368,865.97
List Price:  ₲516,441.87
You save:  ₲147,575.90
$U1,890.76
List Price:  $U2,647.22
You save:  $U756.45
zł200.34
List Price:  zł280.50
You save:  zł80.15
Already have an account? Log In

Transcript

In this video, we are going to take a look at creating and manipulating file commands. So the first command here is to create a file. So for that, we have to write d, u, c h. With this command, you can create a file. So I'm going to right touch then space, then demo dot txt. Now here you will have to specify the extension every single time because if you don't, and it won't have any extension, and it will just be created. So you will have to specify the type whether it is document, text, whatever, you will need to specify it here.

So let's enter and you can see that demo dot txt file is created. Now, what if you want to enter some data into this txt file through this terminal or without going out of this terminal. So you can do that using a simple command that is nano space demo dot txt. And this will open a gmu editor. So this is where you can write the content that you want into this. txt file.

So I'm going to write Hello, world. So I have written HelloWorld. And I'm going to save it so for that, what you have to do is here if you see in this downside then for exit, it is written that you have to press Ctrl and x this arrow sign. This represents control and access So we have to press Ctrl X to exit, then it is going to ask that we want to save the edited file, then you have to press Y for yes and, and for No. So I'm going to press Y. So now you have to again, verify the file name.

And if it is same, then press Enter. And that's it. You have edited that file. So let's check. So here is our file. And here is the Hello World text that we entered.

So this is how you can enter any data that you want into your file. So now, if I want to copy this file, then the command is same as directory that is CP. And if you want to remove the file, then that is RM same as for directories. And for moving the file, it is same MV. Okay, so now let's perform the cd command. So CP space, the file name, that is demo dot txt, and I am going to copy this into the ABC folder.

So let's change the directory to ABC. And here we have our demo dot txt file. So now let's go back. And what if I were to copy this into an another text file? So let's create a txt file. So I'm going to right touch demo two dot txt.

So I have the second txt file. So now I'm going to copy the contents of demo dot txt into this demo dot txt. So, demo. So I'm going to write CP demo dot txt space demo dot txt. And let's check. So no demo to the XP.

And we have hello world here. Now we created this demo file. Now even if we don't create this demo file, then it is going to be automatically created. So let me just show you that. So we'll remove the demo dot txt file. So it is removed.

Now, let's run this command again. And as you can see the demo dot txt file is generated automatically. So this is how the CP, the copy command works. Now. Now let's run the move command. So I'm going to move the demo dot txt file into the ABC folder.

So MV demo dot txt, AB, C. So let's change the directory. So here we have our demo dot txt. And as you can see here, it is not present here. So it is deleted. So, this is how you can use the Move command. Now you know the VMO copy and move command.

Now, there is another command that is C a t, that is concatenate. So what this command does is it combines the content of two files and displays them. So, let's go to the ABC folder. And we have two files here demo and demo two. So, cat space demo dot txt and space demo two dot txt and enter. So as you can see, it displayed the content of both these files.

So the first files of contents HelloWorld second, also contains This. So let's change the content of the second file nano demo. And I'm going to right here Aakash, exit. Yes, and go. And now let's run this command again. So as you can see here, it displayed both the files content.

So this is what the cat command does. Now, the next command is S e d. So, the cd command, standard stands for string editor. With this command, what we are going to do is we are going to replace a word with another word in a file. So we are going to first have to create a file. So we already have one file. Let's edit that file.

So, demo dot txt. Okay, so now let's change the content of this file. So now I'm going to keep the hello world as it is, and I'm going to write Hello. Aakash, then again. Hello Udemy then hi Udemy and let's exit, enter. So we have edited this demo dot txt file.

Now, I'm going to write the cd command, cd space, minus i space, single inverted comma, as an call, comma then Hello Then comma high m comma G. Again, closing the single inverted comma and space demo dot txt. Now what this command will do is it is going to search for this HelloWorld in this file and replace it with high word and it is going to do it globally. So, every HelloWorld in this file will be changed to high. So let's run it. And let's see if it is changed to Hi. As you can see here, that all the Hello World is changed to Hi.

So this is how you can change multiple words into a text file without even Opening that exe file using just a single line statement. Okay, so the next command is g r e v grip. So this command stands for global regular expression print. So with this command, we can search for a word in the text file and it is going to print out the whole line with that word. So GRP then we have to write the words that we want to search for. And then the name of the exe file that is demo dot txt.

So as you can see it printed every single line with the word Hi. So now let's change it to world. So I just printed this line Now, let's change it to Udemy. So, as you can see it printed both these lines as the Udemy word contains in both of these lines. So it will just print out the whole line with that word and it is case sensitive. So, the capital letter and small letter are both different things.

Okay, so now the next command is less m more. So, less command is used when you want to output the content. And you can also scroll through that content within this terminal and more will display the contents of file, page by page. So, let's see the last command first. So far that I have already created a file named file dot txt, so it contains this content. So now let's use less file dot txt.

So it displays the content like this. Now, this is the end of the file. If it would not have been this end, then you can scroll through the content of the file. So now let's exit. Now, let's run the more command more than the file dot txt. So it is going to display the content like this.

Now the next command is head. So this command will display the first 10 lines Out there in the file. So these are the first 10 lines, and then there is tail. And this is going to display the last 10 lines. So these are the last 10 lines of this text file. Now the next command is sought before that let's append the content of the file dot txt.

So, cat file dot txt and this is the content of this file. Now, let's run start then file dot txt and as you can see, the data that was there in this file is sorted. So first of all there is 10 than hundred. So it consider this as one. So this is also considering it as 1-212-345-6789 then we have a then b, h, k, v and w. So it is sorted in ascending order. Now, if we go into the editor so as you can see here that the file is not really sorted here.

So what this command does is it just displays the data in sorted form. It doesn't write this into the file. This is just for displaying purpose, same as the cat function that displays the two files content. So these were all the commands for the final manipulation.

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.