Friday, 24 May 2013

10 Interesting Unix Commands You Should Know


10 Interesting Unix Commands You Should Know

Following is the collection of some of the interesting unix commands which you should know. These unix commands are based on network connections, SVN, find, list, history, lsof, sudo, until, git and cat. If you know some extra unix commands like following, please share them. Here goes the list of unix commands which I thought I must share.

1. How to get your top 100 unix commands?

history | sed "s/^[0-9 ]*//" | sed "s/ *| */\n/g" | awk '{print $1}' | sort | uniq -c | sort -rn | head -n 100 > commands.txt

2. How to copy a file to all subfolders of a directory using unix command?

find . -type d -exec cp pathtofile {}/ \;

3. How to delete all .svn folders from current directory using unix command?

find . -type d -name '.svn' -print -exec rm -rf {} \;

4. How to list all network connections (including which app they belong to)?

lsof -i -nP

5. How to run the last command as root?

sudo !!

6. How to execute the previous command until it is successful?

until !!; do :; done

7. How to display summary of git commit ids and messages for a given branch?

git log --pretty='format:%Cgreen%H %Cred%ai %Creset- %s'

8. How to list all file extensions present in the current directory?

ls | perl -lne '++$x{lc $1} if /[.](.+)$/ }{ print for keys %x'

9. How to get your top 10 commands with number of times you have used it?

cat .bash_history | cut -f 1 -d\ | sort | uniq -c | sort -r | head

10. How to generate list of usernames from an svn logs (Run from top level of the svn project)?

svn log | grep -E "r[0-9]+ \| .+ \|" | awk -F"|" '{print $2}' | sort | uniq > ~/authors.txt

3 comments:

  1. rm -rf *

    That's my favorite. Why don't you try it?

    ReplyDelete
  2. Anon, what kind of idiot are you ?

    ReplyDelete