Edit History Actions Discussion

Diff for "Howto/FileManagement"

Differences between revisions 1 and 5 (spanning 4 versions)
Revision 1 as of 2007-11-05 18:47:52
Size: 5394
Comment:
Revision 5 as of 2007-11-06 18:51:05
Size: 11597
Comment:
Deletions are marked like this. Additions are marked like this.
Line 10: Line 10:
Line 13: Line 12:
{{{nano myfile.txt}}} {{{nano myfile.txt
}}}
Line 19: Line 19:
{{{touch newfile}}} {{{touch newfile
}}}
Line 23: Line 24:
{{{mkdir mydir}}} {{{mkdir mydir
}}}
Line 27: Line 29:
{{{ls}}} {{{ls
}}}
Line 31: Line 34:
{{{cp myfile.txt mydir/}}} {{{cp myfile.txt mydir/
}}}
Line 35: Line 39:
{{{cp -r mydir/ mydir-bak}}} {{{cp -r mydir/ mydir-bak
}}}
Line 41: Line 46:
{{{cd mydir/}}} {{{cd mydir/
}}}
Line 47: Line 53:
{{{pwd}}} {{{pwd
}}}
Line 51: Line 58:
{{{mv myfile.txt ../}}} {{{mv myfile.txt ../
}}}
Line 57: Line 65:
{{{mv myfile.txt renamedfile.txt}}} {{{mv myfile.txt renamedfile.txt
}}}
Line 61: Line 70:
{{{rm renamedfile.txt}}} {{{rm renamedfile.txt
}}}
Line 79: Line 89:
Detailed Layout.
{{{-rw-r--r-- 1 independence shelluser 0 2007-11-05 19:32 myfile.txt
|\ /\ /\ / | | | | | | |
| | | | | | | | | | \-File name
| | | | | | | | | \-Time created/modified
| | | | | | | | \-Date created/modified
| | | | | | | \-Size of file
| | | | | | \-Group the file is in
| | | | | \-Owner's username
| | | | \-Number of hard links (or files in directories)
| | | \-Other permissions
| | \-Group permissions
| \-Owner permissions
\-File type}}}
Line 93: Line 118:
{{{chown independence myfile.txt}}} {{{chown independence myfile.txt
}}}
Line 97: Line 123:
{{{chown independence:othergroup myfile.txt}}} {{{chown independence:othergroup myfile.txt
}}}
Line 105: Line 132:
{{{chmod g+w myfile.txt}}} {{{chmod g+w myfile.txt
}}}
Line 123: Line 151:
{{{chmod u+x myfile.txt}}} {{{chmod u+x myfile.txt
}}}
Line 126: Line 155:
{{{chmod o-w myfile.txt}}} {{{chmod o-w myfile.txt
}}}
Line 130: Line 160:
{{{ls -l yourfile.txt}}} {{{ls -l yourfile.txt
}}}

==== Changing Permissions (Numeric) ====

We can also change permission of user, group, others using numbers. This might be used in other howtos and similar on the Internet so it's good to know, but it's not really ''needed'' to manage files. We will get into this now. We will be changing permissions of files with numbers.

So lets first explain how to understand what numbers control what permission, it is rather simple actually, their are only 3 numbers you need to remember.

 * read == 4
 * write == 2
 * execute == 1

Basicly we are just doing fundamental adding, to get the number you first decide what permissions you want to set, then add those numbers together, we need to do this for all 3 categories, user, group, and other. So if we want a permission of read/write but no execute then the number would be 6, and if we wanted read/execute only the number would be 5.

well now that we understand the basic idea, lets do some examples.

The following example will make myfile.txt user read/write/execute, group read/execute, and other read.

{{{chmod 754 myfile.txt
ls -l
-rwxr-xr-- 1 bushblows shelluser 0 2007-11-05 19:32 myfile.txt}}}

Now we will make myfile.txt user read/write/execute, group read/write, other read/write.

{{{chmod 766 myfile.txt
-rwxrw-rw- 1 bushblows shelluser 0 2007-11-05 19:32 myfile.txt}}}
Line 134: Line 190:
ls -lh

quota

du -hs

== Compressing/achives ==

tar

gzip

