A Word About the Linux Filesystem
Linux's filesystem can take a little getting-used-to coming from Windows. The filesystem in Linux always starts from root or '/', and all drives and partitions are mounted in the filesystem from there. Directories are hierarchically written out with slashes (/) between each directory. For instance, your desktop is located at '/home/johndoe/Desktop'. This says that it's a directory named 'Desktop', within a directory named 'johndoe', within the 'home' directory of root. This could have also been written as '~/Desktop', as the tilde (~) indicates the currently logged in user's home directory. Notice also that 'Desktop' is title-cased. The Linux filesystem is case-sensitive, so 'desktop', 'Desktop', 'DESKTOP', and 'DeSkToP' are all different directories.
Basic File and Directory Commands
| Changing Directories | cd [directory] |
|---|---|
| Creating a Directory | mkdir [directory] |
| Copying a Directory | cp -r [target] [destination] |
| Moving a Directory | mv [target] [destination] |
| Removing a Directory (empty) | rmdir [directory] |
| Removing a Directory (non-empty) | rm -r [directory] |
| Listing the Contents of a Directory | ls |
| Getting a Detailed List of the Contents of a Directory | ls -l |
| Copying a File | cp [target] [destination] |
| Moving a File | mv [target] [destination] |
| Removing a File | rm [file] |
A Note About Permissions
Every file and directory in the Linux filesystem is subject to priviledges, owners and groups. Priviledges are things that are allowed to be done to a particular file or directory by those who have permission to do so. They are broken down widely into read, write, and execute priviledges. Groups are, obviously enough, groups of users who 'own' certain files and directories: they have permission to edit and otherwise alter or use files that have been given to their group. Owners are members of groups but have their own files and directories that they 'own' that the rest of the group does not. Root is a special user who in effect owns all files in the filesystem and belongs to all groups. This gives the root user complete and total authority of every part of the system, which also makes root a potential dangerous user. Most Linux distros, including Ubuntu, do not assign root to the computer's owner, rather creating a separate account for them. Ubuntu goes a step further and assigns a random password to root that the computer owner doesn't even know. This is good in that it protects the system against attacks, but it also creates a problem when things must be done on the system which actually require root priviledges. Thankfully, there's solutions for this.
Administrative Tasks
| Do Something in a Terminal as Root | sudo [command] |
|---|---|
| Use a GUI Program as Root | gksu [command] |
| Use Terminal as Root (Potentially Dangerous!) | sudo su - |
| Change Priviledges of a File or Directory | sudo chmod [u/g][+/-][r/w/x] [target] |
| Change Priviledges of a Directory and All Files and Directories Within | sudo chmod -R [u/g][+/-][r/w/x] [target] |
| Change Owner of a File or Directory | sudo chown [owner]:[group] [target] |
| Change Owner of a Directory and All Files and Directories Within | sudo chown -R [owner]:[group] [target] |
This will do for now. I might come back and add more later or follow-up in another post. I intend on discussing some of the basic ways of editing files, but this really requires an post in itself.