Wednesday, December 31, 2008

Creating files and directories

As a Linux user, most of the files you save and work with will probably be in your home directory. Here are some of the commands you use in the file creation process:
· cd — Change to another current working directory
· pwd — Print the name of the current working directory
· mkdir — Create a directory
· chmod — Change the permission on a file or directory
· ls — List the contents of a directory
The following procedure steps you through creating directories within your home directory, moving among your directories, and setting appropriate file permissions:
1.First, go to your home directory. To do this, simply type cd.
2.To make sure that you got to your home directory, type pwd.
$ pwd
/home/chris
3.Create a new directory called test in your home directory, as follows:
$ mkdir test
4.Check the permissions of the directory by typing:
$ ls −ld test
drwxr−xr−x 2 chris sales 1024 Jan 24 12:17 test

Tuesday, December 30, 2008

Linux file system

Some of the Linux directories that may be of interest to you include the following:
· /bin — Contains common Linux user commands, such as ls, sort, date, and chmod.
· /dev — Contains files representing access points to devices on your systems. These include terminal devices (tty), floppy disks (fd), hard disks (hd), RAM (ram), and CD−ROM (cd).
· /etc — Contains administrative configuration files.
· /home — Contains directories assigned to each user with a login account.
· /mnt — Provides a location for mounting devices, such as remote file systems and removable media (with directory names of cdrom, floppy, and so on).
· /root — Represents the root user’s home directory.
· /sbin — Contains administrative commands and daemon processes.
· /tmp — Contains temporary files used by applications.
· /usr — Contains user documentation, games, graphical files (X11), libraries (lib), and a variety of other user and administrative commands and files.

Sunday, December 28, 2008

Configuring your shell

You can tune your shell to help you work more efficiently. Your prompt can provide pertinent information each time you press Enter. You can set aliases to save your keystrokes and permanently set environment variables to suit your needs. To make each change occur when you start a shell, you can add this information to your shell configuration files.
Several configuration files support how your shell behaves. Some of these files are executed for every user and every shell. Others are specific to the particular user that creates the configuration file. Here are the files that are of interest to anyone using the bash shell in Linux:
· /etc/profile — This file sets up user environment information for every user. It is executed when you first log in and the shell starts. This file provides default values for your path, your prompt, the maximum file size that you can create, and the default permissions for the files that you create. It also sets environment variables for such things as the location of your mailbox and the size of your history files.
· /etc/bashrc — This file is executed for every user that runs the bash shell. It is read each time a bash shell is opened. It sets the default prompt and may add one or more aliases. Values in this file can be overridden by information in each user’s ~/.bashrc file.
· ~/.bash_profile — This file is used by each user to enter information that is specific to their own use of the shell. It is executed only once, when the user logs in. By default it sets a few environment variables and executes the user’s .bashrc file.
· ~/.bashrc — This file contains the bash information that is specific to your bash shells. It is read when you log in and also each time you open a new bash shell. This is the best location to add environment variables and aliases so that your shell picks them up.
· ~/.bash_logout — This file executes each time you log out (exit the last bash shell). By default, it simply clears your screen.

Command line recall

After you type a command line, that entire command line is saved in your shell’s history list. The list is stored in a history file, from which any command can be recalled to run again. After it is recalled, you can modify the command line, as described earlier.
To view the contents of your history list, use the history command. You can either type the command without options or follow it with a number to list that number of the most recent commands. Here’s an example:
$ history 8
382 date
383 ls /usr/bin
384 man sort
A number precedes each command line in the list. There are several ways to run a command immediately from this list, including:
· Run Command Number (!n) — Replace the n with the number of the command line, and the command line indicated is run.
· Run Previous Command (!!) — Runs the previous command line.
· Run Command Containing String (!?string?) — Runs the most recent command that contains a particular string of characters.

Friday, December 26, 2008

Checking directories and permissions

Associated with each shell is a location in the Linux file system known as the current or working directory. As previously mentioned, each user has a directory that is identified as the user’s home directory.
When you first log in to Linux, you begin with your home directory as the current directory. When you request to open or save a file, your shell uses the current directory as the point of reference.
Simply give a filename when you save a file and it will be placed in the current directory. Alternatively, you can identify a file by its relation to the current directory (relative path). Or you can ignore the current directory and identify a file by the full directory hierarchy that locates it (absolute path).
To find out what your current directory is, type the pwd command:
$ pwd
/usr/bin
At this point, list the contents of your home directory, using the ls command. Either you can type the full path to your home directory to list its contents, or you can use the ls command without a directory name to list the contents of the current directory. Using the −a option to ls enables you to view the hidden files (dot files) as well as other files. With the −l option, you can see a long, detailed list of information on each file.
$ ls −la /home/nitin
You can get the total files in home directory of user 'nitin', with the read/write permissions associated with the file.