Summary
To show the files and folders in one or more directories in your terminal, use the ls
command:
ls
ls folder-name
ls folder-1 folder-2
Details
To show the files and folders in your current directory in your terminal, use the ls
command:
ls
To show the files and folders in a different directory, you can include the path to that directory. For example, if you were in your home folder but wanted to display the files and folders in your Documents folder, you would enter the following command:
ls Documents
You can also use ls with the ~
and ..
shortcuts.
ls ~
ls ~/Documents
ls ..
ls ../..
Show files and folders in multiple directories
To show the files and folders in multiple directories, pass in multiple directories as arguments to the ls
command, like this:
ls Documents Downloads
Options
You can use the -1
flag to list everything in one column.
You can use the -G
flag to add color to the output. Folder names will have one color and file names will be displayed using a different color.
You can also use the -F
flag to add slashes to the ends of the folder names.
You can combine multiple flags like this:
ls -GF
Exercises
Try the following command in your project folder:
ls
You should see the following print out:
README.md index.html subfolder
References
Command Line Primer on the Apple Developer Archive (see the sections called Specifying Files and Directories and Frequently Used Commands)