Tuesday 22 January 2013

Linux Commands For Directory Handling


In Linux there are a few commands that work for both files and directories (such as the cp command),and some that only work for directories. To create a new directory, you’ll need to use a specific command, which I’ll discuss here. Removing directories can get interesting, so we’ll look at that as well as.
Creating/Making directories
There’s not much to creating a new directory in Linux, just use the mkdir command:
$ mkdir dir3
$ ls -il
total 16
1954886                  drwxr-xr-x             2              rich rich         4096        Sep 1 09:42           dir1/
1954889                 drwxr-xr-x              2             rich rich          4096        Sep 1 10:55            dir2/
1954893                 drwxr-xr-x              2              rich rich         4096        Sep 1 11:01            dir3/
1954888                  -rw-r--r--                1             rich rich        0              Dec 25 2008           test3
1954793                  -rw-r--r--                1              rich rich        6             Sep 1 09:51            test4
$
The system creates a new directory and assigns it a new inode number.
Deleting/Removing directories
Removing directories can be tricky, but there’s a reason for that. There are lots of opportunity        for bad things to happen when you start deleting directories. The bash shell tries to protect us from accidental catastrophes as much as possible. The basic command for removing a directory
is rmdir:
$ rmdir dir3
$ rmdir dir1
rmdir: dir1: Directory not empty
$
By default, the rmdir command only works for removing empty directories. Since there is a file in the dir1 directory, the rmdir command refuses to remove it. You can remove nonempty directories using the --ignore-fail-on-non-empty parameter.
Our friend the rm command can also help us out some when handling directories. If you try using it with not parameters, as with files, you’ll be somewhat disappointed:
$ rm dir1
rm: dir1: is a directory
$
However, if you really want to remove a directory, you can use the -r parameter to recursively remove the files in the directory, then the directory itself:
$ rm -r dir2
rm: descend into directory `dir2’? y
rm: remove `dir2/test1’? y
rm: remove `dir2/test3’? y
rm: remove `dir2/test4’? y
rm: remove directory `dir2’? y
$
While this works, it’s somewhat awkward. Notice that you still must verify every file that gets removed. For a directory with lots of files and subdirectories, this can become tedious. The ultimate solution for throwing caution to the wind and removing an entire directory, contents and all, is the rm command with both the -r and -f parameters:
$ rm -rf dir2
$
That’s it. No warnings, no fanfare, just another shell prompt. This, of course, is an extremely dangerous tool to have, especially if you’re logged in as the root user account. Use it sparingly, and only after triple checking to make sure that you’re doing exactly what you want to do.

Monday 21 January 2013

Linux File Handling Commands


The bash shell provides lots of commands for manipulating files on the Linux file system. Here  basic commands you will need to work with files from the CLI for all your file-handling needs.
Creating files
Every once in a while you will run into a situation where you need to create an empty file. Sometimes applications expect a log file to be present before they can write to it. In these situations, you can use the touch command to easily create an empty file:
$ touch test1
$ ls -il test1
1954793    -rw-r--r--   1     rich rich   0    Sep 1 09:35    test1
$
The touch command creates the new file you specify, and assigns your username as the file owner. Since I used the -il parameters for the ls command, the first entry in the listing shows the inode number assigned to the file. Every file on the Linux system has a unique inode number.
Notice that the file size is zero, since the touch command just created an empty file. The touch command can also be used to change the access and modification times on an existing file without changing the file contents:
$ touch test1
$ ls -l test1
-rw-r--r--                 1              rich rich   0             Sep 1 09:37             test1
$
The modification time of test1 is now updated from the original time. If you want to change only the access time, use the -a parameter. To change only the modification time, use the –m parameter. By default touch uses the current time. You can specify the time by using the –t parameter with a specific timestamp:
$ touch -t 200812251200 test1
$ ls -l test1
-rw-r--r--                 1 rich rich                0              Dec         25 2008  test1
$
Now the modification time for the file is set to a date significantly in the future from the current time.
Copying files
Copying files and directories from one location in the filesystem to another is a common practice for system administrators. The cp command provides this feature. In it’s most basic form, the cp command uses two parameters: the source object and the destination
object:
cp source destination
When both the source and destination parameters are filenames, the cp command copies the source file to a new file with the filename specified as the destination. The new file acts like a brand new file, with an updated file creation and last modified times:
$ cp test1 test2
$ ls -il
total 0
1954793   -rw-r--r--  1 rich rich  0  Dec 25 2008  test1
1954794   -rw-r--r--  1 rich rich  0  Sep 1 09:39  test2
$
The new file test2 shows a different inode number, indicating that it’s a completely new file. You’ll also notice that the modification time for the test2 file shows the time that it was created. If the destination file already exists, the cp command will prompt you to answer whether or not you want to overwrite it:
$ cp test1 test2
cp: overwrite `test2’? y
$
If you don’t answer y, the file copy will not proceed. You can also copy a file to an existing directory:
$ cp test1 dir1
$ ls -il dir1
total 0
1954887  -rw-r--r--  1  rich rich  0  Sep 6 09:42  test1
$
The new file is now under the dir1 directory, using the same filename as the original. These examples all used relative pathnames, but you can just as easily use the absolute pathname for both the source and destination objects.
To copy a file to the current directory you’re in, you can use the dot symbol:
$ cp /home/rich/dir1/test1 .
cp: overwrite `./test1’?
As with most commands, the cp command has a few command line parameters to help you out. Use the -p parameter to preserve the file access or modification times of the original file for the copied file.
$ cp -p test1 test3
$ ls -il
total 4
1954886                   drwxr-xr-x              2               rich rich  4096   Sep 1 09:42      dir1/
1954793                  -rw-r--r--                  1             rich rich   0        Dec 25 2008      test1
1954794                  -rw-r--r--                 1               rich rich   0        Sep 1 09:39      test2
1954888                  -rw-r--r--                 1              rich rich    0        Dec 25 2008     test3
$
Now, even though the test3 file is a completely new file, it has the same timestamps as the original test1 file.
The -R parameter is extremely powerful. It allows you to recursively copy the contents of an entire directory in one command:
$ cp -R dir1 dir2
$ ls -l
total 8
drwxr-xr-x               2 rich rich                4096     Sep 6 09:42                                dir1/
drwxr-xr-x               2 rich rich                4096     Sep 6 09:45                                dir2/
-rw-r--r--                                  1 rich rich                 0          Dec 25 2008              test1
-rw-r--r--                  1 rich rich                 0          Sep 6 09:39               test2
-rw-r--r--                  1 rich rich                 0          Dec 25 2008              test3
$
Now dir2 is a complete copy of dir1. You can also use wildcard characters in your cp commands:
$ cp -f test* dir2
$ ls -al dir2
total 12
drwxr-xr-x   2 rich rich 4096   Sep 6 10:55   ./
drwxr-xr-x   4 rich rich 4096   Sep 6 10:46   ../
-rw-r--r--      1 rich rich  0        Dec 25 2008  test1
-rw-r--r--      1 rich rich  0        Sep 6 10:55  test2
-rw-r--r--      1 rich rich  0        Dec 25 2008  test3
The cp Command Parameters
Parameter Description
-a           Archive files by preserving their attributes.
-b           Create a backup of each existing destination file instead of overwriting it.
-d           Preserve.
-f            Force the overwriting of existing destination files without prompting.
-i            Prompt before overwriting destination files.
-l            Create a file link instead of copying the files.
-p           Preserve file attributes if possible.
-r            Copy files recursively.
-R          Copy directories recursively.
-s           Create a symbolic link instead of copying the file.
-S          Override the backup feature.
-u          Copy the source file only if it has a newer date and time than the destination (update).
-v          Verbose mode, explaining what’s happening.
-x          Restrict the copy to the current filestytem.
Linking files
You may have noticed a couple of the parameters for the cp command referred to linking files. This is a pretty cool option available in the Linux filesystems. If you need to maintain two (or more) copies of the same file on the system, instead of having separate physical copies, you can use one physical copy and multiple virtual copies, called links. A link is a placeholder in a directory that points to the real location of the file. There are two different types of file links in Linux:
A symbolic, or soft, link
A hard link
The hard link creates a separate file that contains information about the original file and where to locate it. When you reference the hard link file, it’s just as if you’re referencing the original file:
$ cp -l test1 test4
$ ls -il
total 16
1954886      drwxr-xr-x            2 rich rich 4096   Sep 1 09:42  dir1/
1954889     drwxr-xr-x              2 rich rich 4096  Sep 1 09:45  dir2/
1954793     rw-r--r--                  2 rich rich       0  Sep 1 09:51  test1
1954794    -rw-r--r--                 1 rich rich       0  Sep 1 09:39  test2
1954888    -rw-r--r--                 1 rich rich       0  Dec 25 2008  test3
1954793    -rw-r--r--                2 rich rich        0  Sep 1 09:51  test4
$
The -l parameter created a hard link for the test1 file called test4. When I performed the file listing, you can see that the inode number of both the test1 and test4 files are the same, indicating that, in reality, they are both the same file. Also notice that the link count (the third item in the listing) now shows that both files have two links. On the other hand, the -s parameter creates a symbolic, or soft, link:
$ cp -s test1 test5
$ ls -il test*
total 16
1954793       -rw-r--r--         2 rich rich 6 Sep 1 09:51  test1
1954794       -rw-r--r--         1 rich rich 0 Sep 1 09:39  test2
1954888       -rw-r--r--         1 rich rich 0 Dec 25 2008  test3
1954793       -rw-r--r--         2 rich rich 6 Sep 1 09:51  test4
1954891        lrwxrwxrwx   1 rich rich 5 Sep 1 09:56  test5 -> test1
$
There are a couple of things to notice in the file listing, First, you’ll notice that the new test5 file has a different inode number than the test1 file, indicating that the Linux system treats it as a separate file. Second, the file size is different. A linked file needs to store only information about the source file, not the actual data in the file. The filename area of the listing shows the relationship between the two files.
Be careful when copying linked files. If you use the cp command to copy a file that’s linked to another source file, all you’re doing is making another copy of the source file. This can quickly get confusing. Instead of copying the linked file, you can create another link to the original file. You can have many links to the same file with no problems. However, you also don’t want to create soft links to other soft-linked files. This creates a chain of links that can not only be confusing
but also be easily broken, causing all sorts of problems.

Renaming files
In the Linux world, renaming files is called moving. The mv command is available to move both files and directories to another location:
$ mv test2 test6
$ ls -il test*
1954793           -rw-r--r--         2    rich rich 6  Sep 1 09:51   test1
1954888           -rw-r--r--        1   rich rich 0  Dec 25 2008   test3
1954793           -rw-r--r--         2   rich rich 6  Sep 1 09:51   test4
1954891           lrwxrwxrwx    1 rich rich 5  Sep 1 09:56   test5 -> test1
1954794           -rw-r--r--         1   rich rich 0  Sep 1 09:39   test6
$
Notice that moving the file changed the filename but kept the same inode number and the timestamp value. Moving a file with soft links is a problem:
$ mv test1 test8
$ ls -il test*
total 16
1954888    -rw-r--r--                                 1   rich rich            0   Dec 25 2008   test3
1954793    -rw-r--r--                               2   rich rich             6   Sep 1 09:51    test4
1954891    lrwxrwxrwx           1 rich rich                                5   Sep 1 09:56    test5 -> test1
1954794   -rw-r--r--                1    rich rich             0   Sep 1 09:39   test6
1954793    -rw-r--r--                                2    rich rich            6   Sep 1 09:51   test8
[rich@test2 clsc]$ mv test8 test1
The test4 file that uses a hard link still uses the same inode number, which is perfectly fine. However, the test5 file now points to an invalid file, and it is no longer a valid link. You can also use the mv command to move directories:
$ mv dir2 dir4
The entire contents of the directory are unchanged. The only thing that changes is the name of the directory.
Deleting files
Most likely at some point in your Linux career you’ll want to be able to delete existing files.Whether it’s to clean up a filesystem or to remove a software package, there’s always opportunities to delete files.
In the Linux world, deleting is called removing. The command to remove files in the bash shell is rm. The basic form of the rm command is pretty simple:
$ rm -i test2
rm: remove `test2’? y
$ ls -l
total 16
drwxr-xr-x               2 rich rich 4096   Sep 1 09:42   dir1/
drwxr-xr-x               2 rich rich 4096   Sep 1 09:45   dir2/
-rw-r--r--                                 2 rich rich 6   Sep 1 09:51   test1
-rw-r--r--                 1 rich rich 0   Dec 25 2008  test3
-rw-r--r--                 2 rich rich 6   Sep 1 09:51   test4
lrwxrwxrwx             1 rich rich 5 Sep 1 09:56 test5 -> test1
$
Notice that the command prompts you to make sure that you’re serious about removing the file. There’s no trashcan in the bash shell. Once you remove a file it’s gone forever. Now, here’s an interesting tidbit about deleting a file that has links to it:
$ rm test1
$ ls -l
total 12
drwxr-xr-x               2 rich rich 4096   Sep 1 09:42 dir1/
drwxr-xr-x                2 rich rich 4096   Sep 1 09:45 dir2/
-rw-r--r--                 1 rich rich 0        Dec 25 2008 test3
-rw-r--r--                 1 rich rich 6         Sep 1 09:51 test4
lrwxrwxrwx             1 rich rich 5          Sep 1 09:56 test5 -> test1
$ cat test4
hello
$ cat test5
cat: test5: No such file or directory
$
I removed the test1 file, which had both a hard link with the test4 file and a soft link with the test5 file. Noticed what happened. Both of the linked files still appear, even though the test1 file is now gone (although on my color terminal the test5 filename now appears in red). When I look at the contents of the test4 file that was a hard link, it still shows the contents of the file. When I look at the contents of the test5 file that was a soft link, bash indicates that it doesn’t
exist any more. Remember that the hard link file uses the same inode number as the original file. The hard link
file maintains that inode number until you remove the last linked file, preserving the data! All the soft link file knows is that the underlying file is now gone, so it has nothing to point to. This is an important feature to remember when working with linked files. One other feature of the rm command, if you’re removing lots of files and don’t want to be bothered
with the prompt, is to use the -f parameter to force the removal. Just be careful!

