## Linux File System: Part 3

September 15, 2009

Well sorry it has taken so long but here is the third installation in the series on the Linux file system. In case you haven’t been following before now, here are the links to part1 and part2.

In this portion I will discuss the following directories/partitions: /lost+found /lib /mnt and /tmp.

## /lost+found

So you are working and all of a sudden there is a power outage. Or even worse your system suddenly crashes for no reason. Well the next time you boot up your machine Linux will try to recover any lost data/files. The result of this recovery attempt will be saved here. Sure the files in here might not make much sense but there is a small chance that there might be something that you might be able to actually use. Finally, for those of you that really want to know, this recovery is done by using the fsck command. Look into it yourself, since this isn’t the place to go into depth on it.

## /lib

The location of all the shared library files. Think DLL files on Windows.

## /mnt

This is the generic place to mount other file systems. Such as internal/external hard drives, CD-ROMS, DVD, and floppy disk if people still use those. For more information on mounting see the link to the post dedicated to this topic.  But I should mention that you can make any location a mount point, but it’s usually a good idea to have them all relatively “close” to each other.  Plus try not to overdo it, because really 50 different mount points might just be a little excessive.

## /tmp

Temporary files are stored here. In other words, DON’T SAVE IMPORTANT STUFF HERE! This directory is cleared upon each reboot of the system. As a side note, this is really useful for getting around disk quotas. Just save your files here and then when you restart they will be gone. All you have to do is make sure that you won’t be needing those files ever again.

## File Transfer and SSH

September 10, 2009

Well I’m not going to explain what SSH is (mainly because I would not do it much justice), so instead I will direct you to these pages if you wish to find out more. Suso Technology Services Inc. and Wikipedia.

Now suppose you want to SSH into a remote computer (one that I hope you know the name of) it is “pretty easy”. For this let us say that on that computer your username is NewKid and the host computer is FarAway.Land.ofDreams.

Then to connect to it from your computer you just enter

ssh NewKid@FarAway.Land.ofDreams

If prompted for a password then enter it. And look you are now connected.  At this point you will be able to perform whatever you want on the other computer.  However, there is no GUI so hope you like command line (which by now you should).

Now a lot of good this would do if you weren’t able to send and receive files between the two computers.  Suppose there is a file ~/urgent that you need to send to the remote computer, and wish to place it on the Desktop (~/Desktop).  Well you are in luck there is a simple way to do this.

scp ~/urgent NewKid@FarAway.Land.ofDreams:~/Desktop

There is a space between ~/urgent and NewKid… Note that if you had instead entered

scp ~/urgent NewKid@FarAway.Land.ofDreams

The file would have been placed in the home folder on the remote computer.

Now instead let us assume that ~/urgent was on the remote computer and we needed it on the local one (the one we are physically at).  In this case we run

scp NewKid@FarAway.Land.ofDreams:~/urgent ~/Desktop

Here we have copied ~/urgent to our Desktop. Similarly if we had not put ~/Desktop it would have been copied to our home directory.

Overall the usage of scp is

scp [user@from-host]:source [user@to-host]:destination

Really this post is as much a reference for me as it is a learning tool for others. Since I know that I will need to be sending and getting files quite often in the near future and am pretty sure that I will forget how right before I need to start. But hopefully, I will get back to talking about the Linux file system soon enough. Sorry for the ‘side post’, but I really do hope that someone will find it useful.

## Linux File System: Part 2

September 7, 2009

This is a continuation from part 1, so you might want to read that first in order to get a general idea of what’s going on.  That is  of course you are a somewhat experienced Linux user.

In this part of the series I will be discussing the following directories/partitions: /bin /boot /dev /etc /home.

## /home

I will start by discussing the partition that is most familiar to most new users, /home.  First you should know that Linux, unlike Windows, was originally designed to be a multi-user system.  Thus in the home directory you will find a set of directories, one for each user.  Every user (along with the system administrator) can access their directory by entering cd /home/[user name].  Each user’s home directory contains their own personal files in addition to their personal settings for programs.

## /bin

