The command gives us the list of the contents in the current or a specified directory.
Moving around the file systemWe’ve learned how to use Use the commands we’ve learned so far to navigate to the
What if we want to move back up and out of this directory and to our top level directory? Can we type
Your computer looked for a directory or file called We have a special command to tell the computer to move us back or up one directory level. Now we can use
From this output, we can see that You can chain these together like so: prints the contents of
In most commands the flags can be combined together in no particular order to obtain the desired results/output. Examining the contents of other directoriesBy default, the Then enter the command:
This will list the contents of the The Try entering:
This will take you to the
Full vs. Relative PathsThe You will see: This is the full name of your home directory. This tells you that you are in a directory called Now enter the following command:
This jumps forward multiple levels to the You can also navigate to the These two commands have the same effect, they both take us to the A relative path is like getting directions from someone on the street. They tell you to “go right at the stop sign, and then turn left on Main Street”. That works great if you’re standing there together, but not so well if you’re trying to tell someone how to get there from another country. A full path is like GPS coordinates. It tells you exactly where something is no matter where you are right now. You can usually use either a full path or a relative path depending on what is most convenient. If we are in the home directory, it is more convenient to enter the full path. If we are in the working directory, it is more convenient to enter the relative path since it involves less typing. Over time, it will become easier for you to keep a mental note of the structure of the directories that you are using and how to quickly navigate amongst them.
Navigational ShortcutsThe root directory is the highest level
directory in your file system and contains files that are important for your computer to perform its daily work. While you will be using the root ( Then enter the command: This prints the contents of your home directory, without you needing to type the full path. The commands
What command is used to list the contents of a directory?The ls command is used to list files or directories in Linux and other Unix-based operating systems.
What is the command that will show the current directory?Use the pwd command to write to standard output the full path name of your current directory (from the /(root) directory). All directories are separated by a slash (/).
What is the command to list the contents of a directory in Unix?The ls command ( lowercase L and lowercase S ) lists the contents of your current working directory. There may be no files visible in your home directory, in which case, the UNIX prompt will be returned.
How do I list the contents of a directory in another directory?Using ls on Different Directories
To have ls list the files in a directory other than the current directory, pass the path to the directory to ls on the command line. You can also pass more than one directory to ls , and have them listed one after the other.
|