Thursday 17 January 2013

Ubuntu for Android Devices


Ubuntu desktop for docked Android phones
Ubuntu for Android provides a full desktop experience, including office software, web browsing, email and media applications, on Android phones docked to a screen and keyboard. Thanks to tight integration with the Android service layer, the transition between the two environments is seamless, making it easy to access the phone's services from the desktop when docked.

Secure access full-featured web

Sit back and enjoy a full desktop browser for multi-tab, multi-window web productivity. Ubuntu supports both Chromium and Firefox, the world's fastest browsers, and is naturally resistant to web malware, which is why enterprises and governments are adopting Ubuntu on desktops.
Surf on the move with the Android browser, then dock to continue your session on the desktop. You get the same web pages, the same bookmarks and the same browsing history, with all the real-estate of a desktop. Using web applications with a full keyboard and mouse is so much better than a tablet when you're at a desk, even in a hotel. 

Unified contacts

Both Ubuntu and Android access the same mobile address book. So even when the phone is docked, you can view, edit, call, text or email a contact. You can even check their profiles on Facebook or Twitter. 

Messaging and calls

Read and reply to incoming SMS messages from the desktop, using Ubuntu's message indicator. You can also make and receive calls via the desktop - and you'll be alerted to voicemails so you can manage them while you work.

 integrated settings

