Navigating the CLI Sea

Navigating the CLI Sea

The root directory

The starting point for the file system is the root folder. We call it the root, but its actual directory name is "/".

Confusingly, there is a sub-directory named "root". These are not the same.

To open the root directory, use the xdg-open / command.



The home directory

/home contains a home folder for each user on the system.

For example, my home folder is located at /home/shivm-soaini.

The xdg-open ~ command will take you to the home folder for the currently logged in user.

Short-hands

  • / - root
  • ~ - home



pwd (print working directory)

The print working directory command is super simple but very useful. Think of it as a "where am I" command.

It will print the path of your current working directory, starting from the root /.

For example, if I were on my desktop and I ran pwd, I would see /home/shivm-soaini.


The ls Command

The list command will list the contents of a directory.

When used with no options or arguments, it prints a list of the files and folders located in the current directory.

We can also list the contents of a specific directory using ls path. For example,

ls /bin command will print the contents of the /bin directory.



ls options

The ls command accepts a ton of options.

Two of the more commonly used are -l and -a.

The -l ( lowercase L ) prints in long listing format. It shows far more information about each file or folder.

The -a option will also list any hidden files that begin with " . "(dot). These are normally not listed.

We can combine the options. The -la option prints detailed information for all files, including hidden files. Try it out!

Take a loot at the man page for ls command to explore more options.



The cd command

The cd command is used to change the current working directory, "moving" into another directory.

For example, cd chickens would change into the chickens directory (assuming it exists)

In my case, cd /home/shivm-soaini would take me back to my home directory.


In Unix-like operating systems, a single dot "**.**" is used to represent the current directory. Two dots "**..**" represent the parent directory.

So we can use cd .. command to move up one level, from our current directory into the parent directory.


Relative and Absolute Paths

When providing paths to commands like cd or ls, we have the option of using relative or absolute paths.

Relative paths are paths that specify a directory or file relative to the current directory (located in that directory).

For example, if our current directory is /home/username and we want to cd into directory Desktop, we can simply run cd Desktop.

However, cd Desktop does NOT work if we are located in another directory like /bin. The relative path from /bin is ../home/username/Desktop.


Absolute paths are paths that start from the root directory (they start with a / symbol).

The absolute path to the Desktop directory is "/home/username/Desktop". We can use absolute paths to specify a location no matter our current location.

For example, from the /bin directory I could use cd /home/username/Desktop to change into the Desktop directory.


Thanks for reading :)

要查看或添加评论,请登录

Shivm Soaini的更多文章

  • Pipelines

    Pipelines

    Pipes are used to redirect a stream from one program to another program. We can take the output of one command and…

  • The Standard Streams and Redirection

    The Standard Streams and Redirection

    The three standard streams are communication channels between a computer program and its environment. They are:…

  • Working with Files

    Working with Files

    The cat command The cat command concatenates and prints the contents of files. cat filename will read the contents of…

  • The Shortcuts

    The Shortcuts

    We can speed up our command-line experience by taking advantage of the many built-in shortcuts. These shortcuts are…

  • Deleting, Moving and Copying

    Deleting, Moving and Copying

    The rm command We use the rm (remove) command to remove files from our machine. For example, rm app.

  • The Nano Text editor

    The Nano Text editor

    Nano is a simple text editor that we can access right from the terminal. It's far more accessible than other popular…

  • Making Files and Folders

    Making Files and Folders

    The touch command To create a new file from the command line, use the touch command. Provide a filename, and that file…

  • Getting Help in Command Line Interface

    Getting Help in Command Line Interface

    Sometimes it's difficult to wrap our head around some of the commands we encounter. In this scenario, man pages can…

  • First Step in Command Line

    First Step in Command Line

    Some Familiar Terms A Shell is a computer interface to an operating system which expose the OS's services to the human…

  • A Brief History of Linux

    A Brief History of Linux

    The world of operating systems has many residents, but they can be segregated into two tribes: The Microsoft NT…

社区洞察

其他会员也浏览了