Fourth Friday Linux Lesson

Tagged as Linux

Written on 2007-06-08 22:38:00

So, I've been thinking about how I could improve these lessons and if anyone has ideas they should let me know (max, that's you :-). Anyway, I was reading full circle magazine early (it's an online rag all about Ubuntu) and they had a section on the directory structure in Linux which would definitely be useful for someone who isn't used to Linux. Thinking about this I realized that my requiring one application or command to go with one concept is an artificial and possibly bad constraint to place on these articles. I mean, file management involves (at least at the command line level) a minimum of two or three utilities and as many as you like really. One, cd to navigate the file system and two, rm to delete stuff. Potentially there are also commands like locate\find for searching, nano\vim for editing, apt-get\yum for installing\removing software, mkdir and rmdir to create and delete directories, and more still. Now, even though that list may appear intimidating it's really not and it's far from comprehensive as well. It is however really nice to just use whatever makes your life easier and ignore the rest. Anyway, let me know what you would be interested in hearing about next week cause I'd really like to know.

The concept for this week is file management and\or the Linux directory structure. The base of the Linux directory structure, the mother ship from which all other things spring, is "/". Under that you have an assortment of "/bin", "/boot", "/dev", "/etc", "/home", "/mnt", "/media", "/opt", "/root", "/tmp", "/usr", and "/var". "/bin" is where a lot of your basic command line utilities go so when you type a command in the terminal it starts by looking here. It's sort of like Program Files but it basically just holds executables or "binaries" hence bin. "/boot" holds the information the bootloader needs to get the system up and the configuration files for said bootloader. "/dev" holds all your devices. Literally. Your cdrom drives, hard drives, usb drives, audio and video cards, everything, has a "/dev" entry. So the operating system talks to your stuff through this directory and it sort of just maps out where everything is for your system. "/etc" holds a ton of configuration files which is nice though not everyone stores all their config data there. I guess that's a good thing. There are a few central documents of importance there you may find yourself playing with. More on that later. "/home" is just what it sounds like. That's where your user directories, desktop, and most of your other stuff is found. "/mnt" is a place where drives get "mounted" so you can read and\or write to them. Some distributions use "/media" instead of "/mnt" but they're essentially interchangeable. They are where you (not the operating system) go to check out CDs and USB drives and iPods and such. They do something called symlink (which is sort of like a precursor to hyperlinks on webpages) to the "/dev" entries for whatever you want to play with. "/opt" contains optional stuff you might install but not everything you do install. It's a grab bag. Mine's pretty much empty. It kind of has what you put in it. "/root" is the root user's version of "/home" it's normally pretty sparse and remember root is god so you don't want to play around in there. Root might get pissed at you. "/tmp" is just what it sounds like, temporary files and stuff. "/usr" is the real Program Files. This is where a ton of your shit ends up going and you'll notice it has subdirectories like "bin" "docs" etc. Finally, there's "/var" which I mainly find myself going in to peek around the "log" subdirectory. That's a pretty decent overview of the Linux filesystem.

The utilities to keep in mind with file management for me have been "mkdir", "rmdir", and "rm", "cp" and "mv". That's really all I use. mkdir and rmdir are two sides of the same coin. mkdir makes directories and rmdir removes them but, interestingly enough, only if they're empty. The syntax looks like this "mkdir mp3s" and "rmdir mp3s". Since you'll want to put your mp3s there you can use cp to copy them over. It'd be easier to use mv but run with me on this. Say all your mp3s are in "/home/your_username/downloads/music" you could use "cp /home/your_username/downloads/music/*.mp3 mp3s" and it would copy all your files with the .mp3 extension (*.mp3) to the mp3s directory. Then you could do "cd /home/your_username/downloads/music" and "rm *.mp3". That's not very efficient though, is it? It'd be easier to just blow away the directory. Well, you can. With rm -R. "rm -R /home/your_username/downloads/music" will remove files recursively starting at /home/your_username/downloads/music. That is, it deletes everything in the directory as well as the directory itself. Interestingly you can rename things with the mv command and that might be the easiest way to do this. For example, "mv /home/your_username/downloads/music /home/your_username/downloads/mp3s" then "mv /home/your_username/downloads/mp3s /wherever/you/want/mp3s". Generally I do file management from the file browser. I still like a GUI for it but if you're running into permissions errors it helps to come down and "sudo rm -R" or cp or mv something. Of course, if you don't know what file is giving you permissions errors you might not want to do that. Anyway, this hasn't been explained beautifully so let me know if this makes sense and\if you have questions.
comments powered by Disqus

Unless otherwise credited all material Creative Commons License by Brit Butler