Alarm clock settings on the phone can be synchronised to alert you when working in the Ubuntu environment. You'll have one place to enter wifi passwords and one place to pair your bluetooth headset, then everything just works.

Social networking 

All your Android social network account credentials are synchronised seamlessly, using the Ubuntu social networking client to provide easy access to your online communities.

Hardware specifications

Ubuntu for Android requires minimal custom hardware enablement, allowing fast and cost-efficient core integration. It requires a core based on Android 2.3 (Gingerbread) or any subsequent version.
Ubuntu and Android share the same kernel. When docked, the Ubuntu OS boots and runs concurrently with Android. This allows both mobile and desktop functionality to co-exist in different runtimes.
Shared services and applications are delivered using a Convergence API module which ensures the tight integration between desktop and mobile environments. Work is balanced across the cores of the phone. When the handset is not docked, both CPU cores transfer their full power to Android.
For more information please visit


Linux Commands For File and Directory Listing



The most basic feature of the shell is the ability to see what files are available on the system. The
list command (ls) is the tool that helps do that. Here we briefly describe ls command, and all
of the options available to format the information it can provide.

Basic listing

The ls command at its most basic form displays the files and directories located in your current
directory:
$ ls
           4rich Desktop Download Music Pictures store store.zip test
           backup Documents Drivers myprog Public store.sql Templates Videos
