File management: copy, move, remove and search files

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
€64.94
List Price:  €92.78
You save:  €27.83
£55.57
List Price:  £79.40
You save:  £23.82
CA$95.27
List Price:  CA$136.11
You save:  CA$40.83
A$107.88
List Price:  A$154.13
You save:  A$46.24
S$94.55
List Price:  S$135.08
You save:  S$40.52
HK$547.57
List Price:  HK$782.28
You save:  HK$234.71
CHF 63.42
List Price:  CHF 90.61
You save:  CHF 27.18
NOK kr759.63
List Price:  NOK kr1,085.23
You save:  NOK kr325.60
DKK kr484.38
List Price:  DKK kr692.01
You save:  DKK kr207.62
NZ$117.46
List Price:  NZ$167.80
You save:  NZ$50.34
د.إ257.02
List Price:  د.إ367.19
You save:  د.إ110.16
৳7,682.93
List Price:  ৳10,976.08
You save:  ৳3,293.15
₹5,837.41
List Price:  ₹8,339.52
You save:  ₹2,502.10
RM331.26
List Price:  RM473.25
You save:  RM141.99
₦99,285.71
List Price:  ₦141,842.81
You save:  ₦42,557.10
₨19,466.20
List Price:  ₨27,810.04
You save:  ₨8,343.84
฿2,553.28
List Price:  ฿3,647.70
You save:  ฿1,094.41
₺2,262.39
List Price:  ₺3,232.12
You save:  ₺969.73
B$349.43
List Price:  B$499.21
You save:  B$149.77
R1,335.92
List Price:  R1,908.54
You save:  R572.62
Лв126.45
List Price:  Лв180.65
You save:  Лв54.20
₩94,634.34
List Price:  ₩135,197.71
You save:  ₩40,563.37
₪258.03
List Price:  ₪368.63
You save:  ₪110.60
₱3,943.57
List Price:  ₱5,633.91
You save:  ₱1,690.34
¥10,600.67
List Price:  ¥15,144.47
You save:  ¥4,543.79
MX$1,161.53
List Price:  MX$1,659.40
You save:  MX$497.87
QR255
List Price:  QR364.31
You save:  QR109.30
P959.59
List Price:  P1,370.91
You save:  P411.31
KSh9,203.68
List Price:  KSh13,148.68
You save:  KSh3,945
E£3,310.52
List Price:  E£4,729.52
You save:  E£1,419
ብር3,976.27
List Price:  ብር5,680.63
You save:  ብር1,704.36
Kz58,526.41
List Price:  Kz83,612.74
You save:  Kz25,086.33
CLP$68,581.80
List Price:  CLP$97,978.20
You save:  CLP$29,396.40
CN¥506.04
List Price:  CN¥722.95
You save:  CN¥216.90
RD$4,144.87
List Price:  RD$5,921.50
You save:  RD$1,776.62
DA9,443.17
List Price:  DA13,490.83
You save:  DA4,047.65
FJ$158.28
List Price:  FJ$226.12
You save:  FJ$67.84
Q545.87
List Price:  Q779.86
You save:  Q233.98
GY$14,645.83
List Price:  GY$20,923.51
You save:  GY$6,277.68
ISK kr9,762.20
List Price:  ISK kr13,946.60
You save:  ISK kr4,184.40
DH709.20
List Price:  DH1,013.19
You save:  DH303.99
L1,234.28
List Price:  L1,763.34
You save:  L529.05
ден3,991.30
List Price:  ден5,702.11
You save:  ден1,710.80
MOP$564.10
List Price:  MOP$805.89
You save:  MOP$241.79
N$1,325.35
List Price:  N$1,893.44
You save:  N$568.09
C$2,576.69
List Price:  C$3,681.15
You save:  C$1,104.45
रु9,334.54
List Price:  रु13,335.63
You save:  रु4,001.09
S/259.58
List Price:  S/370.84
You save:  S/111.26
K267.89
List Price:  K382.72
You save:  K114.82
SAR262.49
List Price:  SAR375
You save:  SAR112.51
ZK1,765.85
List Price:  ZK2,522.76
You save:  ZK756.90
L322.98
List Price:  L461.43
You save:  L138.44
Kč1,645.46
List Price:  Kč2,350.75
You save:  Kč705.29
Ft25,709.21
List Price:  Ft36,729.02
You save:  Ft11,019.81
SEK kr749.87
List Price:  SEK kr1,071.30
You save:  SEK kr321.42
ARS$60,034.20
List Price:  ARS$85,766.82
You save:  ARS$25,732.62
Bs483.70
List Price:  Bs691.04
You save:  Bs207.33
COP$271,296.95
List Price:  COP$387,583.68
You save:  COP$116,286.73
₡35,581.11
List Price:  ₡50,832.34
You save:  ₡15,251.22
L1,728.07
List Price:  L2,468.78
You save:  L740.71
₲516,441.87
List Price:  ₲737,805.73
You save:  ₲221,363.85
$U2,647.22
List Price:  $U3,781.90
You save:  $U1,134.68
zł280.50
List Price:  zł400.73
You save:  zł120.23
Already have an account? Log In

Transcript

After we looked at how to view and edit files, let's now look at how to make copies of files and move them around in the file system. I will change to my work directory. If I want to make a copy of a file, I can do it using the CP command specifying the source file and target file. I will now copy my run.sh script and name it run sudo sh and I will list the content and you can see there are two files. I can also copy a file to another directory. I'll create a subdirectory called sub one using MK dir command and I will copy my render to Sage inside it.

Let's leave the content of sub one now. I can also copy multiple files using wildcard notation with tar I will now copy all shell scripts starting with run to subdirectory sub one. Now I can see in the subdirectory that two files I can Well move files in the same manner. I will now move the second version of the run script and move it to the subdirectory and name it run Fredo to sage. And I forgot the.sh extension. This way I moved and renamed the file at the same time.

