Examining Files from the Command Line

team bbl


To use the command line, open a terminal window. You see the home directory of the account you are using. To see a listing of the files in the directory, use the ls command, as follows:

 ls Desktop      Images       test.txt 

The output shown just lists the names. Some distributions output color-coded listings to show the type of files, such as blue for directories. Others show a forward slash (/) after the names of directories, as shown in the following output:

 ls Desktop/     Images/     test.txt 

To see more information about the files, use the options of the ls command. All the options are documented in the man page for ls, accessed by typing:

 man ls 

One useful option is -l to get a long listing, as follows:

 ls -l drwx------   3  janet  janet  4096  Oct   2  13:21  Desktop/ 

The first character is d for directory. A file would show a - for the first character. The next 9 characters are the permissions, as explained in the "File Permissions" section of this chapter. The first janet is the user owner. The second janet is the group owner. 4096 is the file size. Oct 2 at 13:21 is the date/time the file was last modified. Desktop is the filename.

You can use ls to list the contents of a directory by specifying its name, as follows:

 ls /home/robert Desktop     mysecretstuff 

Actually, you can only look at the contents of the robert directory if you have permission to do so. If you don't have permission, you see an error message such as:

 ls:  /home/robert:  Permission denied 

You can save the directory listing in a file, rather than display it to the screen, with the following command:

 ls > dir_listing 

The list of files is stored in a text file named dir_listing in the same format that it would be displayed on the screen. You can look at the file or print it.

The files and directories listed using the ls command don't include system files unless you use the -a option. On Linux, system files are named with a dot (.) as the first character, such as .bash_history, which contains a history of your commands. These files make your system behave properly. In general, it's best to leave these system files alone until you are fairly knowledgeable.

When you use the -a option, your file listing includes . and .., representing the current directory (.) and the directory above the current directory (..), also called the parent directory.

To move through the file system, use the cd command. The following are valid cd commands:

 cd /home/janet    (moves to /home/janet) cd ..             (moves up one directory) cd                (moves to your home directory) 

Most Linux distributions provide you with a prompt that displays which directory you are in. However, if you don't know which directory, you can always type:

 pwd 

It displays the path to the current directory.

If you provide ls or cd with a directory or filename that can't be found, you will see a message similar to the following:

 No such file or directory 

For instance, if you want to change to the directory /home/janet, you can type the following relative path if you are in the /home directory:

 cd janet 

However, if you are in a different directory, you will get the "No such file or directory" message.

    team bbl



    Spring Into Linux
    Spring Into Linux
    ISBN: 0131853546
    EAN: 2147483647
    Year: 2005
    Pages: 362
    Authors: Janet Valade

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net