This directory contains programs that are able to be used by the system(Linux), the administrator and non-privileged users. Examples of such programs would include cp, mv, rm, and other such commands/programs. In addition to programs it also contains the shells, like bash, csh, sh, and so on. Just as a side note, you should be aware that there is also a /usr/bin which also contains programs that the system, administrator, and non-privileged users can use. However, unlike those in /bin, these programs are not essential-meaning that you can do without them and not have any real problems. Some programs that are located in my /usr/bin are: g++, apt-get, javac, whoami, and acroread. Sure it would be a pain not having these programs, but the system would still run perfectly fine.

## /boot

All of the system startup files and the kernel (vmlinuz) are located in this directory (also I would suggest reading the Wikipedia article on System.map, which is also stored in this directory). On Ubuntu, this is also where Grub (GRand Unified Boot loader) stored.  For those of you that are dual-booting here is something that might interest you.  When you start up your system you will normally see a list asking you which OS you want to enter.  This list normally contains the various Linux kernels along with Windows (or whatever OS you have on your computer).  If you would like to change the order these elements are presented along with other properties here is what you need to do.  cd /boot/grub then sudo gedit menu.lst (actually you can use whatever text editor you desire)  The file is pretty well documented so editing it is pretty straight forward.

## /dev

All computers have hardware, and this is where the information on all your hardware is stored. Once again let me reiterate that EVERYTHING is a file (or directory but I don’t distinguish between them in this case). If you list all of the files here, you should find sda, sda1, sda2… which represent the partitions of you master drive (instead of sda you might have hda depending on your drive type). Also you might see a files /dev/cdrom and /dev/fd or (/dev/fd0). These represent your CDROM and floppy drive (if you have them that is, because really who still has a floppy drive?). Here is something “cool” that you should all try (don’t worry it won’t damage your computer. I have done it on mine if that makes you feel any better). The file /dev/dsp represents your speakers (or whatever sound output device you have). So anything written to this file will be redirected to your speakers and played for you to hear. Thus if you run cat ~/funfile.java > /dev/dsp you will hear what funfile.java “sounds like”, assuming that you have a file called funfile.java in your home directory. Pretty cool hu?

## /etc

Finally, I will slightly discuss the /etc directory.  One overview that I read, described this directory as the Linux equivalent to the Control Panel in Windows.  Basically most of the important configuration files are located here.  There are a lot of important files here that have to do with system start up (one being /etc/rc.d which contains the startup scripts for the system). It is always a good idea to back up your system, but this file more than any other I would say should really be backed up. Doing so would save you a lot of headache later when you have to reconfigure your settings, because you reinstalled your system or somehow managed to lose your installation.

Well that’s all there is for part 2. Hope you will stick around for part 3.

## Linux File System: Part 1

September 5, 2009

You just moved over from Window and are now working with Ubuntu.  The only problem is that you have no idea how the file system is laid out.  In Windows you know that there are partitions D:\ (usually the recovery partition/drive) and C:\ (which acts like the main partition/drive).  Even further, these partitions are visible when you boot up your computer so you don’t have to worry about mounting them.

Now as for a Linux system, EVERYTHING IS A FILE!!! (and if it isn’t a file it’s a process).  Directories like /home (similar to C:\Users\[user name] in Windows) is just a special kind of file, that contains “pointers” do it descendants.  At this point I should mention that in Linux the file system is set up like a tree, with root node /.  Those of you that are familiar with working in DOS will have to get use to using / to navigate between directories and not \.  Really it’s not that hard to do, but does take some getting used to.  And if you are going to say “Why does Linux not adhere to the standard?” Just remember that Linux is based off of Unix which has been around much longer than Windows.  Additionally Windows doesn’t have a great track record when it comes to adhering to standards (IE for example).  Something else to keep in mind is that file names are case sensitive.  That means that THIS.txt is different from tHiS.txt or This.txt and even this.txt.  In Windows this isn’t the case (Thanks Kevin telling me this.  I always entered file names as if they were case sensitive when working with Windows.)

