5 Common Shell Commands
5 Common Shell Commands
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: Print Working Directory
The 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: Listing files in a directory
The 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.
The 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:
ls
Command with Options/Flags:
ls
[FileName]:
Writing the filename will return all the files & folders within the mentioned directory.
ls -la
or la -al
:
To list files or directories in a table format with extra information including hidden files or directories:
ls -R
:
To list files recursively we can use the -R
option.
Warning: 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 ls
) using Ctrl+C
. Or, you can run the ls
command with the help of a directory name like we've done above.
ls -s
:
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:
cd ..
To Navigate to the previous folder
cd ~
To navigate to Home Directory
cd /
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
The 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 new_directory
within sample
. You can also remove a directory with the rmdir
command.
cat
: Display the content of a file
The 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.
Aside from cat
, we can specify certain sections of the file we want to read, by using the following commands:
head
& tail
:
The head
command will display the first few lines of your file whereas the tail
command will display the last few lines of your file.
Conclusion
There are tons of other commands and combinations you can explore to navigate your filesystem or perform other tasks using the command line like mv
, touch
, rmdir
etc...
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.
Also Read:
- https://towardsdatascience.com/a-quick-guide-to-using-command-line-terminal-96815b97b955#:~:text=Linux%3A%20You%20can%20open%20Terminal,and%20opening%20the%20Terminal%20application.
- https://www.techrepublic.com/article/16-terminal-commands-every-user-should-know/
- https://www.howtogeek.com/125157/8-deadly-commands-you-should-never-run-on-linux/
!pip install jovian --upgrade --quiet
import jovian
# Execute this to save new versions of the notebook
jovian.commit(project="base-notebook")
[jovian] Updating notebook "himani007/base-notebook" on https://jovian.ai
[jovian] Committed successfully! https://jovian.ai/himani007/base-notebook