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.