DEV Community

M.Ark
M.Ark

Posted on • Updated on

File system in Computer Architecture

Filesystem
A filesystem organizes a computer’s files and directories into a tree structure:
The first directory in the filesystem is the root directory. It is the parent of all other directories and files in the filesystem.
Each parent directory can contain more child directories and files. In the filesystem on the right, blog/ is the parent of 2014/, 2015/, and hardware.txt.
Each directory can contain more files and child directories. The parent-child relationship continues as long as directories and files are nested.

ls
The first command we’re going to look at is ls. A command is a directive to the computer to perform a specific task. When you type ls, the command line looks at the directory you are in, and then “lists” all the files and directories inside of it. Be sure to type the letter l as in “List” and not the number 1.

In the terminal, the first thing you see is $. This is called a shell prompt. It appears when the terminal is ready to accept a command.

pwd
The next command we’re going to look at is pwd, which stands for “print working directory.” It outputs the name of the directory you are currently in, called the working directory.

Here the working directory is blog/. In Codecademy courses, your working directory is usually inside the /home/ccuser/workspace/ directory.
Together with ls, the pwd command is useful to show where you are in the filesystem

cd I

Our next command is cd, which stands for “change directory.” Just as you would click on a folder in Windows Explorer or Finder, cd switches you into the directory you specify. In other words, cd changes the working directory.

Let’s say the directory we change into is 2015:

cd 2015
Enter fullscreen mode Exit fullscreen mode

When a file, directory, or program is passed into a command, it is called an argument. Here the 2015 directory is an argument for the cd command.

The cd command takes a directory name as an argument and switches into that directory.

cd II
Instead of using cd twice in order to move from 2015 to memory, we can use it once and give it a longer argument:

 cd jan/memory
Enter fullscreen mode Exit fullscreen mode

To navigate directly to a directory, use cd with the directory’s path as an argument. Here, cd jan/memory navigates directly to the memory directory.
To move up one directory, we use cd ..:

cd ..
Enter fullscreen mode Exit fullscreen mode

Here, cd .. navigates up from jan/memory/ to jan/.

mkdir
Now that we can traverse the existing filesystem, let’s try editing it by making directories (folders) through the command line. The command for that is mkdir:

mkdir media
Enter fullscreen mode Exit fullscreen mode

The mkdir command stands for “make directory”. It takes in a directory name as an argument and then creates a new directory in the current working directory.
Here we used mkdir to create a new directory named media/ inside our working directory.

touch
Now we know how to create directories through the command line, but how do we create new files?

We can do this using the command touch:

$ touch keyboard.txt
Enter fullscreen mode Exit fullscreen mode

The touch command creates a new file inside the working directory. It takes in a filename as an argument and then creates an empty file with that name in the current working directory.

Here we used touch to create a new file named keyboard.txt.

Helper Commands
Now that we’ve covered the basics of navigating your filesystem from the command line, let’s look at some helpful commands that will make using it easier!
clear is used to clear your terminal, which is useful when it’s full of previous commands and outputs. It doesn’t change or undo your previous commands, it just clears them from the view. You can scroll upwards to see them at any time.

tab can be used to autocomplete your command. When you are typing the name of an existing file or directory, you can use tab to finish the rest of the name.
The up and down arrows (↑ and ↓) can be used to cycle through your previous commands. ↑ will take you up through your most recent commands, and ↓ will take you back through to the most recent one.

Review
You’ve learned five commands commonly used to navigate the filesystem from the command line. What can we generalize so far?

  • The command line is a text interface for the computer’s operating system. To access the command line, we use the terminal.
  • A filesystem organizes a computer’s files and directories into a tree structure. It starts with the root directory. Each parent directory can contain more child directories and files.
  • From the command line, you can navigate through files and folders on your computer:
  1. pwd outputs the name of the current working directory.
  2. ls lists all files and directories in the working directory.
  3. cd switches you into the directory you specify.
  4. mkdir creates a new directory in the working directory.
  5. touch creates a new file inside the working directory.

You can use helper commands to make navigation easier:

  • clear clears the terminal
  • tab autocompletes the name of a file or directory
  • ↑ and ↓ allow you to cycle through previous commands

Top comments (1)

Collapse
 
denim06111991 profile image
denim06111991

Would you be interested to share you thoughts on one of our book titled, Modern Computer Architecture and Organization? In return we would share a free ebook copy of the book and any other ebook as per your expertise.