$
Notice that the ls command produces the listing in alphabetical order (in columns rather than
rows). If you’re using a terminal emulator that supports color, the ls command may also show
different types of entries in different colors. The LS COLORS environment variable controls this
feature. Different Linux distributions set this environment variable depending on the capabilities
of the terminal emulator.
If you don’t have a color terminal emulator, you can use the -F parameter with the ls command
to easily distinguish files from directories. Using the -F parameter produces the following output:
$ ls -F
        4rich/  Documents/  Music/  Public/    store.zip Videos/
        backup.zip Download/  myprog* store/    Templates/
        Desktop/    Drivers/    Pictures/ store.sql test
$
The -F parameter now flags the directories with a forward slash, to help identify them in the
listing. Similarly, it flags executable files  with an asterisk, to help you find the files that can be run on the system easier.
The basic ls command can be somewhat misleading. It shows the files and directories contained
in the current directory, but not necessarily all of them. Linux often uses hidden files to store
configuration information. In Linux, hidden files are files with filenames that start with a period.
These files don’t appear in the default ls listing (thus they are called hidden).
To display hidden files along with normal files and directories, use the -a parameter.
 In a home directory for a user who has logged in to the system
from a graphical desktop, you’ll see lots of hidden configuration files. This particular example
is from a user logged in to a GNOME desktop session. Also notice that there are three files that
begin with .bash. These files are hidden files that are used by the bash shell environment.
The -R parameter is another command ls parameter to use. It shows files that are contained
within directories in the current directory. If you have lots of directories, this can be quite a long
listing.

