Tnoergaard’s Blog

You will not be disappointed A Blog about everything

Color Code Commands – Linux CLI

Posted by tnoergaard on January 26, 2012

  1. #——————————————////
  2. #       Color Commands
  3. #——————————————////
  4. if [ -x /usr/bin/dircolors ]; then
  5.     eval “`dircolors -b`”
  6.     alias ls=’ls –color=auto’
  7.     alias dir=’dir –color=auto’
  8.     alias vdir=’vdir –color=auto’
  9.     alias grep=’grep –color=auto’
  10.     alias fgrep=’fgrep –color=auto’
  11.     alias egrep=’egrep –color=auto’
  12. fi

 

 

Ad above code to your bashrc file

Posted in A Tnoergaard Blog | Leave a Comment »

Mint Fixer

Posted by tnoergaard on January 23, 2012

#!/bin/bash

clear

# Test for UID=0
if [ "$(echo $UID)" != "0" ]
then
echo “You must be superuser to run this program. Try ‘sudo ./fixmint.sh’”
exit
fi

# Add packages you need
echo “install some good packages to have handy.”
apt-get -y install sshfs smbfs irssi vpnc screen vlc mencoder vim moc openssh-server subversion git twinkle curl php5-cli mutt clusterssh html2text autofs vncviewer &> /dev/null

# Turn off guest login
echo “Turning off guest login.”
grep -q “allow-guest=false” /etc/lightdm/lightdm.conf || echo “allow-guest=false” >> /etc/lightdm/lightdm.conf

# Fix dual monitors
echo “Fixing dual monitor mode so that both monitors reflect changing virtual desktops.”
gconftool-2 –set /desktop/gnome/shell/windows/workspaces_only_on_primary –type bool false

# Fix broken login chime
echo “Fixing broken login chime.”
for user in $(ls /home)
do
mv /home/$user/.config/autostart/libcanberra-login-sound.desktop /home/$user/.config/autostart/libcanberra-login-sound.desktop.orig
echo -e “[Desktop Entry]\nType=Application\nName=GNOME Login Sound\nComment=Plays a sound whenever you log in\nExec=/usr/bin/canberra-gtk-play -f /usr/share/sounds/linuxmint-login.wav\nOnlyShowIn=GNOME;Unity;\nAutostartCondition=GSettings org.gnome.desktop.sound event-sounds\nX-GNOME-Autostart-Phase=Application\nX-GNOME-Provides=login-sound” >> /home/$user/.config/autostart/libcanberra-login-sound.desktop
done

# Set the login page wallpaper
echo “Setting the login background to /usr/share/backgrounds/mint.jpg. Copy any background you wish to be the login wallpaper to that file.”
sed -i -e ‘s/^background.*/background=\/usr\/share\/backgrounds\/mint.jpg/g’ /etc/lightdm/unity-greeter.conf

echo “All done. Enjoy!”

Posted in A Tnoergaard Blog | 1 Comment »

Lost your Mint password?

Posted by tnoergaard on January 23, 2012

First time this happened! A coworker asked me today how to get into his Linux Mint box after he forgot his password. Of course I rattled off the old GRUB way to get things done, but, what?? This is GRUB 2! No so fast there! Turns out it’s quite different.

You hold down the shift key while booting to get to the grub menu.
You hit ‘e’ to edit your boot options.
You change the kernel line options on the very end of the kernel line to read “rw init=/bin/bash”.
You press F10 to boot.

Once booted you are dropped immediately into a shell prompt where you can change your password with the “passwd username” command. Reboot and you’re home free!

Posted in A Tnoergaard Blog | Leave a Comment »

Delete Files Older Than x Days on Linux

Posted by tnoergaard on January 23, 2012

Delete Files Older Than x Days on Linux

The find utility on linux allows you to pass in a bunch of interesting arguments, including one to execute another command on each file. We’ll use this in order to figure out what files are older than a certain number of days, and then use the rm command to delete them.

 

Command Syntax

find /path/to/files* -mtime +5 -exec rm {} \;

