Basic Linux Tutorial
Introduction – What is it? Why to learn? Linux installation directory structures Boot process Run levels in Linux Desktop Environments Different shells BASH Internal and External Commands Basic Linux Commands Important files and directories in Linux Environmental and Shell Variables Command history in Linux Character classes in Linux Text editors vim nano Searching files Creating new files Viewing File Contents File commands File permissions and ownership WildCards (Globbing) in files File compression Directory commands xargs command in Linux Comparing files Searching patterns using grep command Translating the characters using tr command Extracting data using cut command Stream editing using sed command Data extraction and reporting using awk command Sorting the file or string input uniq command in Linux Difference between grep, tr, cut, sed and awk commands Hardware commands Hard disk and memory space commands Working with Processes Managing Jobs Working with cron jobs Service command in Linux Network commands Managing Users and Groups Other Popular commands Standard streams and Redirection Pipes Package Managers in LinuxBasic commands in linux shell
In this topic, we will look at some basic Linux command.
help command
We can list all available commands using below command
$ help
Getting help on specific command
We can get the manual of each command by using below command
$ man ls
compgen command
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)
cat /etc/shells
You can use chsh command to change your default shell
chsh -s /bin/bash
To find out your default shell, use below command
echo $SHELL
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.
- CTRL+F – forward one window
- CTRL+B – backward one window
uname -a
echo command in Linux
echo – print the text to standard output stream
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
echo “$SHELL”
To print value literally, you can use single quotes. The output will be $SHELL
echo ‘$SHELL’
To execute command within echo, you will have to use back quotes “
echo `ls`
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.Web development and Automation testing
solutions delivered!!