Five Useful Shell – Prompt Tips

Five Useful Shell – Prompt Tips

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.

For example:

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.

5) If you want to find all files with the extension .txt and .jpg, then use the following command:
Shell Tips

$ 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.


  1. tala says

    I don’t know C, but I understand the concept of what the assignment is.
    In short, after the program is completed, the professor while testing it, should be able to do the following…

    1.Start the program from a command line on Linux. (We’ll call that session ‘window 1′)
    2.When the program starts, a second window pops up (window 2)
    3.In Window 2, there should be a prompt that has the current name of the directory path that session is in. •In Linux, that info is in the $PWD environment variable. set the prompt environment variable PS1=’$PWD >’
    •That will give you a path that follows the directory your in. I’m also pretty sure your professor will check to see if he CD’s into another directory, will your path stay with him.

    4.From Win2, the user should enter in one of these 6 made up commands.
    These commands are TYPED in Win2, but the output has to go to Win1 (the original window) •Sho (alias for Linux command, ls)
    •2nsa5 (alias for Linux command, cp)
    •2m7i (alias for Linux command, rm)
    •Roo7 (alias for Linux command, cd)
    •Dawir (alias for Linux command, grep)
    •23rid (alias for Linux command, more)

    5.Another command is 2ktob. After the command and a file name is entered, the rest of the output for this should stay on Win2 as the user types text, and what ever name the user has for file name, should be the name used to create a text file. (Don’t call the file ‘filename’)
    Also, be sure to generate an error if there is no file name entered. I’m pretty sure that will be tested.
    6.The final command, bye would close Window2 and end the program.

    The major trick to this project before you even write any code is to find out HOW to enter text in ONE session and have the output in a second session. I suspect her professor has already gone over that (thus the test) so hopefully that’s covered.

    The second trick is to simply substitute the fake commands with the real commands.

    For that (unless directed otherwise by the professor) I would simply use the ‘alias’ command.

    For example:

    Alias sho=ls

    Then when you type sho, linux reads it as ls.

    Embed is into your C code, and you’re set… just direct the output to window 1.
    Note: we cant use aliasing we must use parsing or something like that in C
    thank u

 Comment Policy

Your words are your own, so be nice and helpful if you can. Please, only use your REAL NAME, not your business name or keywords. Using business name or keywords instead of your real name will lead to the comment being deleted. Anonymous commenting is not allowed either. Limit the amount of links submitted in your comment. We accept clean XHTML in comments, but don't overdo it please. You can wrap code in [lang-name][/lang-name] tags.

Tell us what you're thinking...

If you want a picture to show with your comment, then get Gravatar!

CommentLuv badge