Some of the Basics of Working with Linux

As you start to learn your way around Linux, you will need some level of competence with its interface, with navigating its directories and files, and with Linux commands. These commands have a common form, which you’ll learn to recognize. And you’ll see how various Linux features are roughly comparable to elements you may know from Windows or other systems you already know.

A Look at the Interface

One of the biggest misconceptions about Linux is that you can operate it only from the command line. This is simply not true. You can operate Linux through any one of several available GUIs. In the Windows world, both options are available as well, but most people use the GUI and rarely think about the command-line interface—the way of working with a computer that involves entering text commands rather than clicking on icons. In the Linux world, it is not uncommon to use both. Some advanced users don’t use the GUI at all, and in many cases, the command line is the only way to carry out more advanced operations. But that does not mean the command line is your only option. And Linux has introduced more advanced and usable interfaces as it has become more popular and widely adopted.

Basic Linux Navigation

One of the biggest differences you will notice in the Linux OS if you are used to Windows is the difference in how drives and files are referenced. Windows uses drive letters, but in Linux, drives and partitions are referenced by using paths and filenames. These filenames generally follow this format:

In Linux, disk drives are devices that are referenced under the /dev directory. Each physical disk drive has a separate subdirectory that Linux uses to refer to the device driver that provides the actual interface to the physical disk drive. The hda1 subdirectory generally refers to the first physical disk drive connected to a Serial Advanced Technology Attachment (SATA) interface. After that, further subdirectories simply refer to the directory structure stored on the device. Another difference that exists between Windows and Linux is how directories are annotated. In Windows, directories are referenced with the familiar , but in Linux the directories are referenced with /. If anything is going to cause you grief as a Windows user moving to Linux, this is probably it. In Linux, the backslash, , is actually a special character, not a directory separator.

Important Linux Directories

When navigating the many different directories in the Linux file system, you will need to have a good knowledge of the different directories and what they provide you as a user. TABLE 12-1 lists some of the most common directories in the Linux file system. Awareness of these default directories allows administrators to monitor known expected files and directories and detect rogue files that have been either accidentally placed in sensitive directories or maliciously planted to trap unsuspecting system users.

TABLE 12-1 Some of the vital directories in the Linux filesystem.

DIRECTORY PURPOSE
/ This represents the “root,” or the most basic part of the file system. This is similar in some respects to the location C: in Windows.
/bin All executables in this directory are accessible and usable by all system users. This can be considered to be more or less like the Windows folder in the Windows OS.
/boot This contains all the files required to start up and boot a Linux OS.
/dev This is where the files that dictate the access between hardware and the OS reside. These files can be thought of as device drivers and similar related files.
/etc Files that store configuration information for applications are located in this folder. Applications can also store some configuration information in their own directories.
/home This location is where the users will store their information by default. Typically, their information is stored in special subdirectories underneath this folder.
/lib Library files (mostly C programming language object files) can be found here. Libraries are shared code that is incorporated into an application later on demand. Applications and the OS store their library files in this location by default.
/mnt Certain temporary file systems (floppies, CD/DVD, network file systems) are normally placed here when a device is activated. For example, when you place a CD or DVD into the optical drive, the OS may mount (connect to) the CD/DVD file system and display the directories and files under /mnt/cdrom or /mnt/dvd.
/opt This directory is used at the administrator’s discretion (optional), but it is typically used for third-party software.
/proc This directory contains vital information about running processes on the Linux system.
/root The home directory of the root user is contained in this special directory, away from normal users.
/sbin The system binaries directory contains executables that are used by the OS and the administrators but typically not by normal users.
/tmp This is a temporary directory for general use by any user.
/usr This is a generic directory that contains the body of useful folders and files for use by Linux users, such as executables and documentation.
/var This important directory contains system variables, such as print and mail spoolers, log files, and process IDs.

Commonly Used Commands

Because of the many tasks that can be performed at a command line or terminal window, it is vital for you to understand terminal windows and the frequently used commands. This will require using your knowledge of filenames, directory names, and commands that are case sensitive. When at the Linux command line, you will see a command prompt similar to what is shown here:

This command prompt indicates the user account logged in (in this case root) and the computer name (in this case impa) along with the current directory (in this case /). The # symbol at the prompt indicates that the user account holds privileges, whereas a prompt followed by the $ will indicate a user account with standard user privileges.

The Basic Command Structure of Linux

Linux commands share a common form, which is the following:

This lets you identify the command you want Linux to execute. Keep the following points in mind:

  • The name of a command generally consists of lowercase letters and digits.

  • Options modify the way that a command works. For example, the -a option of the ls command generates the output of the command to list “hidden” files as well as normal files.

This command

and this command

both list hidden files, but use different output formats.

The next detail in commands is something known as the arguments. They are used to specify filenames or other targets that fine-tune the action of the command. For example, the ls command lets you specify a directory as an argument, which causes the command to list files in that particular directory:

TABLE 12-2 lists a small number of the commands in Linux, but you should become comfortable with all of them, including their functions.

TABLE 12-2 Linux commands.

COMMAND PURPOSE
ls This command, known as the list command, is similar to the dir command in Windows, with very similar options. The ls command is used to display all the files and subdirectories in a given location.
pwd This command is the same as the Windows cd command with no arguments. The pwd, or print working directory, command is used to display the current location of the user within the Linux directory structure. This command is very useful, especially for newbies, who can get lost in the Linux file system quickly.
cd

The cd, or change directory, command is used to switch between locations in Linux. This command is essentially identical in operation to the Windows version. The main difference is the way directories are referenced (remember the slashes).

Important shorthand notations include:

  • / Root of the file system

  • ./ Current directory

  • ../ Parent directory (the directory above)

  • ~ Home directory

The format is:

cd <location name>

mkdir

The make directory, or mkdir, command is used to create new directories in Linux. The format is:

mkdir <new directory name>

rmdir

Remove directory, or rmdir, is a command that is used to remove or delete empty directories from the Linux file system. Note that the directory in question must be empty. Otherwise, the command will simply not work. The format is:

rmdir <directory name>

rm

This is a more aggressive removal command that removes files and folders. The difference between this command and the rmdir command is that this command will remove a directory that is not empty. When using this command on directories, exercise caution. The format is:

rm <directory name>

cp

This is a command used to copy files from location to location, much like the copy commands in other OSs. The format is:

cp <original location> <new location>

mv

The mv command is used to move files from one location to another location. The format is:

mv <original location> <new location>

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.15.171.202