Commands by kaushalmehra (8)

  • while commandt do command command ... done {commandt is executed and its exit status tested.} for i in 1 2 3 > do > echo $i > done Show Sample Output

    i=0; while [ $i -lt 100 ]; do echo "test, ttest, tttest-${i}" >> kk.file; i=`expr $i + 1`; done
    kaushalmehra · 2012-09-13 21:46:18 0
  • sed '$ d' foo.txt.tmp ...deletes last line from the file

    cp foo.txt foo.txt.tmp; sed '$ d' foo.txt.tmp > foo.txt; rm -f foo.txt.tmp
    kaushalmehra · 2012-09-13 20:57:40 2
  • Output lines starting at line 2.

    tail -n +2 foo.txt
    kaushalmehra · 2012-09-13 20:54:36 0
  • This physical volumne - hdisk1 - has TOTAL PPs:11999 (1535872 megabytes) -> 1.5 TB This physical volumne - hdisk1 - has -> 60 GB Show Sample Output

    lspv hdisk1
    kaushalmehra · 2012-09-13 15:40:58 0
  • The lspv command displays the information about the physical volume if the specific physical volume name is specified. If you do not add flags to the lspv command, by default all the available physical volumes are printed along with the following information: * Physical disk name. * Physical volume identifiers (PVIDs). * The volume group, if any, that the physical volume belongs to or the label,if any, locked with the lkdev command. * The state of the volume group. Active-When the volume group is varied on. Concurrent-When the volume group is varied on in the concurrent mode. Locked-When the physical volume is locked with the lkdev command. **************************************************************************************** In the example, the iw406 system has two hard disks. Phy disk name Phy vol identfrs (PVIDs) volume group State of Volumne group hdisk0 00f6267c8a99c7b6 rootvg active hdisk1 00f6267cb3746d01 appinstvg active hdisk0 is mounted on volume group rootvg. hdisk1 is mounted on volume group appinstvg Show Sample Output

    kaushalmehra · 2012-09-13 15:20:06 0

  • 0
    db2 connect to STGNSY3; db2 -tvf source_CUST_DIM_DELTA.sql > kk.out
    kaushalmehra · 2012-07-09 21:28:58 0
  • db2 CONNECT TO stgndv2; db2 'load from /dev/null of del replace into STMOT.ST_MORT_ARRG_DELTA nonrecoverable' Show Sample Output

    db2 CONNECT TO stgndv2; db2 'load from /dev/null of del replace into STMOT.ST_MORT_ARRG_DELTA nonrecoverable'
    kaushalmehra · 2012-06-07 19:45:57 0
  • db2 => ? connect CONNECT [USER username [{USING password [NEW new-password CONFIRM confirm-password] | CHANGE PASSWORD}]] CONNECT RESET CONNECT TO database-alias [IN {SHARE MODE | EXCLUSIVE MODE [ON SINGLE DBPARTITIONNUM]}] [USER username [{USING password [NEW new-password CONFIRM confirm-password] | CHANGE PASSWORD}]] Show Sample Output

    db2 CONNECT TO stgndv2 USER pmserver USING ********
    kaushalmehra · 2012-06-07 18:55:47 0

What's this? is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands

Check These Out

Typing the current date ( or any string ) via a shortcut as if the keys had been actually typed with the hardware keyboard in any application.
That works in all softs, CLI or GUI... I don't want to waste time to all the time typing the same stuff . So, I have that command in my window manager shortcuts ( meta+l ). All the window managers have editable shortcuts AFAIK. If not, or you don't want to use it that way, you can easily use the xbindkeys soft. I you're using kde4, you can run : $ systemsettings then open "inputs actions" and create a new shortcut. For Gnome take a look there : A more advanced one, with strings and newlines : $ xvkbd -xsendevent -text "---8

FInd the 10 biggest files taking up disk space
This combines the above two command into one. Note that you can leave off the last two commands and simply run the command as "find /home/ -type f -exec du {} \; 2>/dev/null | sort -n | tail -n 10" The last two commands above just convert the output into human readable format.

Selecting a random file/folder of a folder
Also looks in subfolders

Run bash on top of a vi session (saved or not saved), run multiple commands, instead of one at a time with :!(bashcommand), type exit and [enter] to get back to where you left off in vi.
Helps when I'm editing a script and want to double check some commands without having to exit out of vi multiple times or having to use another terminal session.

check open ports without netstat or lsof

Get the size of all the directories in current directory
OSX's BSD version of the du command uses the -d argument instead of --max-depth.

Calculate N!

Find Duplicate Files, excluding .svn-directories (based on size first, then MD5 hash)
Improvement of the command "Find Duplicate Files (based on size first, then MD5 hash)" when searching for duplicate files in a directory containing a subversion working copy. This way the (multiple dupicates) in the meta-information directories are ignored. Can easily be adopted for other VCS as well. For CVS i.e. change ".svn" into ".csv": $ find -type d -name ".csv" -prune -o -not -empty -type f -printf "%s\n" | sort -rn | uniq -d | xargs -I{} -n1 find -type d -name ".csv" -prune -o -type f -size {}c -print0 | xargs -0 md5sum | sort | uniq -w32 --all-repeated=separate

Show max lengths of all fields in a pipe delimited file with header row

pass the output of some command to a new email in the default email client
This depends on 'stripansi' and 'urlencode' commands, which exist on my system as these aliases: $ alias stripansi='perl -ple "s/\033\[(?:\d*(?:;\d+)*)*m//g;"' $ alias urlencode='perl -MURI::Escape -ne "\$/=\"\"; print uri_escape \$_"' The `open` command handles URLs on a Mac. Substitute the equivalent for your system (perhaps gnome-open). I don't use system `mail`, so I have this aliased as `mail` and use it this way: $ git show head | mail

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.


Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: