Here we are enlightening you with five useful Shell-Prompt tips which definitely will prove to be a boon for you.
1) For a short-cut we always define the alias. But, sometimes, we don’t need that and want the original effect of the command.
alias ls='ls -la'
Now to restrict the alias effect and see the native command, we can execute it in any of the following three ways:
$ command ls $ \ls $ "ls"
2) If you want to check whether alias are assigned to a particular command, you can use the type command with an alias name as follows:
$ type ls
You can also use the unalias command to revert back to the original ‘ls‘ command:
$ unalias ls
This will display the alias name, if the alias is assigned.
3) To open an application from the command line in GNOME, we can use the gnome-open command. For example:
$ gnome-open jash.xls
This will open the file with the application associated with it.
4) Here is a useful way to use the append operator. To append text at the end of a file, we simply use the >> character. But if we want to append text at the beginning of the file, run the following command:
$ echo "hi Nidheeshdas" | cat - file.txt > /tmp/out && mv /tmp/out file.txt
By using this command, the “hi Nidheeshdas” line will be added at the beginning of the file.
$ find . -type f -iname "*.txt" -or -iname "*.jpg"
…where the -type f parameter is used to find files and -or is used for the ‘or’ operation. If you want to exclude hidden files in this ‘find’, then use the ! (not) operator:
$ find . -type f -iname "*.txt" ! -iname ".*"
Variables used by Shell
Here’re some variables and their details that are used by a Shell script.
- $1, $2 … Positional parameter representing command line argument.
- $# Number of arguments specified in command line.
- $0 Name of the executed command.
- $* Complete set of positional parameters as a single string.
- “$@” Each quoted string is treated as a separate argument.
- $? Exit status of the last command.
- $$ PID of the current Shell.
- $! PID of last background job.
- !$ Command line argument of the previous command.