Remember earlier when I said that under Windows you don’t have to mount drives/partitions once you boot up the system?  Well under Linux you don’t have this convenience.  However, there are some advantages to this set up, so you shouldn’t cry too much.  For instance the /usr (the file that contains most of the system executables, I’ll talk about this more later) can be mounted from another computer on your network and everything will work just fine.  Just try moving the folder C:\WINDOWS to another location (have fun fixing your registry errors if you actually do this by the way).  The reason this will work under Linux is because it will still see /usr as a local directory that’s part of the local directory structure.

It is finally time to talk about the different parts of the Linux file system. To see what the directories under / are just go to that directory and enter  ls -p. The entries with a / after them are directories, everything else is just a regular file.
On my system the list of directories is:

 /bin /boot /dev /etc /home /initrd /lib /lib32 /lost+found /media /mnt /opt /proc /root /sbin /srv /sys /tmp /usr /var

The /lib32 directory seems to be special to 64-bit machines so I won’t be talking about it. However, I figure that it is similar to /lib, but provides support for 64-bit systems.

In part 2-and part 3, if it is needed, I will discuess each of these directories.  Nothing too detailed but it should provide you with a good starting point.

## Murder Murder Murder

September 5, 2009

You say kill just doesn’t do it for you. Have you tried killall? Oh well in that case I would suggest pkill.

Really pkill is very similar to kill and killall.  If you entered pkill firefox, it would find all processes related to firefox and do away with them right away.  The advantage of doing this over using the ps ux trick mentioned in this post, is that you don’t have to do the searching yourself.  And run the risk of missing a process.  As for an advantage over killall, pkill can be used with regular expressions.  Also, with killall you need to get the name exactly right.  Thus to kill the mozilla browser you would have to run killall mozilla-bin and not killall mozilla.

I personally have not found a need to use pkill as of yet, but you never know when it will come in handy.

## LaTex…it Just Looks Good

September 4, 2009

Well for those of you that don’t know what LaTex is-and I’m not talking about the “fabric”-I suggest you head over to Google and find out.

I’m not all too sure on how to install Tex from the command line, but if I had to guess I would say it is something like sudo apt-get install texlive.  TexLive is the package that gives you LaTex functionality.   I installed this a while back by System>Administration>Synaptic Package Manager then chose to install TexLive from the menu.

Now that you have all that you need (well enough to get started) just open up Gedit or some other text editor.  Let us call this file FIRST.tex and enter the following and save:

 \documentclass{article} \begin{document}
Hey check this out
$$\int_0^\infty\left(\frac{\sin x}{x}\right)^2dx=\frac{\pi}{2}$$ \end{document} 

Now to view your creation you just need to “compile” it to a PDF (or a dvi if you would rather do that).  This is done with the command pdflatex FIRST.tex then to view it you just open up a PDF viewer.  If you are using Adobe this can be accomplished with acroread FIRST.pdf .

Your file should look something like:

Hey check this out $\displaystyle\int_0^\infty\left(\frac{\sin x}{x}\right)^2dx=\frac{\pi}{2}$

Best of luck ‘Tex-ing’.

September 1, 2009

Well I have finally moved into my place and have discovered 2 things.

1: My desktop is dead…well at least to a point where a Linux Live CD won’t help.

2: My Data Structures & Algorithms class will be using Java 1.5

Well #2 is more of a annoyance than a real problem (I use Java 1.6).  As for #1 I was planning to use my desktop to try and update Ubuntu.  It used to run 8.10 before it died (I’m sure it’s just some simple hardware problem).  Well at least most of my stuff from there is backed up elsewhere.  Guess it pays off to be paranoid.  Besides it is probably a good idea to do that before even attempting to upgrade you system, no matter how fool proof the process is said to be.

As things are now I will either buy another desktop around January 1, 2010 or a new laptop around that same time.  Either way, I will be putting Ubuntu on it, hopefully a 32 bit version.  The only real pain I for see is getting the wireless card to work, but other than that everything I need to change I have previously documented the process for; either on this blog or another location.

Guess in my next post I’ll talk about one of my biggest peeves of working with a functional Ubuntu installation.  The default terminal size.