Navigating the CLI Sea
Shivm Soaini
Math Major Turned AI Enthusiast: Mastering Computer Vision | Building Robust Python Code | Delving Deep into the Math of AI | Sharing Knowledge Through Writing | Ready to Transform Ideas into Reality
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
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 :)