torstai 29. elokuuta 2013

Creating shell script

There are thousands of command in Linux. How are we supposed to remember them all ? This little trick will help you to do some things faster. We are going to do a shell script. Open terminal and change directory where you want to store the shell script. Then we are going to do a shell script named "mystatus" type

nano mystatus.sh

Inside this file we are going to type:

df -h
ifconfig

This is supposed to show information about your disk space and interface (ip, mac address) Of course you could type any command in to this script. Press CTRL + O (save) when you are ready and CTRL + X to exit. (nano shows all the command in the bottom of terminal ^ means same as CTRL + letter. 

To run shell script open terminal, locate the file and type

sh mystatus.sh

It should show the information we wanted.


Make the script runnable for everyone for everywhere

Insert in the beginning of the script this line:

#!/user/bin/env bash

It means it looks bash from every place, it can be used in any Linux version.


Then move it to /usr/bin
sudo mv mystatus.sh /usr/bin/
Give permissions 
sudo chmod 755 mystatus.sh



And run from example your own user directory.

Ei kommentteja:

Lähetä kommentti