Saturday, October 23, 2010

Have u ever seen the calendar for September 1752???

If you are working in Unix, please try this out. At $ prompt, type: cal 9 1752 Surprised????


not only in Unix, we can also search it in Google
Explanation for what you see: 
Isn't the output queer? A month with whole of eleven days missing. This was the time England shifted from Roman Julian Calendar to the Gregorian Calendar, and the king of England ordered those 11 days to be wiped off the face of the month of September of 1752. (What couldn't a King do in those days?!) And yes, the workers worked for 11 days less, but got paid for the entire 30 days. And that's how "Paid Leave" was born. Hail the King!!!

Before that April is the first Month of the year. Even then people didn’t agree to use the Roman Julian Calendar and celebrated 1st April as a New Year then the King announced that, those who celebrate April as the New Year are fools… (April fools…)
Histories are really interesting!!! 

Tuesday, October 5, 2010

11-biggest-open-source-success-stories

http://www.techdrivein.com/2010/08/11-biggest-open-source-success-stories.html

Linux Advantages in 2 minute

1. Price. You don't have to license as many "CALS" as users on your
company!

2. Stability: LINUX just goes non-stop.

3. Security: It is much more secure than other systems in the market
today.

4. Compatibility: It recognises the majority of other OS in the
network.

5. Speed: It is much faster to complete most tasks.

6. Technical Support: It has the support of thousands of programmers
and user around the world and around the clock. Frequent updates are
there as opposed to "service packs" once in many months.

7. The installer packets include the source code, which allows you to
modify, and improve it depending on your particular needs.

8. Ideal for programming: It is possible to write programs for Linux
under different platforms, and includes software compilers by default.

9. It is a system of rapid growth.

10. It is possible to run it using commodity hardware (even 486s!).
(Can use for 386 with some compilation)

11. Multitasking is REAL and not an afterthought. (similarly It is a
multiuser system from groundup)

12. It can run on multiple processors (up to 16!).

13. Free of viruses, there's no knowledge of any major virus for
LINUX.

14. It can handle hard disks of up to 16 Terabytes.

15. It is easy to get software patches, and they are free.

16. Big brands like IBM and COMPAQ are supporting it. Oracle also runs
on LINUX. MySQL and PosgreSQL replace flawlessly other Database
products. Many software vendors are already porting their systems
across.

17. Many software vendors have implemented certification systems for
Linux

18. IDC International predicts the growth of Linux will be at a rate
of 25% per year.

19. It is not limited to run applications for Linux. There are
extensions to it available, to run and support    emulation to other
OS's (Operating Systems) (Virtualisation can also be used!).

20. Lots of choice for almost every kind of software

Monday, October 4, 2010

Adding User in Linux with Script

Create a File contains the username on each line. (userlist.txt)


#ADD USER


for i in `more userlist.txt `

do
echo $i
adduser $i
done


Remove shadow  file and create it again using 


  pwconv


That utility will reconcile all of the user accounts listed in the passwd file with the shadow file entries. Then you can use the passwd utility to create a passwd for the new user account.

#CHANGE THE PASSWORD

for i in `more userlist.txt `
do
echo $i
echo $i"123" | passwd –-stdin "$i"
echo; echo "User $username’s password changed!"
done

#FORCE TO CHANGE PASSWORD AT FIRST LOGIN

for i in `more userlist.txt `
do
echo $i
echo $i"123" | chage -d 0 --stdin "$i"
echo; echo "User $username’s password changed!"
done

Sunday, October 3, 2010

30+ useful Linux commands list

