Ubuntu Forums ubuntu.com - launchpad.net - ubuntu help  

Go Back   Ubuntu Forums > The Ubuntu Forum Community > Main Support Categories > General Help
Register Reset Password Forum Help Forum Council Search Today's Posts Mark Forums Read

General Help
All your general support questions for Ubuntu, Kubuntu, Edubuntu and Xubuntu.

 
Thread Tools Display Modes
Old October 20th, 2008   #1
dennismoore1
5 Cups of Ubuntu
 
Join Date: Jul 2008
Beans: 28
Useful Shell Scripts

Hello, these are a collection of shell scripts I have created and found very useful.

install-script - installs a shell script

mv $1 /usr/local/sbin/$1
chmod a+rwx /usr/local/sbin/$1

use:
install-script file

alph - alphabetizes a file

cat "$1" | sort > "$1"

use:
alph file

clndir - gets rid of pesky "file~" files

rm *~

use:
clndir directory/name

empty-trash - empties the trash bin

rm -rf ~/.local/share/Trash/

use:
empty-trash

delinux-disk - gets rid of .Trash directories on jump drive

sudo mv /media/$1/.* ~/.local/share/Trash/files/
empty-trash

use:
delinux-disk drive name

vidget - downloads youtube videos and names them
!IMPORTANT!
use the following code before using this script:

sudo apt-get youtube-dl

youtube-dl http://www.youtube.com/watch?v=$1
mv ~/$1.flv ~/Videos/$2.flv

use:
vidget video-roster-number desired name

for clarification or amendments on any of these just reply to this post.
Thanks Guys!

Last edited by dennismoore1; October 20th, 2008 at 08:17 PM..
dennismoore1 is offline   Reply With Quote
Old October 20th, 2008   #2
shaggy999
Ubuntu Extra Shot
 
Join Date: Jun 2007
Beans: 337
Re: Useful Shell Scripts

Here's a useful shell script I use:

Code:
#!/bin/bash
/etc/init.d/ntp stop
ntpdate ntp.ubuntu.com
/etc/init.d ntp start
hwclock --systohc
Just drop this in a file, name it whatever and set the execute bit and run it. I use a commandline-only system so this is pretty handy. Took me FOREVER to figure out that I need to shut off the ntp server to update manually.
shaggy999 is offline   Reply With Quote
Old October 20th, 2008   #3
WRDN
Skinny Soy Caramel Ubuntu
 
WRDN's Avatar
 
Join Date: May 2008
Beans: 669
Ubuntu 9.04 Jaunty Jackalope
Re: Useful Shell Scripts

Good scripts. My only comment is that, in the "empty-trash" script, you only need to remove the Trash folder, and unless there are some files you do not own in your Trash folder, "sudo" is not required. When you next delete a file, the Trash folder is recreated.
__________________
Everything that has a Beginning, has an End
WRDN is offline   Reply With Quote
Old October 20th, 2008   #4
dennismoore1
5 Cups of Ubuntu
 
Join Date: Jul 2008
Beans: 28
Re: Useful Shell Scripts

Could you please clarify WRDN?
I did not quite understand that.
I have tinkered with the script quite a bit.
And I am the only user on my system so I almost never include security.
Of course, I am deffinitly no master.
I am open to your suggestions.
dennismoore1 is offline   Reply With Quote
Old October 20th, 2008   #5
WRDN
Skinny Soy Caramel Ubuntu
 
WRDN's Avatar
 
Join Date: May 2008
Beans: 669
Ubuntu 9.04 Jaunty Jackalope
Re: Useful Shell Scripts

Quote:
Originally Posted by dennismoore1 View Post
Could you please clarify WRDN?
I did not quite understand that.
I have tinkered with the script quite a bit.
And I am the only user on my system so I almost never include security.
Of course, I am deffinitly no master.
I am open to your suggestions.
Sure.

To quote from the original post:

Code:
empty-trash - empties the trash bin

sudo rm -rf ~/.local/share/Trash/
mkdir ~/.local/share/Trash/
mkdir ~/.local/share/Trash/info
mkdir ~/.local/share/Trash/files

use:
empty-trash
This can be reduced to a single line:

