Posted: . At: 11:59 AM. This was 5 years ago. Post ID: 13529
Page permalink. WordPress uses cookies, or tiny pieces of information stored on your computer, to verify who you are. There are cookies for logged in users and for commenters.
These cookies expire two weeks after they are set.


Very useful Linux shell tips and tricks.


Add a new directory to the PATH to allow running an application from it without typing the full path every time you wish to run it.

PATH=$PATH:/usr/local/bin

Or you may have something like this in your .bashrc to add this every time you log in.

PATH="/home/jason/perl5/bin${PATH:+:${PATH}}"; export PATH;

This can also be set in your .bash_profile, then it can be reloaded by either logging out and back in, or by running this in your terminal.

. .bash_profile

This will reload the new settings from that file.

CONTROL CHARACTERS AND COLOUR SEQUENCES

Useful bash control characters.
Useful bash control characters.

The above image contains very useful bash control characters and color sequences.

ou can toggle the behaviour of the shell by setting and unsetting various shell options using the shopt command. To see what options are set for you, type shopt.One option which is handy to set and not enabled by default is the ‘cdspell’ option. Set it using:

shopt -s cdspell

This allows the shell to correct minor typos in the name of a directory when using the cd command. So, for example, if you have the directory ‘new’ and you type in cd enw, Bash will work out that you want to change to the ‘new’ directory. Put any shopt commands into your .bashrc file. You can find out other options by wading through the man page for Bash, or by having a read of the Bash Reference Manual (online at http://www.gnu.org/manual/bash). The Manual will also explain how to set other options using the set command and how to configure the command-editing commands on the command line, as well as thoroughly describing the Bash shell.If you want to see how other people have configured Bash, have a look at a great collection of dot files at http://www.dotfiles.com.

If you’re a fast typer you might find yourself quickly typing cd.. in order to change to a parent directory instead of cd .. — if you’re getting tired of seeing the bash: cd..: command not found error, try defining a new alias to take care of it.

alias cd..=”cd ..”

How does this work exactly? Whenever Bash sees the string cd.. starting a line, it recognises it as an alias and substitutes the string cd .. for it. Et voila! No more error messages. Aliases should be placed in your .bashrc file, because this is loaded whenever you start an interactive shell. If you cat your .bashrc file now, you’ll probably see some aliases already set up by your distribution. Alternatively, issuing the alias command alone will display aliases configured by .bashrc in addition to any system-wide aliases defined by your system administrator. If that’s you, and you’d like to find out where these other aliases are being defined, take a look in the /etc/profile.d directory. Other global Bash settings are configured in /etc/bashrc and /etc/profile.A couple of aliases intended to protect you may be predefined. To prevent you from crunching your files, you’ll often see rm aliased to rm -i and mv to mv -i. The ‘-i’ option to each of these commands causes the commands to prompt you for confirmation whenever you are going to overwrite or otherwise cause the demise of a file. If you don’t want to be prompted for confirmation when deleting files, comment out these aliases or remove them at the command line by typing this useful command.

unalias rm

To print news and system information for Ubuntu in your terminal, use these commands in your .bashrc.

cat /var/cache/motd-news
 
landscape-sysinfo

Follow the guide here to get this installed.

https://securitronlinux.com/ubuntu-2/print-useful-ubuntu-news-in-your-terminal-easily/.

This is a really nice addition to your Linux terminal.


Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.