.

Labels

.
Showing posts with label tips. Show all posts
Showing posts with label tips. Show all posts

using rm to move to trash

Using terminal can be quite dangerous if you do not have a clear idea of what you are doing. If deleted with rm function , the deleted file does not land in trash! The file is gone from your system itself. Same can also happen with mv. Making a back up copy of your important files is a necessary precaution , but there is no guarantee that you will do it on a regular basis.

So the best thing is to put an alias to rm to use it to remove / delete to trash bin.
Open  .bashrc file in your home folder. Write
 alias rm='mv -t /home/$USER/.local/share/Trash/files/' 
at the end  and save it.Now anything removed with rm will straightaway land in your trash bin.



From now onwards TOTALLY SAFE SCRIPTING !!

Enjoy Linux !!

Faster shell scripting

While scripting makes  several task easier , the complete process of writing scripts take quite some time. To make scripting faster we can combine the common processes while writing a script. Starting a script include making a new text file with or without '.sh' extension . Always the first line will include name of the bash compiler i.e !#/bin/bash. After completing the script it definitely need to be made executable  .

The following script does all the above in one go.


-------------------------------------------------------------------------------------------------------------------------------------------------
HOW THIS SCRIPT WORKS:
The script is very simple and self explaining , moreover comments are provided to make more clarity. 
$USER is a special variable which contains the name of the user.
-------------------------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------
#!/bin/bash

#for creating bash document with necessary title and permission


#creating new bash file in "/home/$USER/BASH".Change this to correct path in your system.
> /home/$USER/BASH/"$*"

#writing compiler name to the file.Please correct the path here too.
echo "#!/bin/bash" >> /home/$USER/BASH/"$*"

#making the file executable
chmod 755 /home/$USER/BASH/"$*"

#opening the file in gedit.Change this to your faviourite text editor (emacs, vim etc).Please correct the path here also.
gedit /home/$USER/BASH/"$*"

-------------------------------------------------------------------------------------------

Script is named cbd in my system ( short form for create bash doc ) . Now suppose if you want to start a  new script named fast.sh, execute cbd fast.sh in terminal . fast.sh file will opened in your faviourite text editor , with necessary permission and name of the compiler written. Just complete fast.sh script , save it and run it .(make sure you change the path name to the correct one )

Happy scripting !!



Enjoy Linux !!

Dont know what to do with these codes?? click here

'alias' to do anything faster

alias is a linux/unix tool which helps to assign very long line-commands to a name. It helps to save huge lot of time and typing.
For example   alias  play ='find -type f -iname "*.mp3" -exec mplayer {}\;'   will play every mp3 file in the current directory with mplayer just by executing play in terminal; i.e instead typing the long command on the right side of '='  you only have to type play.
To make an alias permanent you have to include and  save it in .bashrc file in home folder.

I am giving some examples which I personally  found very useful

alias go ='gnome-open'
gnome-open opens files and URLs by the default application; i.e instead of gedit foo.txt and evince foo.pdf we just have to execute  go foo.txt and go foo.pdf.You dont need to know all the names of applications installed in your system!!Make sure that gnome-open is installed else install it by sudo apt-get install libgnome2-0 ( Ubuntu ) in terminal or through Software Centre ( Ubuntu ) or Add/Remove Software ( Fedora ).


alias u ='sudo apt-get update;sudo apt-get -y upgrade'
 Execute u in terminal to update and upgrade your system.


alias S='sudo shutdown -h now'
Just executing S in terminal will shutdown your system.You will have to type password after executing S.


alias R='sudo shutdown -r now'
Executing R in terminal will restart your system


alias T='rm -rf /home/$USER/.local/share/Trash/files/*'
executing T in terminal will empty your trash bin


alias say='espeak -s 95 -v en+f2'
Now executing say "this is good" will make you hear a sweet female voice saying this is cool!!


alias ahora='truecrypt /media/Education/Ahora;nautilus /media/truecrypt1'
executing ahora will open truecrypt window for entering password.After entering the correct password the truecrypt volume will be opened in nautilus.(in this example truecrypt volume name is Ahora in /media/Education/)


alias gcheck='curl -u username --silent "https://mail.google.com/mail/feed/atom" | grep -E "title|email"'
This is the fastest method to check whether you have recieved any new mail in your gmail account.Just execute gcheck in terminal.Replace username with your real username.


alias bbc='vlc http://www.radiofeeds.co.uk/ws.asx' 
or
alias bbc='mplayer -playlist http://www.radiofeeds.co.uk/ws.asx'
Now execute bbc in terminal to listen to BBC Radio World Service in vlc media player or mplayer.



Now that is not all !! Visit http://www.commandlinefu.com/commands/browse . You can get wonder struck seeing so much line commands!! Search for commands that you require and assign an alias to it.Your life is going to get smoother and faster!!


Enjoy Linux!!