This collection of commands are some of the commands I have learned in these years. Of course I am not the author of them, as no one is the author of any command in Linux. I have found some of them in differente pages, and modify some of them, others I have "created" by myself. Reading books, or man pages. Disclaimer: Try any of these commands, in non-production servers, some of them may break something Add yours in the comments.
  1. Purge configuration files of Debian's removed packages

  2. There are different ways to do this, these are some options.sudo aptitude purge '~c' sudo dpkg -l | awk '/^rc/ {print $2}' | xargs dpkg -P
  3. Create movies from jpg files

  4. mencoder "mf://*.jpg" -mf fps=10 -o test.avi -ovc lavc -lavcopts vcodec=msmpeg4v2:vbitrate=800
  5. Empty (erase contents) of a file

  6. Once again there are different ways to do this::> file truncate -s0 file
  7. Find duplicate files, based on size and MD5

  8. find -not -empty -type f -printf "%s\n" | sort -rn | uniq -d | xargs -I{} -n1 find -type f -size {}c -print0 | xargs -0 md5sum | sort | uniq -w32 --all-repeated=separate
  9. Replace space on file names with underscores

  10. #!/bin/bash
    
    ls | while read -r FILE
    do
        mv -v "$FILE" `echo $FILE | tr ' ' '_' `
    done
    
  11. Convert a man page to txt file

  12. man cp | col -b > /tmp/man-cp.txt change cp for any command you want to have its man page in text format.
  13. List the most used commands in your history

  14. history | awk '{print $2}' | sort | uniq -c | sort -rn | head
  15. Execute a command, and do not save it in history

  16. command
  17. Attach a clock to the command line prompt

  18. export PS1="${PS1%\\\$*}"' \t \$ ' The output will look like this:
    [ggarron@arch ~] 16:13:14 $
    
  19. Force file system check

  20. sudo touch /forcefsck orsudo shutdown -rF now
  21. Create and mount a RAM disk

  22. mount -t tmpfs tmpfs /mnt -o size=1024m That will create a 1 Gig RAM disk, that you can use to have fast access to files there, just remember is a RAM disk, and all its contents will be deleted when the system is rebooted.
  23. Call commands from History

  24. You may call command from history by numbers:class="codigo">history
    963  du -h
      964  ls
      965  df
      966  htop
      967  df -h
      968  df -h 
      969  history
    
    Then using the number call a command:!963 Or call it by using the first letters:!df This last method, is somehow dangerous, as you do not know what arguments and options the command is going to use, so, you can pause it. Using this way is safer:!df:p It shows you the command but do not run, it, then, you can run it without the :p and it will run, but this time you know the options.
  25. Count lines and words in a text document

  26. wc -l -w mytextfile.txt
  27. Mount a remote file system via ssh

  28. sshfs remote-user@remote.server:/remote/directory /mnt/remote-fs/ More info: here
  29. Copy ssh public key to a server to access it with no ssh password

  30. cat ~/.ssh/id_rsa.pub | ssh user@remote.machine "mkdir ~/.ssh; cat >> ~/.ssh/authorized_keys" More info: here
  31. Generate random passwords

  32. dd if=/dev/urandom bs=16 count=1 2>/dev/null | base64 With 16 characters, if you want only 8.dd if=/dev/urandom bs=8 count=1 2>/dev/null | base64
  33. Update Twitter from the command line

  34. curl --basic --user "user:pass" --data-ascii "status=Arriving the office" "http://twitter.com/statuses/update.json"
  35. Replace words in a document using sed

  36. sed -i 's/OLD/NEW/g' FILE More info here
  37. List type of network connections active and the number of them

  38. netstat -ant | awk '{print $NF}' | grep -vE '[:upper:]'| sort | uniq -c | sort -rn Output:
    35 TIME_WAIT
         27 ESTABLISHED
          2 LISTEN
          2 CLOSE_WAIT
    
  39. Mount an iso image as disk

  40. mount -t iso9660 -o loop file.iso /media/disk
  41. Reset the terminal, when it get screwed, and you can only see garbage on it

  42. reset
  43. List all processes with stablished connections

  44. lsof -i -n | grep ESTABLISHED More info here
  45. Backup a disk or partition to an image

  46. dd if=/dev/sda of=~/backup-disk-YY-MM-DD.img More info here
  47. Simple HTTP server to share files

  48. python -m SimpleHTTPServer
  49. Change the layout of you keyboard on the fly

  50. setxkbmap -layout us
  51. Read a compressed file on the fly, without uncompressing it

  52. zcat file.gz
  53. Use lynx to store web pages as text

  54. lynx -dump http://www.go2linux.org > $HOME/go2linux.txt
  55. Determining the type of file

  56. file *
  57. make commands keep running after leaving a terminal session or ssh session

  58. nohup nice -n 4 [command] > output.txt & More info here
  59. Recreate fluxbox menu

  60. fluxbox-generate_menu

linux take screenshot from command line

Some time ago, I have written about taking screenshots with Linux. But at that time I did not know about scrot, so I am now going to write about scrot.

Scrot stands for screen shot
You will have to install it, as it usually is not installed on most Linux distributions, so using your package manager install it.
How to use it
To get an instant screenshot
scrot file.png
To have scrot wait until you orginize your screen.
scrot -d 10 file.jpg
That will enter a delay of 10 seconds before taking the screenshot.
If you want scrot to display the countdown.
scrot -d 10 -c file.png
If you want to select a window, or a rectangle with the mouse use -s
scrot -s file.png
If you want the window be captured with the border
scrot -s -b file.png
Two more useful options.
Set the quality of the picture, de default is 75%.
scrot -s -b -q 90 file.png
Finally create a thumbnail, together with the screenshot, you will have to enter the percentage of the size the thumb will have, of the original picture.
scrot -t 20 file.png
You will get two files.
file.png (the original)
file-thumb.png (The thumbnail, in this case of 20% the size of the original).