Linux: What's in the Terminal?
In the last post we met Linux and came across its shell. Now let's discuss more about the shell. In a Linux system, the shell is a command-line interface that interprets a user's commands and script files, and tells the server's operating system what to do with them.
There are many Linux commands installed with the OS, that allow us to navigate the file system, install software packages, and configure the system and other applications. An instance of a command run is known as process.
Note: Approximately everything in Linux is case-sensitive, including the directory and file names, commands and arguments. If something is not working as expected, we should always double check the spelling and the case of the commands.
Today, we will cover the basics of executing commands in Linux.
There are many Linux commands installed with the OS, that allow us to navigate the file system, install software packages, and configure the system and other applications. An instance of a command run is known as process.
Note: Approximately everything in Linux is case-sensitive, including the directory and file names, commands and arguments. If something is not working as expected, we should always double check the spelling and the case of the commands.
Today, we will cover the basics of executing commands in Linux.
Commands without Arguments or Options
To execute commands without arguments, simply type-in the name of the command and hit enter. In such a way the command will execute its default behavior which is obviously, command dependent.
For example, the default behavior of some of the commands are mentioned below:
- cd- returns to the current user's directory
- ls- prints a list of the current directory's (graphically, folder's) files and directories
- ip- prints a message to show the usage of the ip command
Commands with Arguments
Many commands accept arguments that affect their behavior or working. For example for the cd command (change directory command), if we pass it an argument, it will specify which directory we need to change to. Now by using the ls command we can simply see the contents of the current (changed) user directory. The command prompts current path would also have been updated.
Commands with Options
Many commands in Linux accept options that modify the behavior or working of the command. Options are special arguments and are written after the command followed by a '-'. Multiple options can be written together. Some options are represented by singular uppercase or lowercase letters whereas some are multi-character. Additionally some options start with '--'. For example let's talk of the list command (ls). Some of the options of ls are:
- -l: Print a long listing, including ownership, permission and size details.
- -a: List all the files of a directory including the hidden files.
- We can write this command as ls -l -a or as ls-la.
Commands with Arguments & Options
We can combine options and argument together to run a command. For example if want to see the contents of /usr/bin including the hidden files with all details then we can write the command as ls -la /usr/bin.
What are Environment Variables?
Environment variables are named values that change how commands and processes are executed. On the first login to a server, many environment variables will be set according to a few configuration files by default. (Definition taken from a source I don't remember).
Viewing and Working with the Environment Variables
- To view all the environment variables for a particular working session we use the env command.
- The value of an environment variable can be seen by prefixing the name of the variable with a '$', we may use the echo command. For example: echo $PATH. If the variable does not have a value then it gives out an empty string.
- To set an environment variable we simply need to assign it a value using '='. If the variable did not pre-exist it will be created. But this method sets the environment variable only for the current session.
Some Basic Commands
There are many commands in the shell, out of which I am discussing a few of them here:
- cd- Use to go to a directory.
- ls- Use this to know what files and directories are in the directory.
- date- Used to display the system date and time.
- mkdir- Allows users to create directories.
- touch- Used to create, change and modify timestamps of a file.
- nano- nano is already installed text editor in the Linux command line. The nano command denotes keywords with color and can recognize most languages.
- sudo- sudo stands for "SuperUser Do". It allows commands to be done with administrative or root privileges.
- chmod- We use chmod to make a file executable and to change the permissions associated with it. For example if we have a python file named abc.py. We will have to run "python abc.py" each time we want to run it. Instead if we make it executable, we will just have to run "abc.py" in the terminal. To make a file executable, we can use "chmod +x abc.py" in this case. We can use "chmod 755 abc.py" to get the root permissions or "sudo chmod +x abc.py" for root executable.
Comments
Post a Comment