Linux Commands Tutorials - Using the ls Command with Examples of Options - A Hands-On Tutorial Help

May 13, 2008 Linux Certifications | Comments (0) admin @ 7:36 pm

This Linux command tutorial shows you several examples of how to run the Linux ls command using popular, commonly used command options.

All of the Linux command examples shown below have been designed to work with all Linux distributions (versions).

So, if you run all of the Linux commands shown below yourself, you’ll have a mini Linux command tutorial.

Try it - it’s a great way to get Linux training!

The Linux ls Command

The Linux ls (list) command is a very popular Linux command that is used to show a listing of directories and files.

Linux ls Command Tutorial - Showing Examples of Using ls Command Options

Run the cd (change directory) command below to change into the etc directory (folder) so we have lots of directories and files for the ls command examples below.

]$ cd /etc

Run the ls command without any options.

]$ ls

This shows a listing of all directories and files (items) in the current directory, which is the etc directory. There are a lot of items and only the end of the listing appears. You can’t see the top of the listing because it has scrolled off the screen.

So, we will use the | (vertical bar - above the Enter key on many keyboards) to “pipe” the output of the ls command to the less command - and then see some options of the ls command.

Linux Tips: To type the | (vertical bar) on most keyboards, hold down the shift key and press the \ (backslash) key.

Linux Tips: The less command is used to pause the output of a command after the first “screenful”, so the output doesn’t scroll off the screen. The less command is a Linux command, and not an option of the ls command.

]$ ls | less

Now, because you piped the output of the ls command to the less command, you can use the Up Arrow, Down Arrow and Page Up and Page Down keys to scroll through the output of the ls command.

Press the Down Arrow key a few times; then the Up Arrow key and then Page Up and Page Down. A nice way to view the files in the Linux file system!

Notice that just the item (directory and file) names appear. You don’t see any other information, such as the size and date.

Press the letter “q” (without the quotes) to quit out of the less command. Do this after running each of the command examples below.

Now run the ls command with the -l (for long) option to get a “long” and more detailed listing of the items in the etc directory.

]$ ls -l | less

Now you get lots more info on each item! The size (in bytes) of the item appears at the left of the date. When a “d” appears at the far left of an item, this indicates that the item is a directory (folder).

Try scrolling down and then scrolling up.

The ls command below uses both the -l and -S options. The -S option causes the items to be sorted by size, with the largest item at the top.

Linux Tips: Linux commands are case sensitive, so when you see an upper case “S”, be sure to type in a capital “S” (without the quotes).

]$ ls -lS | less

Press the Page Down key until you get to the bottom of the listing.

A Practical Linux ls Command Example - Listing Linux Text Configuration Files

Now let’s say you need to look at some of the system configuration settings in a Linux text file. You know the file is in the current directory (etc) and that the file ends in “.conf”, but you can’t remember the full name of the file.

To see all possible file names, you use a Linux “pattern” of “*.conf” . This pattern uses the * (asterisk) wildcard character to show all files that end in “.conf”.

]$ ls -l *.conf | less

Now you see the Linux text file you need and can check the settings in it.

Quit out of the less command.

The exit command is used to close a terminal emulation window and end a Linux bash shell “session”.

]$ exit

Beyond This “Linux Commands Tutorials” Article

The Linux ls command is one of the most popular and commonly used Linux commands. There are lots of uses for the ls command and many other useful ls command options.

As part of your Linux training, you also need to learn how to use the ls command to: get a listing of “hidden” files, get a listing using an absolute path and relative path, get listings using several different “patterns” (with wildcard characters), and list directories and files recursively.

Now, imagine watching a clearly narrated Linux video tutorial that not only shows all of the examples above, but also shows you the full output of each command - you get to learn Linux live!

Then imagine pausing the Linux video after each example and trying the commands yourself - an excellent way to get Linux training!

Written by Clyde Boom.

Linux Commands Tutorials - Using the man Command with Examples of Options - A Hands-On Tutorial Help

General Articles | Comments (0) admin @ 7:32 pm

This Linux command tutorial shows you some examples of how to run the Linux man command using popular, commonly used command options.

The Linux man Command

The Linux man command is used to view Linux “man pages” and these “man” (for “manual”) pages describe thousands of Linux commands and concepts.

Linux Tips: The Linux man pages are written in “geek-speak” and are tricky to read and understand.

Once you’ve been working with Linux for a while (and you’re no longer a new Linux user), you will want to be able to use the man command to quickly do things like: look up a Linux command option, learn a new Linux concept, find out about various directories and files in the Linux file system, and learn about the settings in Linux text (configuration) file.

Linux man Command Tutorial - Showing Examples of Using man Command Options

The Linux command examples shown below have been designed to work with all Linux distributions (versions). And if you run all these Linux commands yourself, you’ll have a mini Linux command tutorial.

So fire up Linux and give it a try - it’s a great way to get Linux training!

Linux man Command Tutorial - Using the Man Command without Any Options

To learn about a single Linux command, like the find command, use the following example and replace “find” with the name of the Linux command you need to learn more about.

]$ man find

This will display the “man” page for the find command.

A Practical Linux man Command Example - Using the Man Command with the -f Option

Let’s say it’s absolutely necessary to see all of the man pages that are available on the mkdir command, but there is more than one man page (file) for this Linux command.

Linux Tips: The man pages that are available to you are dependant on the Linux distribution (version) you are using and on the number of Linux software programs you have installed on your system. More Linux software programs = more man pages to describe the programs (and concepts).

To see all of the man pages for a Linux command or concept, use the -f option of the man command as shown in the example below.

]$ man -f mkdir

On some Linux systems, the output (on the screen) of the above command will be:

mkdir (1) - make directories
mkdir (2) - create a directory

Linux Tips: Some Linux systems will only have one man page for the mkdir command.

This output shows you that there are two man pages for the mkdir command. Notice that a (1) and (2) appears in the output for the mkdir command.

Linux Tips: If you just ran the command: man mkdir rather than using the -f option, then you would only see one man page and you would be missing all the info on the other man page(s).

Linux man Command Example - Specifying the Man Page Number with the Man Command

If there is more than one man page and you want to see a specific man page, you need to specify the man page number that you want to see. Otherwise, you will just see the first man page.

For example, to see man page 2 for the mkdir command, you run the following Linux command.

]$ man 2 mkdir

If you just ran the above command without the number 2 in it, you would see man page 1 and never see man page 2.

Beyond This “Linux Command Tutorials” Article

Man pages can be useful once you get to know how to use Linux a bit. But most people don’t usually understand man pages until they’ve been working with Linux for a while.

As part of your Linux training, you also need to learn how to use the man command to: search for a “string” of text in multiple man pages, search for text in a “section” of man pages and also search for specific text within a man page.

Written by Clyde Boom.