bzip
When you list files with `ls -l` you will get the filesize. However, since this filesize is displayed in only bytes (no prefixes) it can be hard to get a good sense of how large files are. To help us read the output we can use the flag `-h` which stands for ''human readable''. This will make the filesizes display with prefixes like KB or MB which is much easier to read.

{{{ls -lh
-rw-r--r-- 1 independence shelluser 851K 2007-10-09 16:02 latest.tar.gz}}}

You can see the filesize here is 815K (KB or KiB really), which is much easier to read than something like 870766.

To view the size of a whole directory tree, we can use the command `du`. This will display the sizes of all directories below and including the working directory. To get some nice prefixes again, use the flag `-h`:

{{{du -h irclogs/Allshells
3.5M Allshells/}}}

To view your total disk usage and quotas use the command `quota`:

{{{quota

Disk quotas for user independence (uid 1000):
     Filesystem blocks quota limit grace files quota limit grace
      /dev/hdv1 56868 0 512000 1054 0 0
      /dev/hdv2 59124 0 512000 1185 0 0
      /dev/hdv3 7308 0 25600 710 0 0}}}

You see your quotas for each mount-point or partition here. `hdv2` is your home directory and `hdv3` is www (everything in public_html.)

`blocks` are the space you are currently using (in KiB), and `limit` is your hard quota limit. You can also see the number of files you have.

I'm using 59124 KiB of 512 KiB in my home directory for example.

== Compressing/Archives ==

Archives and compression are very handy in many different situations, and this is the topic we will talk about in this section. The most generally used archive/compression software in *nix is tar(archive), gzip(compression), and bzip(compression).

Tar is software used for archiving files/directories, but also supports flags to compress as well, we will touch on both a simple archive and an archive with compression.

To just archive a directory with files/directories in it, we would use this command:
{{{tar cf my_archive.tar /destination/of/directory
}}}

And our archived file would be my_archive.tar in our current working directory.


So we archived a file, but now we need a file from the archive, we need to un-archive it, we would do so with this command.

{{{tar xf my_archive.tar
}}}

Now to archive and compress a file, we will archive with tar and use gzip's compression. It's common to use the file ending `.tar.gz` (or less common: `.tgz`) to signify that a file is a gzip-compressed archive. This is how to make such an archive:
{{{tar czf my_archive_compressed.tar.gz /destination/to/directory
}}}

So we archived and compressed our file but need a file from inside, so lets un-compress it and un-archive it.

We would do so with this command:
{{{tar xzf my_archive_compressed.tar.gz
}}}

Remember to always put the flag `f` before the archive filename, and not in the middle of the other flags like `cfz`. This is because the flag `f` expects an argument which is the filename.

If you replace `z` with `j`, you get bzip compression instead of gzip. This is in my experience a better compression for text, but a bit more intense on the CPU.

More flags and usage for tar can be found with the command 'man tar'.

So lets just compress a file with no archiving, we will start with gzip.
This command will compress the desired file.
{{{gzip somefile.txt
}}}

Now if this file is a directory, then we need an extra flag unlike tar, so we would do so with this command.
{{{gzip -r some_directory
}}}

Uncompressing is pretty simple, however we use a different command to uncompress, with this command we would uncompress our file.
{{{gunzip some_file.gz
}}}
Line 150: Line 267:
getfacl

setfacl
Blinkenshell supports ACLs. You might need them if you want to do something a more odd, like giving one specific user (other than the owner) write permission or something similar.

Use the command `getfacl` to view ACLs set on a file:
{{{getfacl
}}}

To set ACLs, use the command `setfacl`:
{{{setfacl
}}}

== Finding files ==

Using `find`.

File Management

This is work in progress, not complete. Please help and add more stuff!

This is a howto explaining how to manage files on a UNIX system. This is very important to get the most out of your shell account.

Basics

The very basics of file management is how to list, create, copy, move and delete files and directories. To create a file, you can open up a text editor, write some text, and then save it. To do this with nano, type:

{{{nano myfile.txt }}}

This will open up the text editor nano. Write some text and press ctrl-x to exit, nano will then ask if you want to save the file. You can also use ctrl-o to just save the file, without exiting nano.

You can also use this command to just create a new empty file:

{{{touch newfile }}}

To create a new directory, use this command:

{{{mkdir mydir }}}

To see your newly created files and directories, use the command ls: