To kick things off, let's take a look at a typical command line to clarify some lingo so we're all on the same page about what we call the different parts of a typical command.
$ rm -f filename.txt
$ is the so-called prompt followed by our actual command
rf. The command has an option or flag
-f followed by the argument
Before we move onto advanced concepts, let's take a look at the basics, so we're able to navigate, perform basic file operations and have a good understanding of the fundamentals.
Just like the finder on MacOS, the explorer on Windows or Nautilus on Linux, the CLI can be used to navigate the filesystem. To see what's inside our current directory,
we can use the
ls command and will get a list of all files in our current working directory:
As you can see we passed the
-la option, which are actually two parameters and they are
-l to show an extended list and
-a to show all files, including hidden files (starting with a dot).
The list option shows us a lot of info, like the permissions, file size and of course the file and folder names. It is generally a little easier to see all the files this way, than just using
The permissions block on the very left also tells us whether we're looking at a file or folder, indicated by the
d for directory on the very left.
Now that we know where we are and where we can go, it's time to move around. The
cd <folder> command allows us to 'change directory' to another, specified folder.
To stay with the example above, we could change into the
scripts folder by issuing
cd scripts. In many shells the prompt also indicates
the current directory we're in like
~/scripts $ ... but additionally, if we want to check where we are, we can issue the
pwd command to print the current working directory and see where exactly we are.
Because navigating can be a little tedious with longer paths, there are some shortcuts that can be used in combination with the
..parameter takes us up one folder in the directory tree (if available):
~parameter will take us to the currently logged in user's home directory:
-will take us back to the last visited directory. This can be especially handy when juggling with long paths and needing to switch back to the previous directory.
While the commands above should set you up for success when navigating the filesystem from the command line, it's easy to get lost and need help.
Luckily the command line comes with its very own manual, called
man. You can call the
man command followed by any other command, like the
cd command and it will
display a helpful manual with all the details, available parameters and more about the command. Here's an example: