Making your own commands!

Every day solutions to every day challenges. + Brilliant stuff

Moderators: b1o, jkerr82508

Forum rules
Please feel free to post your tip it does not have to be advanced. Also ask questions directly related to the tip here. But do not start new threads with questions or ask for help here. That is what the help section is for. forum rules: http://bjoernvold.com/forum/viewtopic.php?f=8&t=568
User avatar
viking60
Über-Berserk
Posts: 9351
Joined: 14 Mar 2010, 16:34

Re: Making your own commands!

Postby viking60 » 18 Nov 2011, 13:50

Jupp! Adding only this line is definitely easier:

Code: Select all

alias ifconfig='/sbin/ifconfig'

The Guru has spoken. ImageImage

Still I will leave the above because it demonstrates how to combine several aliases into one alias.
Manjaro 64bit on the main box -Intel(R) Core(TM) i7 CPU 920 @ 2.67GHz and nVidia Corporation GT200b [GeForce GTX 275] (rev a1. + Centos on the server - Arch on the laptop.
"There are no stupid questions - Only stupid answers!"

User avatar
rolf
Guru-Berserk
Posts: 1107
Joined: 16 Mar 2010, 16:07

Re: Making your own commands!

Postby rolf » 18 Nov 2011, 14:04

Sure, I like your multi-command alias tip. :s

User avatar
viking60
Über-Berserk
Posts: 9351
Joined: 14 Mar 2010, 16:34

Making your own commands! -restarting bash

Postby viking60 » 05 Jun 2014, 13:56

Every time I add an alias I have to restart bash or log out and back in.
to restart bash i have to remember this command:

Code: Select all

source ~/.bashrc

Which i don't :oops: so i made an alias out of it:

Code: Select all

alias restartbash='source ~/.bashrc'

So to make it work you only need to do a:

Code: Select all

source ~/.bashrc
:lol: But that would be for the last time +1 After that you can simply write

Code: Select all

restartbash
Manjaro 64bit on the main box -Intel(R) Core(TM) i7 CPU 920 @ 2.67GHz and nVidia Corporation GT200b [GeForce GTX 275] (rev a1. + Centos on the server - Arch on the laptop.
"There are no stupid questions - Only stupid answers!"

User avatar
viking60
Über-Berserk
Posts: 9351
Joined: 14 Mar 2010, 16:34

Re: Making your own commands!

Postby viking60 » 30 Jun 2015, 15:30

Sometimes you need to alias complex commands with quotes since I use the single quite ( ' ) for my aliases I need to replace the inner quotes with a double one ( " ).
Example:

This command will show the last 20 programs installed in Arch ( you need to install expac):

Code: Select all

expac --timefmt='%d-%m-%Y %T' '%l\t%n' | sort | tail -20

As you can see the time format is in quotes so when I make an alias of it like this:

Code: Select all

alias lastinstalled='expac --timefmt='%d-%m-%Y %T' '%l\t%n' | sort | tail -20'

It won't work :snooty:

But when I replace those inner quotes with " like this:

Code: Select all

alias lastinstalled='expac --timefmt="%d-%m-%Y %T" "%l\t%n" | sort | tail -20'

It works just fine:

Code: Select all

30-06-2015 12:16:09   perl-json-xs
30-06-2015 12:16:10   perl-net-ssleay
30-06-2015 12:16:10   perl-xml-libxml
30-06-2015 12:16:11   perl-xml-parser
30-06-2015 12:16:12   pidgin
30-06-2015 12:16:15   postgresql-libs
30-06-2015 12:16:15   python2-systemd
30-06-2015 12:16:15   rrdtool
30-06-2015 12:16:15   rxvt-unicode
30-06-2015 12:16:15   rxvt-unicode-terminfo
30-06-2015 12:16:15   screen
30-06-2015 12:16:15   systemd-sysvcompat
30-06-2015 12:16:15   virtualbox-host-modules-lts
30-06-2015 13:25:42   ruby-net-ssh
30-06-2015 13:25:58   ruby-net-ssh-gateway
30-06-2015 14:52:49   lsb-release
30-06-2015 16:13:25   expac
31-05-2014 19:40:38   inputproto
31-05-2014 19:41:00   xvidcore
31-10-2014 15:08:54   libpipeline


If you are using exotic foreign dates you may want to change the code to:

Code: Select all

alias lastinstalled='expac --timefmt="%Y-%m-%d %T" "%l\t%n" | sort | tail -20'
Manjaro 64bit on the main box -Intel(R) Core(TM) i7 CPU 920 @ 2.67GHz and nVidia Corporation GT200b [GeForce GTX 275] (rev a1. + Centos on the server - Arch on the laptop.
"There are no stupid questions - Only stupid answers!"


Return to “Tips & Tricks”