Modifying the information presented

As you can see in the basic listings, the ls command doesn’t produce a whole lot of information
about each file. For listing additional information, another popular parameter is -l. The
-l parameter produces a long listing format, providing more information about each file in the
directory:
$ ls -l
total 2064
drwxrwxr-x  2      rich rich        4096      2007-08-24   22:04          4rich
-rw-r--r--    1      rich rich      766205    2007-08-24   15:34          backup.zip
drwxr-xr-x   3        rich rich         4096     2007-08-31   22:24        Desktop
drwxr-xr-x   2        rich rich         4096     2001-11-01   04:06        Documents
drwxr-xr-x    2       rich rich         4096     2001-11-01   04:06        Download
drwxrwxr-x   2       rich rich         4096     2007-07-26   18:25        Drivers
drwxr-xr-x    2        rich rich         4096    2001-11-01    04:06       Music
-rwxr--r--     1        rich rich        30         2007-08-23     21:42      myprog
drwxr-xr-x    2        rich rich        4096     2001-11-01     04:06      Pictures
drwxr-xr-x    2        rich rich        4096     2001-11-01    04:06       Public
drwxrwxr-x   5       rich rich         4096    2007-08-24     22:04       store
-rw-rw-r--    1       rich rich       98772     2007-08-24    15:30       store.sql
-rw-r--r--     1       rich rich      107507     2007-08-13   15:45       store.zip
drwxr-xr-x    2       rich rich        4096       2001-11-01   04:06      Templates
drwxr-xr-x    2       rich rich        4096       2001-11-01    04:06     Videos
[rich@testbox ~]$

