Archive for November, 2008
Where my bash command history is stored
Nov 21st
The bash shell stores all your command history in a file of your home directory. Typically it will be stored in ~/.bash_history. This is a global history of all bash terminals which are open. The bash shell appends all commands executed in a terminal just before closing the terminal.
The history command can be used to view the active history at bash shell prompt.
[neo@techpulp ~]# history 1 ls 2 vi test.c 3 gcc test.c -o test 4 ./test 5 pwd 6 history [neo@techpulp ~]#
The number followed by NOT symbol (!) can be used to repeat a specific command. The following example shows how to More >
How to change my Bash shell prompt
Nov 16th
The environment variable “PS1” determines how the shell prompt should appear in Bash. You can find the current setting of PS1 as shown below.
[neo@techpulp ~]# echo $PS1 [\u@\h \W]\$ [neo@techpulp ~]#
Bash supports some pre-defined automatic variable substitutions in the prompt string PS1. For example in the above PS1, bash will automatically substitute current user name ($USER) in the place of “\u”. Similarly host name for “\h” and base name of current directory name for “\W”. In the above example tilde (~) means I am currently in my home directory which is “/home/neo“.
Let us try few examples now.
Like Windows Shell
[neo@techpulp ~]# More >
How to find list of user groups I belong to in Linux
Nov 16th
The Linux command groups can be used to determine the list of groups a specific user belongs to. This should work in almost all flavors of Linux distributions. The following example shows how to use it.
[neo@techpulp ~]# groups engineers devel [neo@techpulp ~]# groups neo engineers devel [neo@techpulp ~]# groups liz engineers qa [neo@techpulp ~]#
How to find the available and free memory in my Linux system
Nov 16th
The Linux system supports a special file system called PROC in which you can find various file describing the state of the current operating system. There is a file /proc/meminfo which contains information about the size of RAM currently installed on the system and how much of it is being currently used by the Linux kernel.
[neo@techpulp ~]# cat /proc/meminfo MemTotal: 2009328 kB MemFree: 385204 kB Buffers: 58328 kB Cached: 1251596 kB SwapCached: 0 kB Active: 778772 kB Inactive: 763172 kB HighTotal: 1113152 kB HighFree: 1604 kB LowTotal: 896176 kB LowFree: 383600 kB SwapTotal: 883532 kB SwapFree: 883532 kB Dirty: 136 More >
Effective usage of TAB button in Bash shell
Nov 16th
The Bash shell supports good number of intuitive ways of using TAB button on your keyboard to do command or file/directory name completions. Here is the list of TAB key usage combinations bash supports.
Get lists all available commands (<TAB><TAB>)
[neo@techpulp ~]#<TAB><TAB> Display all 4136 possibilities? (y or n) : ircat pnmstitch ! irdadump pnmtile ./ irdaping pnmtoddif [neo@techpulp ~]#
Get all available commands starting with STRING (STRING<TAB><TAB>)
[neo@techpulp ~]# z<TAB><TAB> zcat zdump zfgrep zip zipnote znew zcav zegrep zforce zipcloak zipsplit zonetab2pot.py zcmp zeisstopnm zgrep zipgrep zless zsh zdiff zenity zic zipinfo zmore zsoelim [neo@techpulp ~]# z
Get entire directory structure including hidden one (/<TAB><TAB>)
[neo@techpulp ~]# More >
My telnet session doesn’t respond – How to close it and get the shell back
Nov 16th
Sometimes the telnet session doesn’t respond and almost locks up your shell. This can be because of any of the following reasons.
- Your machine is disconnected from network
- Telnet Server is disconnected from the network
- Network problem between client and server
Your telnet client program uses Transmission Control Protocol (TCP) which takes lot of time (more than your patience) to realize that the connection to server is lost. If you are sure that the server is unreachable and would like to get out of the telnet session, you need to press “Ctrl+]” to get telnet client’s internal command prompt. There you can type ‘quit‘ More >
How to give muliple lines of input to a command in Bash
Nov 16th
There are two ways of sending multi-lined input to a command. One method is to save all the input in a file and redirect it to the command as input. The other method is useful if your input is small and can be typed at the shell itself.
This example shows how to redirect contents of a file as input to a command at bash shell.
[neo@tehpulp ~]# type <message.txt Hi There I am NeoX [neo@tehpulp ~]#
The following example shows how to provide on the fly multi-lined input to a command at Bash shell. The “<<” operator with a word that determines More >
Append redirected output of a command to a file in Bash
Nov 16th
The bash command supports “>>” operator which can be used to append command output to a file instead of overwriting it. The following example appends output of two commands in a file.
[neo@techpulp ~]# echo Hi, There > msg.txt [neo@techpulp ~]# echo I am Neo >> msg.txt [neo@techpulp ~]# cat msg.txt Hi, There I am Neo [neo@techpulp ~]#


Recent Comments