Archive

Archive for the ‘Shell’ Category

Quick Tip: How to search in Windows Active Directory from Linux with ldapsearch

October 16, 2009 sacx Leave a comment

Sometimes we need to query, under Linux, Active Directory for users/computers without accessing a remote desktop. We can achieve that with ldapserch. First you should install first ldap-utils. In Debian or Ubuntu just run:

$ sudo apt-get install ldap-utils

The syntax for using ldapsearch:

ldapsearch -x -LLL -h [host] -D [user] -w [password] -b [base DN] -s sub "([filter])" [attribute list]

A simple example

$ ldapsearch -x -LLL -h host.example.com -D user -w password -b"dc=ad,dc=example,dc=com" -s sub "(objectClass=user)" givenName

Quick Tip: How to mount a windows share under Linux

October 2, 2009 sacx Leave a comment

First you should install smbfs package. Under Debian or Ubuntu is easy, just run:

$ sudo apt-get install smbfs

and apt will install all necessarily dependencies.

Now just mount your windows share

sudo mount -t smbfs -ousername=user //ip_of_your_windows/share /mnt/share

Probably it will ask you the password and after just go in /mnt/share too browse your windows share.

Categories: Debian, Linux, Quick Tip, Shell, Windows Tags: , ,

Quick Tip: Using find to search for files in Linux

October 1, 2009 sacx 1 comment

In 99% of my searches I’m using Midnight Commander search function, but sometimes I had servers where I didn’t had mc , so I was forced to search for a file with find. Anyway find is a very powerfull tool and combined with other linux tools like awk, sed, etc can do a lot of things in a very short time.

For example I will try to find my mp3 files from my home folder:

$ find /home/sacx -name '*.mp3'

It will return a list with my mp3 files, but if we want to search for mp3 files with the size bigger than 1MB we will use

$ find /home/sacx -name '*.mp3' -size +100k

or
$ find /home/sacx -name '*.mp3' -size -1000k

if you want to find a file smaller then 10MB.

If you want to search all the files excluding file what start with “Britney” and bigger than 5MB than you should use:

$ find /home/sacx ! -name 'Britney*.mp3' -size +500k

find have a lot of options, but I will let you to find them :)

Categories: Debian, Linux, Quick Tip, Shell Tags: ,

Quick Tip: Simple parse a CSV file with awk

October 1, 2009 sacx Leave a comment

Writing shell scripts is not an easy thing if you don’t know the power of awk, sed, grep. Today I will show you how to parse a simple csv file and extract only the needed information, with awk.

For example we have a file with the following content:

red, blue, 123, xxx
red, orange, 321, yyy
blue, orange, 312, zzz

To extract only column 1 and 3 use:

$ awk -F ',' '{print $1", "$3}' /path/to/file
red, 123
red, 321
blue, 312

With -F you can specify the field separator, so you can parse any file what contain separators.

Categories: Debian, Linux, Quick Tip, Shell Tags: ,