The Linux Shell ~ Pt. 13: “Syncing” with The ln Command

Links (not the browser)

In UNIX-based systems, files have two parts: the filename part, and the data part. The data part has an affiliation with something called an inode, which contains the file’s data, permissions, etc. The filename part contains a name and the unique ID number of the inode. Two different links can be created to manipulate the data part, hard and soft. Hard links are like indicators that two or more files must be “synced”, or kept the same, no matter which one is modified. To create a link, we use the ln command.

ln

ln can create links to file’s data parts. Let’s try it out. Type these commands:

echo Hai! > dummy.txt
ls -lia
ln dummy.txt dummy-copy.txt
cat dummy-copy.txt
echo Bai! > dummy.txt
cat dummy-copy.txt

I’ll explain each step.
1. The echo command is told to write Hai! into a file called dummy.txt. The > parameter tells echo to write this into the file.
2. The ls command lists the files. The -lia parameter tells ls to show all files, to show their inode IDs, and to show their permissions.
3. ln without any parameters will create a hard link between dummy.txt and dummy-copy.txt, which was created by ln.
4. The cat program outputs the contents of dummy-copy.txt. Notice how they’re the same as dummy.txt’s.
5. echo writes Bai! into the first file, dummy.txt.
6. cat will show the contents of dummy-copy.txt again. They’re different!

This can be very useful. Maybe not now, but eventually it will be of good service.

Symlinks

Symlinks, or soft links, are a bit different from hard links. If a file is created with a soft link to another, if the parent file is deleted, the other disappears, whereas the hardlinked copy would have remained. Try this:

ln -s dummy-copy.txt softlink-dummy.txt
cat softlink-dummy.txt
ls -lia
rm dummy-copy.txt
ls -lia

1. This time, the -s parameter tells ln that you want to make a symlink with a new file, softlink-dummy.txt.
2. cat shows the contents of the softlinked copy.
3. ls -lia shows all files with their inode number, permissions, etc.
4. rm deletes the original file.
5. ls shows all of the files and folders. Notice how both the symlinked copy and the original are gone.

A symlinked copy will also have different permissions and a different inode number.
Links are used in all different things, including LFS and advanced projects like such. These links are also useful for keeping up to date backups. Try and see what you can do with these links.

Next chapter: Your Own Packages

The Linux Shell ~ Pt. 12: Cygwin

Cygwin

If you are like me (have parents with strong Linux bias) and you are forced to use Windows everyday, you must have constant migraines from the blue screens and registry errors. Well, fear no more, for the kingdom of Linuxia has invaded Windows-upon-Microsoft. Say hello to Cygwin.

What’s Cygwin?

Cygwin is a program available for Windows that allows you to use the Linux terminal (and even some GUI applications) in Windows. This is very useful and easy to install. Simply download setup.exe from the Cygwin website and download all of the packages that you want. setup.exe will act as a package manager. For a beginning system, just install the packages you want for now. You don’t need to sift through all of them, but I strongly suggest installing all of the libraries.

Starting Cygwin

To start Cygwin, just go to the Start menu, click All Programs, and find Cygwin. Run the terminal. From here, you can use make, FIGlet, ninvaders, mkdir, and all of the other commands (except fdisk and cfdisk).

Where To Go From Here

Do whatever you want with Cygwin. Play games, mess with configs, browse the web, anything you want. Cygwin allows even Windows users to see how wonderful Linux can be.

Next chapter: ln

The Linux Shell ~ Pt. 11: cfdisk

cfdisk

A hard disk doesn’t just smoosh every file into one big space. To make things safe and keep everything organized, the hard disk is separated into partitions. Partitions are sections of the hard drive that are labeled and given a file system. A file system is a system that controls the storage and retrieval of files from the hard disk. It comes in many variants. For example, the NTFS filesystem is used for Windows. Linux, on the other hand, has many different file systems. The ext series, ReiserFS, swap, and many more are available for Linux. But how can we manipulate partitions? Is it just left to the operating system to choose? With Windows, but not with Linux.

cfdisk

cfdisk is a terminal program that allows you to resize, name, change the file system of, or create partitions, and even more. Its less user-friendly sister, fdisk, is available as well, but cfdisk is better to begin with.

cfdisk is probably not installed already, so you can use your package manager or build it from the tarball (.tar file). After installing, type “cfdisk” to start. Use the Up and Down keys to choose partitions to manipulate. Select Free Space to create partitions. Try it now. Create a partition with the ext4 filesystem. Don’t worry, this won’t harm your computer. After this is done, the main menu will show you that your partition is created. This is all the help necessary for this program, so play around with it for a while. I suggest doing this with virtualisation, where a computer runs inside of yours. You may say it’s a strange concept to understand, but it really isn’t. All the virtualisation software does is create a virtual computer and run the operating system in it. Virtualisation software includes the likes of VirtualBox and VMware. These are relatively easy to use, but on Windows they have many issues.

Next chapter: Windows Sucks

The Linux Shell ~ Pt. 10: make and Packages

Packages

Packages are files that contain software or libraries that can be installed. Normally, you can install packages through a package manager, where you can search for, install, and uninstall them. With a package manager, the packages are built for you. What this means is that packages contain pieces, or code, that need to be put together into software and installed. If a package is not in your package manager’s repositories (servers that store packages for retrieval), then you have to download and build the package yourself. This is done with the make tool.

make

make uses something called a makefile inside of the packages to coordinate the tools used for building. The makefile tells make what to use to build this or combine this with that. make is basically the backbone of Linux. It is how Linux lets you play ninvaders. Without make, Linux != software (programming joke).

Hands-On

Let’s try building and installing an example program. Download the nano source tarball (here) and extract it with the command “tar -xvf nano-2.2.6.tar.gz”. From here, go into the folder nano-2.2.6. There, read the readme file and follow its instructions. If they aren’t clear enough, type these commands:

./configure
make
make install

This will:
A: Run the configure program included with the package that creates a makefile that is tailored to your system’s needs and requirements.
B: Build nano.
C: Install nano.

Simple enough. Try some other packages, like vi or yes. Just don’t run yes!

Next chapter: Partitioning

The Linux Shell ~ Pt. 9: Commanding After Hours

Midnight Commander

By now, you might be wishing that there was an easier way to explore and manipulate directories than ls and mkdir. Well, there is. Midnight Commander is a file browser that you can use from the shell to browse directories and edit files. It even has mouse support! Midnight Commander may or may not be already installed on your Linux system. To check, type “mc”. This should start Midnight Commander.
Midnight Commander uses ncurses, just as ninvaders does. It just takes advantage of ncurses’s strength. ncurses is a very powerful library, and is used for hundreds of programs. If you haven’t already, it’s a good idea to download it as a package (more on these next chapter).

Next chapter: Packages and make