For those new to Linux, you might be a bit concerned about learning the command line. After all, you probably come from a platform that uses a GUI for nearly every task and haven’t spent much time with a command line interface. Fear not, that’s what we’re here for.
This time around, I want to show you how to list files and folders within a directory. This may sound like a very rudimentary task, but you’ll be surprised at how much information you can actually glean from a single command. We’re going to start out with the basics.
First, log in to your Linux system. If this is a GUI-less server, you’ll already be at a terminal window, so you’re ready to go. If not, open a terminal app and you should find yourself in your home directory.
SEE: Linux file and directory management commands (TechRepublic Premium)
To list the files and folders in the current directly, issue the command:
You should see everything listed in that directory. All that command will do is list out those files and directories that aren’t hidden. A hidden file or directory is one that starts with a period, and is exempt from the output of the default ls command.
If you want to view hidden files and folders, issue the command:
What if you need more information? Say you want to know the owner, the group, the size, the creation time, and date as well? For that you can issue the command:
If you’d prefer a human-readable format (for the size column), issue the command:
If you want to include hidden files and folders along with that listing, the command would be:
There’s also a shortcut command for that particular command, which is:
If you want to list the contents of a directory other than the one you’re in, you just add the path to that directory at the end of the command, like:
ls -lah /var/www/html/nextcloud
Finally, a very handy trick with ls is listing files and folders from largest size to last. For that, issue the command:
These ls examples should get you by for some time. If you need a bit more ls trickery in your toolkit, make sure to read the man page with the command man ls.
Subscribe to TechRepublic’s How To Make Tech Work on YouTube for all the latest tech advice for business pros from Jack Wallen.