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 LinuxCommand history in linux shell
When you type commands in shell, all those commands are saved in history file in Linux. So next time, you can execute the commands in history using shortcuts. This saves your time. You can set the history size using below syntax. Below command will instruct shell to save only 111 latest commands in the history.
$ set history=111
To display all commands in the history, you can use below syntax. $ history
$ history
Here are some of the shortcuts to execute the commands in the history.- $ !! – This is used to execute last command.
- $ !-n – This is used to execute second last command.
- $ !n – This is used to execute nth command in the list.
- !! – Execute last command
- !xyz – Execute the command (starting with xyz) from the command history
- !xyz:p – Print the command (starting with xyz) from the command history
- !$ – Execute the last argument of previous command. Note that argument should be the command. For example let us say you execute below command.ls -a
- And then execute !$ command. Then bash will execute command “-a”. But since it is not a valid command, you will get an error message saying -a : command not found.
- !* – Execute the all arguments of previous command. Note that all arguments combined together should be a the commandFor example let us say you execute below command.
- ls -a -l
- And then execute !$ command. Then bash will execute command “-a -l”. But since it is not a valid command, you will get an error message saying
- -a : command not found.
- ^xyz^pqr – Run previous command replacing xyz with pqr. Note that only command string is replaced ..not the arguments
- You can also erase and ignore duplicate commands by configuring below variables.
export HISTCONTROL=erasedups
export HISTCONTROL=ignoredups
To ignore the commands starting with space, you can use below command.
export HISTCONTROL=ignorespace
To clear history, you can use below command.
$ history -c
To disable history, you can use below command.
$ export HISTSIZE=0
Web development and Automation testing
solutions delivered!!