Directories & files in Linux
Linux has a very specific file structure, with certain folders containing certain information. But what are these folders, and how do you traverse them in the command line?
Location | Purpose | Aliases |
| The root directory in Linux, where all folders are stored. Think of this as the equivalent of the My Computer folder on Windows | N/A |
| Where all of your personal files are stored. This usually contains |
|
| A representation of the current directory. For example, if you have a document called | N/A |
| Similar to | N/A |
LS
ls
is the command often taught first to Linux beginners, as it it easy to use and provides information for use in other commands. ls
lists the contents of a directory, showing all files & folders inside. Here are some examples of regular ls
usage:
Command | Usage |
| Lists the contents of the current directory |
| Lists the contents of the current directory, including files beginning with |
| Lists the contents of the current directory, with additional information such as date modified and user permissions |
| Lists the contents of the directory DIR |
| Lists the contents of the parent directory |
Some common ls
flags are:
Flag | Shorthand | Description |
|
| Do not ignore entries starting with |
|
| Display data in a long format |
|
| Sort by size, largest first |
Remember that you can stack flags! Try looking into some of the options for each command, and see what outputs you can produce.
CD
One of the commands you will use most often in Linux is cd
. CD stands for Change Directory, which helps the user to move their current directory. Here are some examples of regular cd
usage:
Command | Usage |
| Moves to the home directory |
| Moves to the parent directory |
| Moves to the last directory. For example, you can use |
| Moves to the directory DIR |
MKDIR
To create a folder in Linux, you can use the command mkdir
. This command is relatively simple, with only basic application:
Command | Usage |
| Creates an empty directory called DIR |
| Creates an empty directory called DIR in the parent directory |
TOUCH
Similar to mkdir
, touch
is a command that creates an empty file at the specified location. Again, this command only has basic applications:
Command | Usage |
| Creates an empty file called |
| Creates an empty file called |
Keep in mind that most of these commands take a path as input, and therefore can be more than just one part. For example, you can use cd ../../..
to travel many directories at once, or mkdir ~/test
to create an empty directory in your home
. Try playing around with more complicated directory usage now, as it will assist you later on with more complex folder structures!
Last updated