That's a great question! To list files in a different directory, you simply provide the path to that directory as an argument after the ls command.
Here is the general syntax:
ls /path/to/directory
Here are a few practical examples you can try right now in your terminal:
-
List the Root directory:
The root directory/is the very top of the Linux file system.ls / -
List the
/etcdirectory:
This is a standard Linux directory where system configuration files are stored.ls /etc -
List a specific folder inside your home directory:
Since you know you have aDesktopfolder in your home directory (~), you can peek inside it like this:ls ~/Desktop
Pro Tip: You can also list multiple directories at once by putting a space between them:
ls /home/labex/project /etc
By adding the path after ls, you can explore any part of the system without having to move there first! Do you want to try navigating into one of those folders next?