The shell is the outermost layer around an operating system that uses utilities called commands to interact and access your computer's OS services. It allows users to enter a command instead of clicking buttons and returns a result within the terminal itself.
The words terminal", "command line", "command line interface/shell", and "console" are often used to refer to the same thing and can be used interchangeably.
There are several commands that you can use on the terminal. Below we will be looking at some basic and most frequent commands that are used to navigate through the filesystem.
pwd command prints the full path of your current working directory from the root. Note that the terms directory and folder are being used interchangeably in the rest of the post.
Note: The Full Path always starts with a slash(/).
ls command is used to return a list of all the files and folders in the current working directory. It works similarly to the file explorer on GUI.
ls command also accepts additional options which change the way the files are listed in the terminal output. To understand these, I've created a sample folder with the following hierarchy:
lsCommand with Options/Flags:
Writing the filename will return all the files & folders within the mentioned directory.
To list files or directories in a table format with extra information including hidden files or directories:
To list files recursively we can use the
ls -R command can take a long time if you run for a directory with a very large number of files. In such a case, you can interrupt the execution (of any command, not just
Ctrl+C. Or, you can run the
ls command with the help of a directory name like we've done above.
You can try the
ls -s command to list files or directories with their sizes.
In the screenshot below you can see the total size of the file, along with the sizes of individual items within this directory.
You can try out other command options with
ls with directories on your computer.
cd: Change Directory
cd will change your current working directory to the mentioned sub-directory.
It has other options/flags to navigate/change the working directories as follows:
To Navigate to the previous folder
To navigate to Home Directory
To navigate to Root Directory
Note: The root directory is the topmost level of the system drive whereas the home directory comes within the root directory.
mkdir: Make Directory
mkdir command is used to create a new directory within the current working directory. In the screenshot below, we will create a new folder within the
sample folder we have been fiddling around with.
Now we can see a new folder called
sample. You can also remove a directory with the
cat: Display the content of a file
cat command reads data from the file and displays its content in the terminal window. You can also concatenate multiple files into a single file.
cat, we can specify certain sections of the file we want to read, by using the following commands:
head command will display the first few lines of your file whereas the
tail command will display the last few lines of your file.
There are tons of other commands and combinations you can explore to navigate your filesystem or perform other tasks using the command line like
The command line can be a very fast and effective tool if you know your commands well. It can also handle repetitive tasks easily and requires less memory compared to other interfaces.
!pip install jovian --upgrade --quiet