Okay. Welcome to module window 3.3. We're gonna look at file management tools.
So we explored a little bit of of this already when we were talking about the shell on some of the other units commands and Lenox new commands.
But we need to go a little further and
learn more about how to manipulate files and directories and so on.
So we're gonna cover how to remove files, how to create them,
how to do compression of files howto find them on to make directories
how to rename files.
So a lot of options here to to discover,
starting off with copying files and moving files.
Now, when I run the copy Command CP,
copy of file and maintain its original name, which is the default behavior,
or I can actually rename it
in that process.
Similarly, with the move command,
when I move a file, I can move it as is,
or rename it during the move.
Now, move is different than copy because copied leaves the original in place. Where has moved, takes the original and puts it somewhere else.
And I can also remove my files
now removing a directory has a couple of,
Gotsch is right. So if I were tried remover directory and it's not empty, I will get an error message. So I have to get around that by using other techniques
that that would involve using recursive
copying or removal.
And you specify Rikers in by using the capital are
so being able to, um, I could also used for removal anyway. I can use our em dash R F,
which, as I mentioned earlier, is removal that's forced and that will get rid of a directory. And it's subdirectories.
There are endure the removed directory option. Dash P
will remove the parents of a current directory
so we can demonstrate this with a couple of different examples
to clear my screen.
It's always good to start with a clear window,
so I should be in my
And first I'm going to start with making a directory structure so I can demonstrate some of these concepts. So I'm gonna run the Make Dirt Command,
and I'm gonna give it a option of Dash Pete. This tells it
make parent directories as needed.
So I just made three directories.
Dir one contains dirt to and do dirt to contains door three.
So if I run the tree command under one, I can see what that structure looks like.
what also going to do is create a file on each directory.
So I'll go to Dirt one, and I'll just create 51
I'm using the redirect operator, since I'm not
sending any data, but this is reading from standard input.
It just creates a file with
size zero discredited empty file. It's very convenient for lots of different things.
So create file, too, and directory to.
And then I'll go to Director three and create 53
All right now, I'm back to Mani Home Directory, and I could see the shell has
Directory and blue, which is handy. It's nice feature of Bash,
all right, so if I want to, um,
copy some files,
let's let's go ahead and do that. I can copy
slash file one
to my current directory. So that's why I use a dot
I could copy to the parents of this director by using dot dot That's another feature of the shell,
but the current director is specified by a dot because of the way that the shell handles the pointers to your current director and the parent of the director that you're ready so we can reference those by using dot and dot dot I'll talk about that little bit more later, but
it's nice to see a little bit of detail as we go along here anyway,
So copying directory ones file one to the current folder.
Now, when I copied here,
if I wanna run Desh l s Dash l rt This shows me the most recent file at the bottom The listing.
So there's file one of just copied it
It's still there, just a copy
and I can verify that by typing Elder one. Now
I can copy I'ma hit up arrow
instead of calling it our sort of copping as is gonna call it file one copy
Now what I've done is I've copied the file from directory one too.
My current folder
specified by dot slash
But I've also
renamed it in the process and now I've got filed one dash copy
of Pretty convenient.
Now let's look at the move command.
So I'm gonna move door one dirt too
to my current folder
now They're already exists there. So because I did this operation earlier,
I can say yes. I do want to overwrite
pain. And Ellis allergy
there is filed two.
Now, Since I did a move, I didn't update the, uh, the access time.
So it's still from just a few minutes ago.
And what I can do is
I'm gonna move this fall back,
so I will say, move file too
back to Dir wander too.
So moving it to the director, too.
A little bit confusing Durban slashgear too. But I don't need to specify the absolute path because this is a subdirectory of the folder on it. Right?
I could have typed the same committee, And
this way, if I want to be more proper, but the shell already knows what I mean. So it lets me do it this way.
so now I move the file back
and I can see that it still exists there.
And similarly, I can
move that file to my current directory and call it
filed two lives.
Now I've moved the file and renamed it in the same time
And now I can move it back where it came from and
give it back. It's old name.
All right, so, moving files, copying files. Very simple.
But what if I want to do this?
Recursive Lee, I could
run a copy command dash R and say
copy everything under
to slash temp directory one.
And if I look, there is
directory one in slashed up.
So if I
look, I can actually I'd better do a tree command.
So there is my structure
I don't like. Did was run the copy command with a capital R two cursive.
And this is very, very handy because I can take an entire directory tree and copy it somewhere else.
Very, very useful.
This can also be done with the move command so I can run, move
dir one. And here I'm going to specify a target directory, so slash t
and again, Look these things up
with the man. Paige. Well, look at that. Hearing a movement, an amendment,
and I'm gonna rename it when I move it.
Can't. Can't use it that way. I have to just specify the folder.
It should be back.
Backtracked one second,
so I'm gonna remove
still can't type today. Remove that director I created earlier. Now I can run the move. Come in again.
There we go. So wanna move directory one with a dash T option for the new target directory.
Now it lets me
and I can see that my directors have been recreated underneath tip,
so it's very, very useful.
So for removal, let's let's take a quick look at
So there's that force option I mentioned.
Dash are just capital Artery is also supported. I'm in more of the habit of Taiping Capital are because that was
first when I learned. I guess that's why you like it better.
So it's usually good idea to use f with recursive
removal, just in case that prompts you for some file or some special situation. You could do this if you're especially if you're running a script. You want the script to be able to reliably remove files, so that's an important distinction.
And then we'll look at helped remove.
I could also do a forced move.
There's that target directory I specified,
and I could even do things like moving and based on the
the the modification time we have a few different options for how you can deal with these
we made that direct retreat,
and I also have the option to run remove directory.
So now if I try to run this against a director that has contents, it tells me, of course, that it's not
I don't really need remove directory. I can just use our M, but if you like this better, you should know about it anyway.
I can specify
the Dash p supposed to delete parents
all I know what's wrong. So
So if I wanted to do it a different way, I could delete
a some deep sub director and then delete the whole tree above it.
So it's kind of the opposite of way normally would think about our ability and the top folder and all the files below it.
We can see that it's now gone.
All right, so let's talk a little bit more about wild cards. We saw this mentioned earlier
the different wildcard types zero or more characters with the asterisk, the hook or the question mark for a single character.
Any position in the name
and a list of characters were arranged or negated list or negated range.
Or we have words
and then we'll last. We have the dollar sign.
So this match is at the end of the line,
something that perceives the dollar sign in your search pattern.
All right, let's look ATT.
Some examples here.
Look at my temp folder for some files to work with. Okay, so I've got
a bunch of files that have system D private and then some big, long string of what appears to be a hex data.
So these are good examples.
I can do a
Are we the list files
that somehow maybe I know that my foul name has the word private
and it's somewhere. I'm not sure where if it's near the beginning or the end, so I can just
search for this way and I get my results
So it doesn't matter what's in front of it, what's after it. The wild card takes care of that
I can also try something a little different. I can
maybe I know that the word province there, but I'm not sure how Private spelled. I think it's
PR something. I need to have wild card before that P r Something
maybe a vey probably ends in a, uh,
a t e.
You can also get the same files
so I can guess what's in between the ranges of characters that I want Thio Match on
now, using a single character position
again I actually start with System D. Right. So I've got
Let me go to
I still don't fit side by side. Let's find, um,
let's look at
files that start with the assistant D
And then I know I've got the
the word private there somewhere. But I'm not sure about that particular
and clear the screen again to show that work.
So I'm searching for something that starts with sister or system, Whatever it is,
some things in the middle I know the word privates. Probably there. I think this this might be a, uh, an I. R. V. I'm not really sure, so I can find the files this way.
Another option is to search for them
the range of characters.
See if that works. And it does.
the word that I'm searching on a system of beginning or a throw V that captures,
I probably could have maybe maybe got a different number. Files. About what? It's a through Z.
So anything that's after the word cysts that's in that range of a through Z I want to try to match on it.
I could be more specific
match on those three letters, which I know should be part of the list.
Show that that worked.
So I'm looking for anything that has the begins. What Cysts has a T an E and an M somewhere in that that file name.
So it's very useful.
And because I can match in these different ways, I have more options for finding things I'm interested in.
Conversely, I could negate thes.
So now that showed me that there are no files that match that criteria.
If it starts, would cyst. It has to have the letters T, e, T, E and M, and there somewhere. Since none of those match my, uh, listing does not produce results.
Now, what if I change that
two wild card, the beginning
still in there?
Because I've got wild cards before and after. It's not gonna work the way I was expecting
but you could see why this does not return when I negate.
Now let's look at some other commands.
We have the
now when I use the greater than simple earlier that counts as a touch command. But it basically it's a simple one of just creates a brand new file. I can also run the touch command like this and specify file name that I want to create. Empty.
Or I can modify its
by using these examples here
pretty handy to be able to create a file and then say OK, I made this file. I wantto give it yesterday's date at 9 a.m. So I can run Touch Dashti yesterday
on that founding
could also specify the date and time like this, like 2018 January 15th 9 30 in the morning and 300.32 seconds.
This might be really useful if you're creating log files for an application or something of that nature, and I want to be very specific in how I
named the file
or how I created time stamp
so very, very handy.
And then we have the file command itself,
is a little bit different than what you might expect.
Anyway, Let's let's play around with touch for a minute. So I'll create file one
and it's taking the current time and date.
So what I can do is say fall one or rather than a touch.
And I wanted to make it look like this file was created. 9 a.m.
So now, if I
list that fall again,
it has a time stamp of 9 a.m.
I can also go back in time with this. I'll say,
three days ago.
So instead of April 8th and should be April 5th, and it is very simple to use.
Then I have the file command. So if I run file against a particular file, well, this one's empty. Doesn't really give me anything useful.
This is an interesting looking for what is
this young file here?
Tribe Yom tab complete.
All right. This is asking text with very long lines.
Might be interesting.
What about one of these System D files?
I like this one that ends in a B. J. So
you run file on s'est something and then b j
that you imagine, Uffe,
that is a directory,
and we should know that because it's already blew, right?
So instead of running afoul, come in there, I will
do along listing
another directory. Let's wanna file committed against something else. Like if configure. I know this is a system binary,
and so it's gonna tell me this is
a 64 bit,
Lee significant bits that
processor architectures details there.
It's a 64 bit compatible, binary,
dynamically linked uses shares, libraries, which we talked about shared libraries before
and even gives me a hash value
for this file. And I can use hash values to compare against changes in the future.
Not really super important for this course, but it's something interesting to think about.
very useful because it lets me
look at the actual type of item that I'm inspecting. So that's been directory these, that this should be all pretty much binary files that we saw. Some bald thinks there,
so some of those were links.
Looks like I found a script,
and it can. It can detect all the different file types that you would
expect to get on the system,
and you need to know a little bit about the find command
find does just what it sounds like. I can search for files based on their name based on the type of file
I can search down deep into a directory folder starting at the bottom. That's what the death option does.
I can return a list of files that exceed a certain size
and even look for files that have specific owners or specific groups
and taken action with a file.
Why am I running the exact you
command line option?
So let's look at some examples here.
All right, so these
actually, you know, good A good thing to search for is all my config files. So I'm just going to say star dot com
probably should get a decent sized list.
So no matter where these files are located,
it matched on
the wild card up to the point where I had dot com Flint.
So we look at the fine command. We start off with the search directory, some surging from route.
I'm giving it a name and specifying the parameters.
So that's a simple, uh, I can also search.
Let's say, I know I want to search in the temp directory. There's something
there that I
Sorry. Tough directory. And I know that there's files that they'd start with
something called System.
Now you notice that it gave me an heir message, whereas before I was able to use a wild card freely. It depends on how, uh, what kind of files you're looking for. If you want to be safe, you should put double quotes around what you're searching for for a name
here, you get more reliable results that way.
Now, what I can also do is
I can search for files. They're owned by
the father of a specific type.
And so maybe I'm interested in looking for files that are regular files. So I can
specify the type, parameter and option of F.
So these are the regular files underneath
the temp folder.
I know I've got a bunch of directories here, so I was told search for directors instead change the type after type D,
and now I only see the names of directories,
so I know he created those earlier off These system D entries are also directories,
and it shows me the contents underneath each directory as well.
Now, when I ran here. Waas
find underneath another director tree, which is large slash user with the depth option and what death does is lets me search the deepest folders. First
shows me all of the other folders
that comprise that directory tree.
So I ran a tree command. You can see what those what those off folder structures look like.
that's looking for help.
So far, it has quite a few options for dealing with regular expressions.
I can also delete things, and I file I can print there
information. I can run the exact option two.
Tell the system. Do this command for whatever gets returned by the fine command.
Yes, a depth processes the contents of the directory for the director itself,
and that might be useful in certain cases. When you want to get the results of a find,
they're in a very specific format
Now. I could also try to find files that are
of a certain size.
So these are all the files underneath slash user
that were greater than 10 megabytes and size.
You can specify bytes, kilobytes, megabytes, gigabytes here,
Using using obvious letters B for bites and for megabytes G for gigabytes.
I can also look for files that have a specific modification time.
So the last access time
these are files that were access within the last three days. So a time of three
and you can see this in the man page as well.
I'll do a slash research a Time
End times 24. So if I put three, that's three days
the creation time. I can also look for that.
I can test if a file is newer or older than a reference date,
plus or minus gives me the option to say
Maur than three times or less than three times. Aiken. Use that positively negatively for different fine strings.
So find has a lot of lot of useful options. I can also do things like Show me files underneath temp
owned by route.
Those are all the files room. But I can also look at the ones that are
have an ownership of, uh, group ownership of route. I get the same list because
those files are all root and route. Maybe admin is a better choice because that was a smaller
listening so These are all the files that are in the owned by the admin group underneath slash temp.
All right. And then we also want to look at
way to run the execute option for fine.
So a surgeon temp?
Let's see, I want to look for, uh,
I want to execute and, alas, Dash Ally A on that directory.
Syntax Little bit weird. I have to use single quotes, curly braces and then a backslash with a semi colon to delimit this command properly.
But only did. Here was a long listing out whatever was returned by
Maybe I want to say,
I know there's a foul underneath temp. I want to see what it's details are. I could find it that way. Maybe I'm interested in
dot young t X files.
Find him that way
frequently. What this is also useful for is maybe I want to go search for a certain kind of files. And instead of using the exact for listing, the father may be on to something else like remove it.
And I could do this for a system cleanup purposes. Maybe I
I want to find all the files that are above one gigabyte that that are in the Temple folder because they might be things that I don't need any longer.
And I can tell find to delete those
All right, moving on.
Let's talk about compression and decompression of files.
Let us give you several options. I can use Jesup. I can use bees up, and I can also use X Z and various other tools. They all work fairly similarly as faras the command line options.
But I can take when I create a file with Ji Zippity renames that with a dot jeezy extension,
and then I can use G unzip or guns up to then un compressed. This file
bees up to, as it says here, uses the same
options, but it's a different compression algorithm. It might be a little bit better for certain types of files,
and there's also X Z and a neck see
as additional options,
which which might be better in certain circumstances. For,
uh, some compression algorithms are better for
binary files versus text files and so on. That's why we have a different bunch of different choices.
So, uh, what I can I'll try first is algae. Zip my messages file, since that's something
sort of large
and we see that it created messages dot tex dot gz. So we went from 1.8 megabytes
to 190 kilobytes. That's pretty good compression ratio.
I can now unzip it.
I had a tab completion,
and I've got my file back.
Now, if I zip it again,
let's look at our help real quick
so I can enlist my file contents. I can run a dash. L,
uh I can use this Dash nine
option to compress the file better
so we can compare
kilobytes. I'll unzip this again,
and this time I'll gie zip it with a dash nine
and it went down to 1 86 So it made a little bit of improvement.
I can run Jesup Dash l toe. Look at the contents of
that file. There's only one file here, but it tells me
that it was compressed
what the UN compressed size was and the compression ratio.
So if I Jesup the whole bunch of files into a archive, for instance like I might do with tar,
then I can go list that the contents.
so me unzip this again.
So be zip.
that work much better. So instead of 1 90 I've got one or two
and then I can be unzipped that
Look at her help. Real quick
decompression dash d
But there was also beyond zip.
I forgot the two. That's why didn't work.
all right now I'm back to my 1.8 megabytes
Then I can also compare that with X Z.
That one always done to 90 megahertz are 90 kilobytes. So x Z is by far the best choice of these three for a text file
and then I can on ecstasy to get
All right now I will move on to tar and C p I. O
and the D D command
tar is useful because I can create what's called a tar ball or ITAR archive.
I can copy a bunch of different
files into one object,
and that object can also be compressed. It gives me a nice, portable way to move files around
the C p I O command stands for copy in and out.
And what that lets me do is various different things. I can
take a bunch of files, create a CPO archive, which is similar to a tar archive. I can also use it to move files around.
And then lastly, we have D D.
And I did. He lets me specifying input file and an output file and then some blocks, eyes and count information. This is useful for copying data in in bulk from one place to another.
Perhaps you're doing it for writing day into a tape drive.
Or maybe you're creating your bootable USB, and you want to write the boot loader with the DD commanders. Different reasons to use this,
and I'll show some simple examples here.
have a look.
So I'm in my, uh,
home director again. I've got a bunch of
items that start with the word files. When I can do
is put these into a narcotic sea for create, be for for verbose,
for the founding that I want to call it. So I'm gonna call it a file dot tar
and I want to give an argument of everything that starts with the word file.
Now file Doctor was created
based on matching that wild card that I gave it a file star.
Now, I might want to, uh,
inspect this so I can look at my,
tea for table of contents V for verbose
for the file name.
And if I run that against follow dot tart, it shows me what was copied into that timer. Got This is what actually created.
I could also, um,
remove these files.
Oops. We try that again.
Armed are rough file.
Oh, I don't want to do that. I removed my my archive as well.
Undo. Why isn't there an undue
I should have been more careful there. I should have removed my file dot text files.
Anyway, what I was gonna show was that I could recreate that those files by X
All right, so I'll create three new files.
I will put these into a archive,
and this time I'll call it
file archived on her
Capture everything. That's enough. All right, so
now I'm looking at my table of contents.
All right, so those files are gone. All I have left is the archive.
Now it can extract it using the dash X option. I like to use verbose s so I can see what's actually going on
with my extraction
and a printed book to the screen. And now my three files are back.
So pretty simple to use,
not are also
Well, help is a little bit long.
I can also upend an archive self. I create a bunch of files I can use the dash. You option to add more files to that existing archive to keep growing it if needed.
There's our options up there, create table of contents and extract.
And there's some other options to be a little more specific with modification times and so on.
But you should know the basic,
options. I also have
my compression options
so I can compress with Visa to compress with Z.
I can compress with one of these other tools, like L zipper Els, E M. A.
Or the dash is the option for Jesus.
We saw A Z has a pretty good compression ratio, but you might want others. In any case, this is pretty convenient, cause now I can create a dot tar dot gz file or don exit the file or so on
to create the archive, bundle everything together and then compress it at the same time.
It's pretty useful.
All right, now, let's dig a little bit into C P I O.
That stands for copy in out.
Look at our help. First,
I can create an extract archives that can also do a pass through or print a table of contents.
And then I've got various options for
which kind of files I'm on a copy and whether or not I want Thio rename them and interactively and so on. There's some other options. They're pretty useful. We're gonna cover the basic ones that you need to know for the exam.
So, uh, first thing I'm gonna do is see what falls out on a copy. In this case, I'm still gonna work with these.
These four files here, three empty files and one that sitar archive.
So find from my current directory name
So that finds those.
And I'm gonna point this to CP I up
so I can create an archive by using the over output V for verbose, which I like, and I'll give it a name of files dot c p i O.
Now we see, I've got my CP I archive
now That's the output command. I can also
input now, when I input from C P i o.
It is going to
recreate whatever path name was captured. So if I did a relative find or I didn't find from root, it'll put the files back to where they came from.
So I can
test this by removing these files.
So now those air gone and I'll re import my archive.
So I for input or or extract a V for forever Bos, and then I have to redirect from
back into my command. If he knows we talked about this redirection operator earlier
I'm basically I'm pulling the file as input to CP I Oh, Desh Ivy. So I have to specify my CB I archive,
and it tells me that those files those four fouls have just been recreated. Even though I deleted them, they're right back where they came from.
Sometimes this isn't really convenient. Maybe I want to make an archive off
files and I want to move them somewhere else.
But I don't want to create
or I want to take a directory tree, rather move it somewhere else. But I don't want to create
a archive in the meantime,
so I split up this messages file again into three pieces I've got, Say, ex, maybe an ex a C.
This gives us a little bit more to
so we'll create my archive again.
Okay. I've got a nice big archive file here.
Actually, it's a little bit, huh?
Look at larger than the original.
That's fine. I'm just bundling everything up. There's a little bit of overhead there,
but maybe I want these three large files in another director so I could make a director here called Temp.
Go into that directory
now I can run CPO with it.
The input function again. V for boast. This time I'll specify letter D for
extracting the archive into my current directory.
And I have to go one directory up to met reference this file messages dot c p i o.
Now, if I look at my temp directory, they're my files.
Another option and I want to remove
Another option for C p i. O. Is to use
fine function again.
But this time what I'm gonna do is use the past operator soapy for past V for Bravo's
D for the directory. I'm going to specify. I am gonna tell, too.
find everything that's named X A
and move it to this other directory.
Now, if I do l l on slash tempt my files. Are there
very handy stuff?
This way I can take an entire director our directory tree and move it somewhere else, preserving absolute path names if I want to or using relative path names. If that's more convenient
that our last command to cover is DD
so this can copy files
and do some conversion if possible,
I can convert from asking absent disc ups a disc
up. Sadiq Sorry.
Also from a IBM format Uppercase the lower case. I could do lots of different things here,
deed is more frequently used when I want to move
information from one place to another in its raw form. At
So, for instance, maybe I want to make a file for doing some other testing.
I can specify
an input file. I f
in this case, someone to specify one of my system devices called Deb zero.
This is a special file that Lennox has. There's Dev Random as well.
And this will let me create an upward file
a certain number, a certain amount of data
that just randomly created.
I can specify a block size on created 10 mega by block signs,
and I'll count
to create 10 of those.
Now, if I look, it tells me my stats for how fast that happened.
My zero file dot text
is now created
and you see it's about it's 10 megabytes.
So I just
generated a bunch of data, moved it from someone, put some standard input or files input and then created it as output.
I could also do other things. Like, for instance, if I had a
I've got a CD that's mounted
so I could do Is space say input file?
Is this entire archive or some,
file inside this archive?
That's not a good choice because there's some really large follows there. But I could take that CD and I could copy it somewhere else. I could copy to a removable media like USB drive.
Let's do one thing real quick.
I wonder if I can do it this way. Let's try reading from Dev
s r. Zero.
Yeah, so I can read from it directly, but you can see this is obviously binary data. It's not gonna be very, uh,
useful for me, but I can specify my output file as,
you know, like a USB drive. For instance, if I want to copy the seedy image to a U. S. B, I could do it this way. I could just say,
Tell me that source from the CD rum destination becomes the USB drive.
And I could specify block sizes and different things if that suits my purposes.
But there's a really useful utility when I want to write raw data from one media to another,
and it'll it'll capture the file system information, whatever else is in that source location.
All right, so that gets us to the end of our file maintenance chapter. We looked at a lot of different utilities. We know how to make directories, how to make them a nested howto copy files and remove them renaming in the process if if needed.
We also looked at some compression utilities like tar C, p i, o Jesup, and be zip
and exit. Can't forget XY
and we covered file gloving, which is the use of the various pattern matching
felt facilities wouldn't show.
We have the asterisk
for matching 10 or more items.
The question mark for matching one or more items,
a range of characters or specific characters of specific words. That is the concept of glob ing.
All right, so our next topic is using streams, pipes and redirects, which we've covered a little bit, but we're gonna dig a little deeper as well. All right, See you there. Thank you.