Basic Linux Commands
In this topic, we will look at some basic Linux command.
We can list all available commands using below command
Getting help on specific command
We can get the manual of each command by using below command
$ man ls
This command is very powerful and gives you lot of information about the system. This command can be executed with below options.
- -a : This option is used to display all alias commands
- -b : This option is used to display all internal commands (shell built-in commands)
- -c : This option is used to display all commands (Internal and external)
- -e : This option is used to display all exported shell variables
- -g : This option is used to display all groups in the system
- -j : This option is used to display all jobs in the system
- -k : This option is used to display all BASH keywords
- -s : This option is used to display list of all services running in the system
- -v : This option is used to all shell variables (Environment as well as local shell variables)
You can use below command to see which shells are installed on your system.
You can use chsh command to change your default shell
chsh -s /bin/bash
To find out your default shell, use below command
If you use -n option with echo command, it will not print new line.
printf command is similar to echo.
Various shells available are –
BASH, CSH, KSH, TCSH
We can find out location of the command by using below commands.
which ls – This command will display the location of binary file of ls command.
whereis ls – This command will display binary as well as other files like manuals related to ls command.
whatis ls – This command displays the information of given command in short line.
We can change the way command output is displayed using more and less commands
more is an old command. more command does not allow you to move forward and backward
less is latest command and we can move forward and backward using it
One you open a file using less command, following two keys are very helpful.
CTRL+F – forward one window
CTRL+B – backward one window
You can also use arrow keys to move back or forward by one line.
It is recommended to use less command.
history – This command shows all the commands in BASH history
Below command shows linux os details
echo command in Linux
echo – print the text to standard output stream
For example – echo hello
Above command will print hello on the screen. Problem with above statement is that it will not preserve all white space characters. It will squeeze all adjacent white space characters in single white space character. It also remove the double quotes. Another problem is that BASH tries to expand the special characters. For example – command echo * will not print * but it will print all file and directories in current directory. To avoid these problems, you should wrap the message in double quotes.
For example – echo “hello”
To print the variables, you can use below command. The output will be /bin/bash
To print value literally, you can use single quotes. The output will be $SHELL
To execute command within echo, you will have to use back quotes “
cat – This is used to concatenate 2 or more files together and display the output to standard output screen.
For example – below command will display the contents of t1.txt followed by t2.txt
cat t1.txt t2.txt
clear – Clears the terminal
We can evaluate the expressions using expr command.
For example – below command will display the output as 4.
expr 1 + 3
“true” command does nothing. It just return the exit status as 0.
“false” command does nothing. It just return the exit status as 1.
Linux commands are case sensitive and usually in lower case. So ls and LS are not same commands.