View Full Version : Can Somebody Explain What A "Directory" Is In Linux?

14-04-2016, 09:18 AM
Use the following command to compress an entire directory or a single file on Linux. It’ll also compress every other directory inside a directory you specify–in other words, it works recursively.

tar -czvf name-of-archive.tar.gz /path/to/directory-or-file

Here’s what those switches actually mean:
-c: Create an archive.
-z: Compress the archive with gzip.
-v: Display progress in the terminal while creating the archive, also known as “verbose” mode. The v is always optional in these commands, but it’s helpful.
-f: Allows you to specify the filename of the archive.

Let’s say you have a directory named “stuff” in the current directory and you want to save it to a file named archive.tar.gz. You’d run the following command:

tar -czvf archive.tar.gz stuff

What is this DIRECTORY about which they are speaking?

14-04-2016, 09:37 AM
Directory in Linux = folder in Windows.

14-04-2016, 12:47 PM
Thanks, PC.

What's the reason you'd move files in a folder anyway? Isn't that just some 'coder writer's' activity? I'm not too much into writing code or doing TOO much line entry things either.

That may change as I grow (fitfully) into L-based distros.

14-04-2016, 03:45 PM
When they talk about moving, they mean to a different location, not moving it around inside the existing directory.

Say you have photos stored in your Documents when really, to keep things consistent, you could move them to your Pictures directory/folder.

This command that you are showing, is a way to 'zip' files up. There are graphical tools for it, I think Ubuntu may use file roller?



14-04-2016, 04:34 PM
This command that you are showing, is a way to 'zip' files up. There are graphical tools for it, I think Ubuntu may use file roller?


Ahaaaa! It is for zipping them UP, not unzipping them then! Hooray.

Then do they have to be unzipped to get them to work?

14-04-2016, 06:42 PM
Linux can work inside files that are compressed (zipped) like it is a normal file or directory, so it is possible but to me, you are better off working on the uncompressed files till you get the hang of it or use the graphical tools that are made to help you.

You should not be linux shamed if you want to use GUI over command line.

tar is the back up program that was used to record data to magnetic tape media but is now not limited by that media.

-c means you are creating a new backup, use this when you are not working with an existing archive.

-z means you want to compress (zip) the folders and/or files to store it in a smaller size. This compression uses gunzip, which gives you the .gz on the end of your tar file.

There are numerous other compressions that can be used instead of gunzip like -j which is bzip2 that gives the .bz2 extension. These are the 2 most common extensions for compressed files you will come across, tar.gz or tar.bz2. The only difference for the end user is one may save you more space than the other.

14-04-2016, 07:03 PM
<KAME> Interesting. Let me see if I understand some of this. It sounds like a file (the directory or INSIDE the directory, or as another directory - er, confusing) need not be 'unzipped' but can be read directly inside a directory without unzipping it, by tar. Is that right?

In other words, even if a file (directory) is in a compressed state, tar can still do a mini-unzip and read it, operate on it and/or change the directory (file) and re-compress it and exit, leaving it as it was.

-c is for use in a VM. Right?
-z will recompress the file some more to make it smaller? This I don't understand.

And - this seems redundant: DIRECTORIES are files, and DIRECTORIES can be INSIDE another DIRECTORY, and all of them, collectively or individually, are called DIRECTORIES. Right?

If so, I like the Windows system whereas a FILE is INSIDE a FOLDER or a FILE can stand alone without being INSIDE a FOLDER.

There can even be multiple FOLDERS INSIDE FOLDERS, which may or may not contain FILES and can even stand as EMPTY FOLDERS.

14-04-2016, 10:21 PM
Yes, tar can show you inside a compressed file. File managers too incorporate tar's understanding and can give you the visual representation of it and similar tools to manipulate it.

Without unzipping is however incorrect, for a user, they don't need to know what goes on but in reality, the file can return listings (folders and files inside itself) without uncompressing it. If you do need to work on a file inside, like open a text file, it will be uncompressed on the fly, whether it loads it all into memory or stores it in a tmp location is program specific.

The reason it has to be uncompressed is that you need to understand that files usually have a few bytes to tell us what type of file we are working with. I call it a magic string/header, it could say 'this file is a txt file', but compressed those bytes may look gibberish and say 'tfiatf' to save bytes and our text editor will not understand it and show us exact gibberish if it opens it without first uncompressing it.

So yes, a mini unzip takes place, you save the modified txt file, it gets put back into the archive, gets compressed and a new CRC checksum is created so that we can detect if the archive is corrupted or not.

tar -c is the option to create an archive, it is the same as tar --create, its an optional command we can include with tar.

-z is not quite recompress, but compresses tar. It's like tar is like an order, keeps things exact, may save bytes too, like turns 1,2,3,4,5 into 12345, while -z (gunzip) turns tar's 12345 into 15.

hyphen - being redundant is program specific, its an old convention that was used to pass options, e.g tar -c -z is the same as tar -cz (single hyphen with all options joined) which if programmed correctly can also be typed as tar cz (hyphen removed). The first method is guaranteed to work, the rest may or may not.

Directories are folders to a user, but behind the scene, they are just text files which act as transport to locations, so a Pictures folder, is like hopping on a train and being taken to Pictures where all your photos are. They act like separators/dividers, because it does not matter to Linux how your hard drive is filled with bits and bytes, it could be seen as being like a book and directories are the indexes in the back, just points you to the right page, where you'll find lots of words (files).

Files in Windows can not stand alone, they have an identifier like a directory. C:\ is the root directory of your first hard drive, just like / is the root location of a hard drive. In other words, thats the greatest grand parent of such drive, there is no older parent than this on your hard drive, everything inside of it, is a child to it.

Directories/Folders, all the same, concept however is different but for the user, acts exactly the same.

Open a folder up in a text editor, you may need to pass this as a command as most editors think you are entering the directory instead of actually wanting to open it.

I hope some of my stories make sense, its hard to metaphor all this from a mobile phone.

15-04-2016, 03:09 AM
<Kame> - thanks, as you are pretty much the sole person from whom I have learned all the things I have about Linux - and a smidgen about Windows too.

The most fun part of this all this that I am learning a lot at this time in life - 70 y/o in a few days. Your thumbs must be smoking from all the typing on a phone keyboard. Again - thanks very much.

15-04-2016, 08:17 AM
Before Windows O/Ss it was called a directory. And so it was in DOS too

15-04-2016, 08:41 AM
Before Windows O/Ss it was called a directory. And so it was in DOS too YEP been there for ages. Sometimes its quite 'fun" using commands instead of a GUI.

In the picture below, commands highlighted.

cd = Change Directory so cd c:\ = change to C Drive then dir shows its contents :)


15-04-2016, 11:37 AM
I remember some of that - it's been a while though.

15-04-2016, 02:02 PM
I am not sure if Windows coined the term folder, but directories was what you would call them in a command line interface, while folders was from the graphical interface because they used a folder icon to represent it.

15-04-2016, 02:50 PM
and shall we introduce you to the wonders of Powershell Joe............................

15-04-2016, 06:43 PM
beama>and shall we introduce you to the wonders of Powershell Joe............................

I can hardly wait.

At this time, I feel I haven't treated myself harshly or badly enough. I've just downloaded k3b.

Let's see if I can really stir my grey matter.

I STILL want a spellchecker in this 32 bit system. If I can't have it, I may add Puppy here as a dual boot and hope the dictionary IT has is cross-over-able to whatever I'm typing at the moment.