A useful awk implementation to count the number of entries in the /etc/passwd file.
john@deusexmachina:~$ sudo awk -F: '{ print $1 }' /etc/passwd | wc -l 34 |
And the quintessential “Hello World” in Awk.
john@deusexmachina:~$ awk 'BEGIN { printf "%s, %s\n", "Hello", "World!" }' Hello, World! |
This command will change your login shell if you wish to use an alternative.
john@deusexmachina:~$ chsh -s /bin/tcsh Password: |
Shell quoting is a powerful feature of the BASH shell. This example shows how we are using a command within a command to generate output. Inception in BASH!
john@deusexmachina:~$ echo "You have `ls | wc -l` files in `pwd`" You have 17 files in /home/john |
This example shows you may use the output of the ls command to provide a list of files to search for that contain a certain word or phrase.
john@deusexmachina:~/Desktop$ egrep '(Example)' `ls` examples.desktop:Name=Examples examples.desktop:Name[en_AU]=Examples examples.desktop:Name[en_CA]=Examples examples.desktop:Name[en_GB]=Examples examples.desktop:Name[sco]=Examples examples.desktop:Comment=Example content for Ubuntu examples.desktop:Comment[en_AU]=Example content for Ubuntu examples.desktop:Comment[en_CA]=Example content for Ubuntu examples.desktop:Comment[en_GB]=Example content for Ubuntu examples.desktop:Comment[sco]=Example content fur Ubuntu |
Another way to print the current directory that you are in at the terminal or virtual console.
john@deusexmachina:~$ echo ${PWD#*/} home/john |
And finally; this command will print out the last ten commands executed on your terminal.
john@deusexmachina:~$ fc -l -10 140 ls -hula | 's/Example/Content/' 141 tail=${PWD##*/} 142 ls -hula | tail=${PWD##*/} 143 ls -hula | tail=${PWD#*/} 144 ls -hula | tail=${PWD##*/} 145 cd 146 ls -hula | tail=${PWD##*/} 147 fc -l -10 148 echo ${PWD##*/} 149 echo ${PWD#*/} |
if you want to edit the last command entered at the BASH shell; use this command: fc -e vi
. This is good if it is a very long and complex command and you want an easier way to edit it.
It is much easier to remember “history 10” than “fc -l -10”
I guess so; but I wanted to post that command anyway; in case someone would find it useful.