Note that there are spaces between rm, {}, and \;

Explanation

  • The first argument is the path to the files. This can be a path, a directory, or a wildcard as in the example above. I would recommend using the full path, and make sure that you run the command without the exec rm to make sure you are getting the right results.
  • The second argument, -mtime, is used to specify the number of days old that the file is. If you enter +5, it will find files older than 5 days.
  • The third argument, -exec, allows you to pass in a command such as rm. The {} \; at the end is required to end the command.

This should work on Ubuntu, Suse, Redhat, or pretty much any version of linux.

Posted in A Tnoergaard Blog | Leave a Comment »

Easy hide file or folder in Linux

Posted by tnoergaard on October 13, 2010

Should you ever need to hide files or folders in Linux

Create at hidden text file in home folder

Code: touch .hidden

All you have todo now is

ad name of any folder or file to that txt file

To view hidden files just press ctrl h

Posted in A Tnoergaard Blog, Ubuntu Tips | Leave a Comment »

Right Click Tips Ubuntu

Posted by tnoergaard on September 17, 2010

If you like quick access to Documents,Spreadsheet

Or any other file you use often,ad them in your

Template folder in home dir.

Now when you mouse right click the are instant available

Posted in A Tnoergaard Blog, Ubuntu Tips | Leave a Comment »

Share a single file from your Linux. To any device with a web browser

Posted by tnoergaard on September 10, 2010

Run “python -m SimpleHTTPServer” in any directory, and the files are now available to anybody on http://your-ip:8000

ie:
cd /home/rich/shared
python -m SimpleHTTPServer

Two commands and you can share anything anywhere with anyone ;-)

Posted in A Tnoergaard Blog, Ubuntu Tips | Leave a Comment »

UUID on Linux fstab file

Posted by tnoergaard on September 10, 2010

UUID stands for Universally Unique IDentifier and it is used in Linux to identify disk in the /etc/fstab file.

This way, the order of the disk in the motherboard can be changed, not affecting the mount point they will have.

As can be seen, it is a good idea to have fstab using UUID instead of the /dev/xdx way to identify the disks.

Let’s learn how to add disks, to your fstab file using UUID.

List the UUIDs

There are two ways of doing this:

  1. ls -l /dev/disk/by-uuid/
  2. Being the output

    lrwxrwxrwx 1 root root 10 Sep  2 10:54 11b7eb1f-79d5-4bfe-8aa5-9235e6cccbfe -> ../../sda1
    lrwxrwxrwx 1 root root 10 Sep  2 10:54 340cf4e2-4ee7-490c-a169-5045ebff4fac -> ../../sdb4
    lrwxrwxrwx 1 root root 10 Sep  2 10:54 37ea6741-c1b0-4297-9f23-b36417b3c109 -> ../../sdb1
    lrwxrwxrwx 1 root root 10 Sep  2 10:54 5b0a6c7b-d936-4470-a645-2b68db32d2c1 -> ../../sdb3
    lrwxrwxrwx 1 root root 10 Sep  2 10:54 6db36bd8-0778-4b35-a0bd-66487002cbe0 -> ../../sdb2
    lrwxrwxrwx 1 root root 10 Sep  2 10:54 afdc3ca9-c06e-452a-8e42-2b35ad9dac65 -> ../../sda2
    
  3. blkid
  4. Being the output

    /dev/sda1: UUID="11b7eb1f-79d5-4bfe-8aa5-9235e6cccbfe" SEC_TYPE="ext2" TYPE="ext3"
    /dev/sda2: LABEL="/home" UUID="afdc3ca9-c06e-452a-8e42-2b35ad9dac65" SEC_TYPE="ext2" TYPE="ext3"
    /dev/sdb1: UUID="37ea6741-c1b0-4297-9f23-b36417b3c109" TYPE="swap"
    /dev/sdb2: UUID="393ac665-f5c2-488d-b601-b59ba1d5675b" SEC_TYPE="ext2" TYPE="ext3"
    /dev/sdb3: UUID="5b0a6c7b-d936-4470-a645-2b68db32d2c1" TYPE="ext2"
    /dev/sdb4: UUID="340cf4e2-4ee7-490c-a169-5045ebff4fac" SEC_TYPE="ext2" TYPE="ext3"
    

