Chapter 2: The Basics

On this page…

    The following were removed from Chapter 2: “The Basics”.

    Sort Contents by File Extension

    ls -X

    The name of a file is not the only thing you can use for alphabetical sorting. You can also sort alphabetically by the file extension. In other words, you can tell ls to group all the files ending with .doc together, followed by files ending with .jpg, and finally finishing with files ending with .txt. Use the -X option (or --sort=extension); if you want to reverse the sort, add the -r option (or --reverse).

    $ $ ls -lX ~/src
    drwxr-xr-x  11 scott scott      320 2015-10-06 22:35 backups
    drwxr-xr-x   4 scott scott       96 2015-04-20 11:24 windows_patches
    -rw-r--r--   1 scott scott  2983001 2015-06-20 02:15 installdata.tar.gz
    -rw-r--r--   1 scott scott    13156 2015-10-18 15:55 horton.html
    -rwxr-xr-x   2 scott scott       96 2015-10-18 11:27 Calvin_n_Hobbes.pdf
    -rwxr--r--   1 scott scott     2294 2015-06-20 02:15 installer.sh
    -rw-r--r--   1 scott scott    13156 2015-10-18 15:55 horton.txt
    -rw-r--r--   1 scott scott  6683923 2015-09-24 22:41 Duck_Doom_Deluxe.zip

    Folders go first in the list (after all, they have no file extension), followed by the files that do possess an extension. Pay particular attention to installdata.tar.gz—it has two extensions, but the final one, the .gz, is what is used by ls.

    Find Out What mkdir Is Doing As It Acts

    mkdir -v

    Now isn't that much easier [referring to mkdir -p]? Even easier still would be using the -v option (or --verbose), which tells you what mkdir is doing every step of the way, so you don't need to actually check to make sure mkdir has done its job.

    $ mkdir -pv pictures/personal/family
    mkdir: created directory 'pictures'
    mkdir: created directory 'pictures/personal'
    mkdir: created directory 'pictures/personal/family'

    One of the best things about being a Linux user is that the OS goes out of its way to reward lazy users—the lazier the better—and this is a great way to see that in action.

    Remove Files Verbosely

    rm -v

    If you want to see what rm is doing as it does it, use the -v (or --verbose) option.

    $ pwd
    /home/scott/libby/by_pool/lieberman_pool
    $ ls -1
    libby_by_pool_01.jpg
    libby_by_pool_01.jpg_bak
    libby_by_pool_03.jpg
    libby_by_pool_03.jpg_bak
    $ rm -v *_bak
    removed 'libby_by_pool_01.jpg_bak'
    removed 'libby_by_pool_03.jpg_bak'
    $ ls -1
    libby_by_pool_01.jpg
    libby_by_pool_03.jpg
    WebSanity Top Secret