Sunday, October 28, 2012

Creating complex password

There could be multiple ways to create Complex password using Linux OS. Here are couple of simple ways with sample execution to create complex password of length 8 characters:

linuxhost $ openssl rand -base64 6
linuxhost $ < /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c8; echo
linuxhost $

Scripted version, where you can define the characters that you require in the password:

Wednesday, October 17, 2012

Listing history commands using 'fc'

In Linux, the command 'fc' (stands for find command) can be used as an alternative to 'history'. 
This is a Bash built-in command using which we can list only the selected number of last executed commands.

For example, if you wish to list only last 20 commands, the syntax for 'fc' command should be "fc -l -20".
Below shown is a sample execution:

linuxhost # fc -l -20
1081     ls
1082     cd current/
1083     ls
1084     make
1085     make linux
1086     make target
1087     history | grep iozone
1088     iozone -a -i 0 -i 1 -i 2 -r 32k
1089     df -h
1090     ps -fu gpadmin | grep iozone
1091     man iozone
1092     exit
1093     df -h
1094     df -h
1095     cd /gplum/
1096     du -sh .
1097     top
1098     uname -r
1099     free -m
1100     getconf -a | grep -i pagesize
linuxhost #

Tuesday, October 16, 2012

Finding all the binaries in a Linux machine

# find / -xdev -type f -perm +111 -exec file -i '{ }' \; | grep 'x-executable' > list_of_binaries.txt

# awk -F":" '{print $1}' list_of_binaries.txt > List_of_Binaries.txt

Saturday, October 13, 2012

Comparing directories between 2 Linux systems

This is a continuation of my previous post on comparing directories using 'diff' command that are Local.
However on several occasions I faced situations, where I need to compare the file configuration between 2 Linux machines (especially in Application servers). In those scenario what I normally used to do was, copy the entire directory from server to another and run the 'diff' command as shown in the previous post. It was obviously a tedious task. Eventually I found a solution to simplify this task by using 'sshfs', which is Secure SHell FileSystem (refer 'man sshfs' for more details).

Steps to compare Folders in 2 machines. Let's assume the local folder name "/dir1" and the remote folder name is "remotehost:/dir2":

1. Login to first machine as 'root' user.

2. Create a local mount point to mount the remote folder.
    # mkdir /rmtmnt

3. Mount the Folder in remote machine using 'sshfs'
    # sshfs user@remotehost:/dir2  /rmtmnt

4. Run the 'diff' command
     # diff /dirl /rmtmnt -r --brief

5. After the execution, umount the remote filesystem using 'fusermount -u'.
     # fusermount -u /rmtmnt
Please note 'umount' command wouldn't work with sshfs.