Command Line - List Directory Contents ls
To list the current directory's contents, at the prompt, type:
ls
Press the "enter" key.
The prompt in my terminal is "chris$", so the above command looks like this:
chris$ ls
If you have a lot of documents, these results display in columns and are not very readable.
So add the option -l (that's a small letter L) to see more information, neatly in one column, one line per item.
ls -l
This will display things such as permissions, owner, group, date, and time for each file and directory contained in the current directory.
Add other options to view information in different ways...
ls -lhS
In this example:
-the l option lists all the information
-the h option shows each file's size in K (kilobytes)
-the S sorts by size
You could have skipped the h option, but I like seeing my files in K (kilobytes) rather than in B (bytes).
One of my favorites is ls -lt
The "t" standing for "time". Hence, this will list your files by time updated.
Keep in mind, many options will not stand alone.
Example: The t option needs the l option to display in a list.
So "ls -t" will not display the files by time, the t will be ignored, and the files will simply display in columns.
To see all the options available to you, at the prompt, type:
man ls
For more about "man" (manual) see COMMAND LINE TIPS below:
Copy and Paste Command Line Code:
ls -l
ls -la
ls -lh
ls -lhS
ls -lt
COMMAND LINE TIPS:
To see a list of commands on your Unix or Mac machine, type:
man builtin
or
man cd
The "enter/return" key or "down arrow" key will page down, and "q" will return you to the prompt.
To see a list of operands (options/arguments) for a specific command, type:
man CommandYouWantToKnowAbout
example:
man ls
Resources:
Command Line Change Directory - Directories cd