Now that you have the UUID edit the /etc/fstab file and make it look like this:

UUID=340cf4e2-4ee7-490c-a169-5045ebff4fac / ext3 defaults 0 1
UUID=37ea6741-c1b0-4297-9f23-b36417b3c109 swap swap defaults 0 0
UUID=5b0a6c7b-d936-4470-a645-2b68db32d2c1 /boot ext2 defaults 0 1
UUID=6db36bd8-0778-4b35-a0bd-66487002cbe0 /home ext3 defaults 0 1

Instead of:

/dev/sdb4 / ext3 defaults 0 1
/dev/sdb1 swap swap defaults 0 0
/dev/sdb3 /boot ext2 defaults 0 1
/dev/sdb2 /home ext3 defaults 0 1

Posted in A Tnoergaard Blog, Ubuntu Tips | Leave a Comment »

Create directory trees in one command

Posted by tnoergaard on September 10, 2010

If you ever need to create directory trees like this

Directory Tree

You can do this:

cd /tmp

mkdir 1

cd 1

mkdir 2

cd 2

mkdir C

or, you can just do this:

mkdir -p /tmp/1/2/3

From the man page of mkdir

-p, --parents
no error if existing, make parent directories as needed

You can also use this option to create more complicated trees. Like this one.

directory tree

Do that with this:

mkdir -p /tmp/a{1,2,B{1,2}}

Posted in A Tnoergaard Blog, Ubuntu Tips | Leave a Comment »

Tar tips and uses

Posted by tnoergaard on September 10, 2010

According to Wikipedia:

“In computing, tar (derived from tape archive and commonly referred to as “tarball”) is both a file format (in the form of a type of archive bitstream) and the name of a program used to handle such files. The format was created in the early days of Unix and standardized by POSIX.1-1988 and later POSIX.1-2001.

Initially developed to be written directly to sequential I/O devices for tape backup purposes, it is now commonly used to collect many files into one larger file for distribution or archiving, while preserving file system information such as user and group permissions, dates, and directory structures.

We will now learn some useful command to manage and create tar files.

We will cover how to:

  1. Create a tar file with no compression
  2. Untar an uncompressed tar file
  3. Create a gzipped tar file
  4. Untar a gzipped tar file
  5. Create a bzipped tar file
  6. Untar a bzipeed tar file
  7. Listing the contents of a tar file
  8. Extracting the files to a specific directory

1. Create a tar with no compression

tar cvf tar-file.tar directory/

2. Untar an uncompressed tar file

tar xvf tar-file.tar

3. Create a gzipped tar file

tar cvzf tar-file.tar.gz /directory

4. Untar a gzipped tar file

tar xvzf tar-file.tar.gz

5. Create a bzipped tar file

tar cvjf tar-file.tar.bz /directory

6. Untar a bzipeed tar file

tar xvjf tar-file.tar.bz

7. Listing the contents of a tar file

tar tvf tar-file.tar

For uncompressed tar file

tar tvfz tar-file.tar

For gzipped tar files

tar tvfj tar-file.tar

For jzipped tar files

8. Extracting the files to a specific directory

tar xvf -C tmp/som/other/directory tar-file.tar.gz

For uncompressed tar files

tar xvzf -C tmp/som/other/directory tar-file.tar.gz

For gzipped tar files

tar xvjf -C tmp/som/other/directory tar-file.tar.gz

For jzipped tar files

The options used

-c
create a new archive
-v
verbosely list files processed
-f
use archive file or device ARCHIVE
-x
eXtract the file
-z
–gzip, –gunzip –ungzip
-j
–bzip2
-C
change to directory DIR

Posted in A Tnoergaard Blog, Ubuntu Tips | Leave a Comment »

 
Follow

Get every new post delivered to your Inbox.