I can as well copy directories in a similar manner by adding an additional argument minus r for recursive. I will now copy the directories of one, two sub two with all its content. I can as well rename directories in the same manner, sub two sub three and I can remove the file with the rm command. I would remove directories with RM dir command, but if I executed on a non empty directory, I will get an error. It only works on empty directories. However, if I do want to completely remove the directory, I could use the rm command to the recursive argument minus R. In our deleted the complete sub three directory, if at least the content of the current directory I don't see it anymore.

Now be extremely cautious with the rm command, especially with the recursive argument, you might unintentionally get rid of files that you actually need. My personal advice is every time you execute the rm command, count until five before pressing Enter. This will help you avoid unpleasant surprises that may even break your system. So be careful. Let me create two more copies of random sh script. I will create a copy and name it run version one.sh and run version two.sh.

Now modify the second file that we have actually two different files will use nano editor that we learned in the previous lectures. We'll remove the last three lines from file and save it and close it will now create a special type of file called symbolic link that would link to the original file. I can do it using the ln command. l specify lm minus as symbolic link. The source front view one in the name of the link would be run dash link.sh. I can see that the file now links to the v1 version of the script.

And you can see this notation with the arrow sign. Now I can work with the file in a similar manner as I would work with the original file. I can now execute it and it will print me what I expect to see from the V one script. I would now like to reuse the link and link into the Vive to have the script I can simply remove the link first. And then run the commands again. I will do the same for version two of my script and name the link again run dash link.sh.

Now if I execute it again, it will execute the second version of the script, which prints the data only once. I could have achieved the same by forcing to recreate the link by adding the minus f argument ln minus F, run the tune. Run dash link I forgot to add the SH extension there's no problem. Currently I would have two links. Let me demonstrate it again. Now I want to link it back to the V one of the script.

And now the link changed. I could also remove the redundant link What do we just did for this symbolic links is widely used in Linux for package upgrades of the libraries. We can see for example, the library file stores in the slash user slash lib directory called lib GIMP to the zero star. Current on this one, as you can see, there are two files, one with extension to the old soul zero, which is the link to the original file that has the specific minor version specified 08 hundred 22. This way applications that depend on the lib gameplay library would be using the length version and I can update this library with the minor versions without breaking their dependent applications. This way you can ensure smooth minor updates of the dependent libraries without breaking other applications.

If I would like to remove the link, I can do it and you can see the original file did not change it's still in place. I can work with the same operations from the directory so I can create a symbolic link on the sub one directory and call it sub one dash link. And in the same way, I can see the content and I can also safely remove the link my original will be still preserved. As always, we can check what arguments I available for the CP or other commands by appending minus minus help arguments. This way you can see the arguments that are available for the CP command for very flexible operation files. The same argument minus minus help also works for remove and move commands and the rest.

Alternatively, we can also have a special command for printing the manual pages called man. Don't try to open it on the ln command. It will open the viewer is similar to the last command we use before and we can navigate it easily the same way. Now at this time, feel free to pause the video and take your time to practice copy and move your files between directories. Also, make sure to have a look at the argument these commands have. This way you will know what these commands can do and one day you will use it and be extra careful with the rm command.

Now that they created a bunch of directories and files, I might need to search for some specific files in the file structure. I can do it using the find command. It is a very powerful command with options for a variety of cases. Let's start with the simplest version. I will type find current directory argument minus name and the pattern for the files I'm looking for. It will be as tired or a sage.

I'm interested now in all shell scripts in my current role Now I can modify the find command and search only in the subdirectory sub one. And now it printed me shell scripts in the sub one sub directory. I can also use find command to find directories in the hierarchy starting with the current directory. I can do it with specifying the type argument with the D parameter where D denotes directories. As you remember directories are also files with special treatment. And with the minus type argument, I tell the find command that I'm only interested in finding directories.

I can also search for Files of Type L, which has symbolic links. Well, we removed all the links from the current directory so let's quickly create one. Now running the find command for the title l which has symbolic links will now print our desired result. Now let me show you one more argument for the find command called exec. I would now like to print the contents of a directory that is found by the find command with the type D. I'll type find current directory minus type D, I will add the minus exact argument. And the parameters for this argument would be LS minus L. And the curly brackets which would mean that for every output of the find command, I want to execute my LS minus l command.

Essentially, the curly brackets here are the placeholder for every line on the Find result. Now I have to use a special notation to finish the parameters for my exact argument. This is specified with the semicolon and since I want the semicolon to be understood by the ls command and not by the full line with a find, I have to use the escape character backslash executing this question We'll print the contents of two directories that we just searched for before. It prints the content of the current directory first. And then it prints the content of the sub one subdirectory. Exact argument for the find command can also be prepended with many other varieties of printing the file content, or listing the directory content, or maybe in the piping operation that we'll cover later.

This is quite a powerful concept that you might find in your day to day work as well. And in general, let's have a look at the main page for the find command. And here I'm specifically interested in the example section that I will now be looking for. In here, the man page specifies quite a few example cases for the find command. Again, make sure to look at the documentation pages or searching the internet for most common usages for the final command. There are really a lot of things you can do with the fine command.

And also there are tons of examples in the internet. Let me go search for the files in slash Etsy D directory by executing find command with a different path argument, find slash etc. Minus name all.com files. Now the interesting part is that the output of this command doesn't really fit into one screen. How need to scroll the terminal window up and down when if I want to go back, however, there is a better alternative for processing the long output of commands like find. This concept is known as pagination, output redirect and piping, which we'll cover just in the next lecture.

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.