Code:
rm -rf ~/.local/share/Trash
Regarding the use of "sudo", in the context of Trash removal, it is OK to use, but if you don't need the higher privileges, there is no point asking for them. The user should own all the files in the Trash folder (which is located in their own home folder), so "sudo" is not needed.
__________________
Everything that has a Beginning, has an End
WRDN is offline   Reply With Quote
Old October 20th, 2008   #6
dennismoore1
5 Cups of Ubuntu
 
Join Date: Jul 2008
Beans: 28
Re: Useful Shell Scripts

very very true
however,
are you sure that when you delete a file the trash bin directories are recreated on their own?
dennismoore1 is offline   Reply With Quote
Old October 20th, 2008   #7
dennismoore1
5 Cups of Ubuntu
 
Join Date: Jul 2008
Beans: 28
Re: Useful Shell Scripts

oh yes
it is
i just tested it
ill make an amendment
thank you
dennismoore1 is offline   Reply With Quote
Old October 20th, 2008   #8
bodhi.zazen
Ubuntu Guru
 
bodhi.zazen's Avatar
 
Join Date: Apr 2006
Location: Montana
My beans are hidden!
Xubuntu Karmic Koala (testing)
Send a message via Yahoo to bodhi.zazen
Re: Useful Shell Scripts

good start, but can be simplified.

Take a look at pipes and redirects.

cat "$1" | sort > "$1"

*Note also using quotes " " allows file names with spaces

Also you will like this one

look at man mkdir

mkdir -p ~/.local/share/Trash/{info,files}

You should likely use /usr/local/bin for scripts (rather then sbin)

Most of these "one liners" can be set as an alias or function in ~/.bashrc
__________________
A person with ubuntu is open and available to others, affirming of others, does not feel threatened that others are able and good, for he or she has a proper self-assurance that comes from knowing that he or she belongs in a greater whole and is diminished when others are humiliated or diminished, when others are tortured or oppressed. ~ Archbishop Desmond Tutu, 1999

bodhi.zazen is online now   Reply With Quote
Old October 20th, 2008   #9
DGortze380
Fresh Brewed Ubuntu
 
DGortze380's Avatar
 
Join Date: Sep 2007
Location: Masschusetts
Beans: 1,368
Ubuntu 8.04 Hardy Heron
Re: Useful Shell Scripts

Use this one twice a day.

Just one a threw together for myself so there isn't much error checking or anything. Simple enough to modify for other systems, PM me with any questions. Could automatically check for a mounted drive easily enough, I just ask the user to remind myself to check, don't need the script to check for me.

Code:
#!/bin/ksh

# The backup created is of /Users (all users home and shared directories) not
# system files. Add any other directories below.

# This script will sync the backup located on /Volumes/My_External using
# the rsync command with options archive and one file system.

begin=no
run=0

while [[ $run -eq 0 ]] do

echo "Is the drive mounted and ready for the backup to begin?" 
echo "(yes|no|exit)"
read begin

if [[ $begin = "yes" ]]
then
run=1
sudo rsync -ax --delete /Users /Volumes/My_External
# -a  archive mode (recursive, links, perms, times, groups, owner, devices)
# -x  one file system

# ADD ADDITIONAL DIRECTORIES HERE USING ABOVE RSYNC COMMAND

else
if [[ $begin = "no" ]]
then
clear
echo "Please Connect and Mount the drive and type yes to continue." 
else
if [[ $begin = "exit" ]]
then
run=1
clear
else
echo "Please enter valid input (yes|no|exit)"
fi
fi
fi
done
__________________
Registered Linux User: 482377
MacBook (1,1) - OS X Leopard
ASUS P5LD2 - Core 2 Duo 3.0GHz - 2GB Corsair RAM - Nvidia 8800GT - Ubuntu 9.04 / Windows 7 Professional
DGortze380 is offline   Reply With Quote

Bookmarks

Tags
shell script useful trash

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 08:56 PM.


vBulletin ©2000 - 2009, Jelsoft Enterprises Ltd. Ubuntu Logo, Ubuntu and Canonical © Canonical Ltd. Tango Icons © Tango Desktop Project. lingonberry