Archive for the ‘Scripts and Commands’ Category.

Goodsong, a script for mpd to rate songs as “good”

multimedia.png

Brisbin, a regular over at the Arch linux forums has come up with a nifty little script for mpd called Goodsong.  It is for people who like to play their entire music collection on shuffle via mpd.  Occasionally,people like us all into a valley of bad music and end up hitting next far too much to get to a good song. For this reason he wrote goodsong.

Continue reading ‘Goodsong, a script for mpd to rate songs as “good”’ »

Shell Script To Rename File Name To Lowercase

terminal.png

This script use tr command to convert uppercase file name to a lowercase file name. The tr utility copies the given input to produced the output with substitution or deletion of selected characters. tr abbreviated as translate or transliterate. It takes as parameters two sets of characters, and replaces occurrences of the characters in the first set with the corresponding elements from the other set i.e. it is used to translate characters.

Continue reading ‘Shell Script To Rename File Name To Lowercase’ »

Bash For Loop Examples

terminal.png

I’m always forgetting the syntax to make “forloops in Bash.  I know I will have to come back here to find it, so I thought I would write put up this quick example with the hope that it will be useful to others as well.

Continue reading ‘Bash For Loop Examples’ »

Generate Random Passwords on the Linux Command Line

tux.png

Here is a quick one line command to generate a random password from the Linux command line.

# < /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c8

This will create an 8 character long password.  To make it longer or shorter change c8 to c# (# being whatever number you want).

Another way to go about this is the pwgen command.  Simply install pwgen and execute it and it will give you a bunch of random passwords, simply pick one out of the bunch.

Getting your screen back when it’s hosed

terminal.png

Try this:

# cat /bin/cat

Behold! Your terminal looks like garbage. Everything you type looks like you’re looking into the Matrix. What do you do?

You type reset. But wait you say, typing reset is too close to typing reboot or shutdown. Your palms start to sweat—especially if you are doing this on a production machine.

Rest assured: You can do it with the confidence that no machine will be rebooted. Go ahead, do it:

# reset

Now your screen is back to normal. This is much better than closing the window and then logging in again, especially if you just went through five machines to SSH to this machine.

See this and other help tips here.

Finding and locating files with find command

terminal-glossy.jpg

let us see how to use find command
(a) To gain lots of useful information about users and their files

(b) Monitor and enhance the security of system using find command

Continue reading ‘Finding and locating files with find command’ »

Finding large files and directories on Linux

terminal.png

Use this simple command to find large directories. To find directories over 1GB

[root@localhost]# du -h / | grep ^[0-9\.]*G

G can be replaced with M if looking for MB instead.

To find directories over 10GB and sort the output with the largest directories on top

[root@localhost]# du -h / | grep ^[1-9][0-9][0-9\.]*G | sort -rn

Continue reading ‘Finding large files and directories on Linux’ »

Empty a text file from the command line

terminal.png

This will create a new file named t whose contents is the word “test”:

$ echo “test” > t
more will display the contents of the file:

$ more t
cat reads the contents of /dev/null (which contains nothing) and > writes this into t

$ cat /dev/null > t

The next time you open your file its contents will be empty. Windows users take notice — when you run the command “cat /dev/null” Windows will throw an error. However, it will still successfully empty the contents of your file.

How To Show The Top Largest Files and Directories

terminal-glossy.jpg

Here is a quick tip on how to display the top largest files and directories within my home directory:

# du -hs /home/userid/* | sort -nr | head