The long listing format lists each file and directory contained in the directory on a single line.
Besides the filename, it shows additional useful information. The first line in the output shows
the total number of blocks contained within the directory. Following that, each line contains the
following information about each file (or directory):
■ The file type (such as directory (d), file (-), character device (c), or block device (b)
■ The permissions for the file
■ The number of hard links to the file
■ The username of the owner of the file
■ The group name of the group the file belongs to
■ The size of the file in bytes
■ The time the file was modified last
■ The file or directory name
The -l parameter is a powerful tool to have. Armed with this information you can see just about
any information you need to for any file or directory on the system.

The complete parameter list

There are lots of parameters for the ls command that can come in handy as you do file management.
If you use the man command for ls, you’ll see several pages of available parameters for you
to use to modify the output of the ls command.
The ls command uses two types of command line parameters:
■ Single-letter parameters
■ Full-word (long) parameters
The single-letter parameters are always preceded by a single dash. Full-word parameters are more
descriptive and are preceded by a double dash. Many parameters have both a single-letter and
full-word version, while some have only one type.
You can use more than one parameter at a time if you want to. The double dash parameters must
be listed separately, but the single dash parameters can be combined together into a string behind
the dash. A common combination to use is the -a parameter to list all files, the -i parameter to
list the inode for each file, the -l parameter to produce a long listing, and the -s parameter to
list the block size of the files. The inode of a file or directory is a unique identification number
the kernel assigns to each object in the filesystem. Combining all of these parameters creates the
easy-to-remember -sail parameter:
$ ls -sail
total 2360
301860           8   drwx------ 36      rich rich     4096    2007-09-03          15:12 .
65473             8   drwxr-xr-x    6       root root    4096   2007-07-29           14:20 ..
360621           8   drwxrwxr-x   2       rich rich     4096    2007-08-24           22:04     4rich
301862           8   -rw-r--r--      1       rich rich      124    2007-02-12           10:18 .bashrc
361443           8     drwxrwxr-x  4       rich rich    4096     2007-07-26          20:31 .ccache
301879           8      drwxr-xr-x  3        rich rich   4096     2007-07-26          18:25 .config
301871           8  drwxr-xr-x       3        rich rich    4096      2007-08-31         22:24 Desktop
301870           8  -rw-------        1       rich rich                   26 2001-11-01    04:06 .dmrc
301872            8 drwxr-xr-x      2      rich rich     4096   2001-11-01            04:06  Download
360207        8 d   rwxrwxr-x      2      rich rich     4096   2007-07-26            18:25 Drivers
301882        8     drwx------      5      rich rich      4096   2007-09-02            23:40 .gconf
301883        8 drwx------         2       rich rich      4096    2007-09-02           23:43 .gconfd
360338        8 drwx------         3       rich rich      4096    2007-08-06           23:06 .gftp

SingleLetter             Full Word                              Description
-a                             all                                         Don’t ignore entries starting with a period.
-A                          --almost-all                             Don’t list the . and .. files.
                               --author                                 Print the author of each file.
-b                           --escape                                Print octal values for nonprintable characters.
                              --block-size=size                    Calculate the block sizes using size-byte blocks.
-B                          --ignore-backups                    Don’t list entries with the tilde (∼) symbol (used to
                                                                            denote backup copies).
-c                                                                        Sort by time of last modification.
-C                                                                       List entries by columns.
                               --color=when                       When to use colors (always, never, or auto).
-d                           --directory                            List directory entries instead of contents, and don’t
                                                                           dereference symbolic links.
-F                             --classify                           Append file-type indicator to entries.
                              --file-type                            Only append file-type indicators to some filetypes (not
                                                                         executable files).
                              --format=word                    Format output as either across, commas, horizontal, long,
                                                                         single-column, verbose, or vertical.
-g                                                                      List full file information except for the file’s owner.
                             --group-directoriesfirst         List all directories before files.
-G                         --no-group                          In long listing don’t display group names.
-h                          --human-readable               Print sizes using K for kilobytes, M for megabytes, and G
                                                                        for gigabytes.
                           --si                                       Same as -h, but use powers of 1000 instead of 1024.
-i                             --inode                            Display the index number (inode) of each file.
-l                                                                    Display the long listing format.
-L                      --dereference                         Show information for the original file for a linked file.
-n                        --numeric-uid-gid                Show numeric userid and groupid instead of names.

-o                                                                  In long listing don’t display owner names.
-r                      --reverse                               Reverse the sorting order when displaying files and
                                                                      directories.
-R                     --recursive                            List subdirectory contents recursively.
-s                      --size                                    Print the block size of each file.
-S                     --sort=size                            Sort the output by file size.
-t                      --sort=time                           Sort the output by file modification time.
-u                                                                 Display file last access time instead of last modification time.
-U                      --sort=none                          Don’t sort the output listing.
-v                    --sort=version                         Sort the output by file version.
-x                                                                 List entries by line instead of columns.
-X                   --sort=extension                   Sort the output by file extension.

Besides the normal -l parameter output information, you’ll see two additional numbers added
to each line. The first number in the listing is the file or directory inode number. The second
number is the block size of the file. The third entry is a diagram of the type of file, along with the
file’s permissions.
Following that, the next number is the number of hard links to the file  the owner of the file, the group the file belongs to, the size of the file (in bytes), a timestamp showing the last modification time by default, and finally, the actual filename.

Filtering listing output

As you’ve seen in the examples, by default the ls command lists all of the files in a directory.
Sometimes this can be overkill, especially when you’re just looking for information on a single file.
Fortunately, the ls command also provide a way for us to define a filter on the command line. It
uses the filter to determine which files or directories it should display in the output.
The filter works as a simple text-matching string. Include the filter after any command line parameters
you want to use:
$ ls -l myprog
-rwxr--r-- 1 rich rich 30 2007-08-23 21:42 myprog
$

When you specify the name of specific file as the filter, the ls command only shows the information
for that one file. Sometimes you might not know the exact name of the file you’re looking for.
The ls command also recognizes standard wildcard characters and uses them to match patterns
within the filter:
■ A question mark to represent one character
■ An asterisk to represent zero or more characters
The question mark can be used to replace exactly one character anywhere in the filter string. For
example:
$ ls -l mypro?
-rw-rw-r-- 1 rich rich 0 2007-09-03 16:38 myprob
-rwxr--r-- 1 rich rich 30 2007-08-23 21:42 myprog
$
The filter mypro? matched two files in the directory. Similarly, the asterisk can be used to match
zero or more characters:
$ ls -l myprob*
-rw-rw-r-- 1 rich rich 0 2007-09-03 16:38 myprob
-rw-rw-r-- 1 rich rich 0 2007-09-03 16:40 myproblem
$
The asterisk matches zero characters in the myprob file, but it matches three characters in the
myproblem file.
This is a powerful feature to use when searching for files when you’re not quite sure of the filenames.