Sunday, 18 November 2012

usefull linux command

sudo : for executing command by using admin privilage .

find command


Find a file "" that exists somewhere in the filesystem

    $ find / -name -print
    If the file is found the path to the file will be printed as output. On most platforms the -print is optional, however, on some Unix systems nothing will be output without it. Without specifications find searches recursively through all directories.

Find a file without searching network or mounted filesystems

    $ find / -name -print -xdev
    This is useful if you have mounted network drives or filesystems that you do not want searched. This can increase search speed greatly if the mounted filesystem is large or over a slow network. "-mount" does the same thing as "-xdev" for compatibility with other versions of find.

Find a file without showing "Permission Denied" messages

    $ find / -name -print 2>/dev/null
    When find tries to search a directory or file that you do not have permission to read the message "Permission Denied" will be output to the screen. The 2>/dev/null option sends these messages to /dev/null so that the found files are easily viewed.

Find a file, who's name ends with .bar, within the current directory and only search 2 directories deep

    $ find . -name *.bar -maxdepth 2 -print

Search directories "./dir1" and "./dir2" for a file ""

    $ find ./dir1 ./dir2 -name -print

Search for files that are owned by the user "joebob"

    $ find /some/directory -user joebob -print
    The files output will belong to the user "joebob". Similar criteria are -uid to search for a user by their numerical id, -group to search by a group name, and -gid to search by a group id number.

Find a file that is a certain type. "-type l" searches for symbolic links

    $ find /some/directory -type l -print
    Several types of files can be searched for:
      b    block (buffered) special
      c    character (unbuffered) special
      d    directory
      p    named pipe (FIFO)
      f     regular file
      l     symbolic link
      s    socket
      D   door (Solaris)

Search for directories that contain the phrase "foo" but do not end in ".bar"

    $ find . -name '*foo*' ! -name '*.bar' -type d -print
    The "!" allows you to exclude results that contain the phrases following it.

The power of find

find becomes extremely useful when combined with other commands. One such combination would be using find and grep together.
    $ find ~/documents -type f -name '*.txt' \
    -exec grep -s DOGS {} \; -print
    This sequence uses find to look in /users/home/directory/documents for a file (-type f) with a name ending in .txt. It sends the files it finds to the grep command via the -exec option and grep searches the file found for any occurrences of the word "DOG". If the file is found it will be output to the screen and if the word "DOG" is found, within one of the found files, the line that "DOG" occurs in will also be output to the screen.
The ordering of find's options are important for getting the expected results as well as for performance reason.
Visit POWER TOOLS:A Very Valuable Find, by Jerry Peek, for creative ways to use find and important tips about constructing the command's options.

Saturday, 17 November 2012

ubuntu root password

ubuntu root account

This is the mystery for most users - you didn't set a root password, so what is it? The root user (also known as superuser), is a user on Ubuntu Linux and Unix-like systems with full administrative privileges (full access). So using root account for daily work can be very dangerous and you may damage your working system.

Ubuntu and root account

By default root account is locked under Ubuntu Linux. Therefore, you cannot login as root or use 'su -' command to become a superuser. To run all administrative command use sudo command. sudo allows a permitted user to execute a command as the superuser or another user. Ubuntu setup your default account (the one created during installation) to run all administrative commands.
For example create a new user called bar, you need to type sudo command as follows:
$ sudo adduser bar
When sudo asks for a password, you need to supply YOUR OWN password. In other words a root password is not needed. Here are few more examples.

Task: Start / stop / restart services stored in /etc/init.d/ directory

$ sudo /etc/init.d/ssh stop
$ sudo /etc/init.d/networking restart

Task: Avoid typing sudo each and every time

Note that this is not recommended until and unless you are an expert and aware of what you are typing:
$ sudo -i
Above command will start /bin/bash as a root shell so that you can enter a root user command without using sudo command.

How do I login as root user?

Open terminal and simply type the following command:
$ sudo bash
$ sudo -s
Supply your password and you will become a root user.