Linux Basic commands

  • $? -> It will give last executed command exit code, any non zero number idicates failure and zero means success.
For example: If we try to remove a file which is not present using rm,they it will say no such directory or file and in the next command if we use '$?' it will return 1 or any number except zero

  • !<CMD>  -> It executes the last executed command i.e !ls means last excuted ls..The most common use case of this is if we want to execute a large command we can get the history number of the same using history and use !<history number> 
For example: If we want to execute ansible playbook using $anisble playbook <playbook_name> -i <inventory file location> --vault-password-file=./vault_pass, then we need to use above lenghty command repeatedly, instead of that get the history numer using $history and use that number with $!<history number> , it will invoke this lengthy command
  • groups -> This command is used to list all the groups which the current user is part  of.
  • Cat,more and less -> here
  1. Less command is like more with some additional features
  2. we cannot navigate back using more if the output is pipped ,we can only navigate back using b when we specify file name
  3. In more caommand,the file movement options are:
  • Enter - to move forward by one line
  • Space - to move forward by one screen
  • b - to move backward by one screen
  • q - to quit
     4. All these are available in less, in addition

  •  arrow keys to move horizontally and vertically
  •  j to move one line forward
  •  k to move one line backward
  • We can prefix the above keys with a number to override the default movement. For example, 5 followed by j will take us 5 lines forward.

    While scrolling through large files, it’s useful to be able to go back to the start of the file, or to the end of the file, quickly. The g key will take us to the start of the file, and the G key will take us to the end of the file.      

Comments