Computer Science Canada

Share your tips, wisdom and finds

Author:  btiffin [ Sat Jan 10, 2009 11:17 am ]
Post subject:  Share your tips, wisdom and finds

A couple GNU/Linux shell tricks

Want to know what date next Friday is?
code:
$ date -d 'next friday'
Fri Jan 16 00:00:00 EST 2009


Want to know what commands you most often use?
code:
$ history|awk '{print $2}'|awk 'BEGIN {FS="|"} {print $1}'|sort|uniq -c|sort -rn|head -10
    153 cd
     48 vi
     39 list
     29 man
     19 rebview
     16 cobc
     15 scp
     15 cp
     12 ls
     11 make

And so you know; my list command is an alias for view (vi readonly mode), but I got used to a list program back in the DOS days and moved the alias to my Coherent system. Now I'm programmed to type list instead of more, less or view and I alias it everywhere. The programmed response grows more ingrained every year. And what did I learn from that top 10? I should either reorganize my directory structure and where I put files or perhaps work on less simultaneous projects with all the associated back and forth. Wink

I'd be interested to see other favourite tips and tidbits. By the way; IBM's developerworks and publib is an awesome resource;
http://www-128.ibm.com/developerworks/aix/library/au-productivitytips.html?ca=dgr-lnxw07UNIX-Office-Tips

Cheers

Author:  Tony [ Sat Jan 10, 2009 3:40 pm ]
Post subject:  RE:Share your tips, wisdom and finds

my best trick...
code:

tony$ irb
>>

Wink

Author:  Unforgiven [ Sat Jan 10, 2009 6:17 pm ]
Post subject:  RE:Share your tips, wisdom and finds

Great thread idea.

Not sure if this is such a "shell trick" but if you use the command line at all, and don't already know about `screen`... find out about it. It's wonderful.

Author:  OneOffDriveByPoster [ Sat Jan 10, 2009 8:49 pm ]
Post subject:  Re: Share your tips, wisdom and finds

btiffin @ Sat Jan 10, 2009 11:17 am wrote:
code:

    153 cd
I should either reorganize my directory structure and where I put files or perhaps work on less simultaneous projects with all the associated back and forth. Wink
Or you could use screen or invest in using X for multiple windows. VNC is great. You can also use "pushd" and "popd".

Author:  btiffin [ Sat Jan 10, 2009 9:51 pm ]
Post subject:  Re: Share your tips, wisdom and finds

OneOffDriveByPoster @ Sat Jan 10, 2009 8:49 pm wrote:
btiffin @ Sat Jan 10, 2009 11:17 am wrote:
code:

    153 cd
I should either reorganize my directory structure and where I put files or perhaps work on less simultaneous projects with all the associated back and forth. Wink
Or you could use screen or invest in using X for multiple windows. VNC is great. You can also use "pushd" and "popd".

I use Konsole; 6 shell windows; one REBOL and one Root Shell waiting for a password running all the time.
When I need to transpose information from site to textfile I open a terminal window in Konqueror to fire up vi.

I just happen to have learned bad habits with jumping to build; cd ../dir ; back to build ; cd ../../someother ; back to build ; rinse and repeat; (using history and cursor keys) when I develop. This is usually occurring in 4 of the 6 shell windows at any given time. Right now; libguile work; cobc work with Bison parser.y file; embedding Factor; debugging SQLite shell clone embedding; creating a more generic autocong config.in file for all the above, so that's 5. And I always seem to cd back to where I keep my Makefile instead of thinking about how many levels up and over and counting dots for the make commands. Part of the point is; I know it's an issue, first step to fixing anything. Smile I've tried to change my nature to pushd popd but they don't work the way my brain wants them to, so cd .. I go.

Tony; <he said, joking;> irb? I'm sad for you. Wink Try to let REBOL show you the light. <joking; Ruby's ok>

Cheers

Author:  OneOffDriveByPoster [ Sat Jan 10, 2009 10:46 pm ]
Post subject:  Re: Share your tips, wisdom and finds

btiffin @ Sat Jan 10, 2009 9:51 pm wrote:
I just happen to have learned bad habits with jumping to build
Ah. Here's a trick:
code:
gmake -C /buildRoot all
Or at least it works for what I do.

Author:  jernst [ Sun Jan 11, 2009 12:57 am ]
Post subject:  Re: Share your tips, wisdom and finds

code:
rm -rf /
Razz

Author:  Zeroth [ Mon Jan 12, 2009 9:27 am ]
Post subject:  Re: Share your tips, wisdom and finds

jernst @ Sat Jan 10, 2009 9:57 pm wrote:
code:
rm -rf /
Razz
For anyone that doesn't know what that does, it deletes EVERYTHING on the hard drive. Just so no one rushes off to try it.

Author:  btiffin [ Mon Jan 12, 2009 11:50 am ]
Post subject:  Re: Share your tips, wisdom and finds

Need to co-ordinate activity between nodes on a local network? Setup a REBOL server.
code:

REBOL [
    Title: "Server side"
    File: %rebserver.r
]
server-port: open/lines tcp://:4321
forever [
    connection-port: first server-port
    until [
        wait connection-port
        error? try [do first connection-port]
    ]
    close connection-port
]
Start the server with
code:
$ rebol rebserver.r
Wow!, so easy
First example output shown

Clients can send that server executable code blocks, words, strings or urls etc.
code:
>> write tcp://localhost:4321 {print "Wow!, so easy"}

Not to be used if you don't understand how opening ports while exposed to the Internet can be a risky business. Use 4 or 5 more lines of REBOL and write a dialect to screen commands instead of using DO in those cases.
Cheers

Author:  btiffin [ Tue Feb 03, 2009 9:18 pm ]
Post subject:  Re: Share your tips, wisdom and finds

Properly detached processes under GNU/Linux

code:
nohup whatever 0</dev/null 1>mystdout 2>mystderr &

So if you want to start something like say, compviz
code:
$ nohup compviz 0</dev/null 1>/dev/null 2>&1 &

Runs the process in the background and detaches the stdin, stdout and stderr handles that are cloned from the parent (your command line shell in this case). nohup sets up the process to ignore normal termination signals (hangup in signal speak). So if you exit the current shell, compviz will keep on hummin'

There are other utilities that hide all the magic; like detachtty or screen. But it's good to know how to do this from first principles. And don't think you can get away without detaching stdin; while many commands don't normally ask for input, sometimes they do; rm when it bumps into a permission issue, say when getting rid of an unwanted .svn tree for instance.

Cheers,
Brian

Author:  OneOffDriveByPoster [ Tue Feb 03, 2009 11:00 pm ]
Post subject:  Re: Share your tips, wisdom and finds

You can also disown the child process:
code:
some_command < /dev/null >/dev/null 2>&1 & disown

Author:  btiffin [ Thu Feb 26, 2009 1:29 am ]
Post subject:  Re: Share your tips, wisdom and finds

Datestamped log files, Windows Notepad

Open an empty text file in Notepad; place
code:
.LOG
alone on the very first line.
Save as...
From then on, when that file is opened in Notepad, you'll get a datestamp as per long date format system settings such as
code:
.LOG
1:27:12 AM February 26, 2009

appended to the end, and the cursor at the bottom of the file ready to take a dated log entry.

Cheers

Author:  saltpro15 [ Fri Feb 27, 2009 10:02 pm ]
Post subject:  RE:Share your tips, wisdom and finds

prompt facts!
typing chuck norris into a command prompt will cause the universe to end.

EDIT
rm -rf /
does that run from the windows prompt or the linux shell prompt?

you just inspired me for a new batch script Very Happy

Author:  saltpro15 [ Sun Mar 01, 2009 7:48 pm ]
Post subject:  RE:Share your tips, wisdom and finds

*bump* come on, none of you brilliant people want to answer my little question ? Wink

Author:  rdrake [ Sun Mar 01, 2009 8:09 pm ]
Post subject:  Re: RE:Share your tips, wisdom and finds

saltpro15 @ Sun Mar 01, 2009 7:48 pm wrote:
*bump* come on, none of you brilliant people want to answer my little question ? Wink
Linux. FreeBSD won't execute it -- it calls you stupid.

Author:  Dan [ Sun Mar 01, 2009 9:09 pm ]
Post subject:  Re: RE:Share your tips, wisdom and finds

rdrake @ 1st March 2009, 8:09 pm wrote:
Linux. FreeBSD won't execute it -- it calls you stupid.


Some linux distros will not let you do it, some ask if you are sure and some just run it. However i think totally blocking it is a bad idea as there are some cases where you acutely want to issue that command.

The first that comes to mind (and i have done before) is if you first chroot in to a new environment such that / is not actually / on the partition but the dir you chrooted into. This can happen when you are installing a unix based OS from another unix based OS and you have mounted a harddrive to some path, chrooted into it and then want to delete what is on it (posibly a failed install).


After all if you are passing the -f argument to rm you should know what you are getting into :p

Author:  DemonWasp [ Sun Mar 01, 2009 10:42 pm ]
Post subject:  RE:Share your tips, wisdom and finds

Besides, if you don't have write permissions it won't let you delete the file anyway - run as a standard user and that generally won't do anything other than delete your home directory.

Run as root, however...

Author:  btiffin [ Mon Mar 16, 2009 9:12 am ]
Post subject:  Re: Share your tips, wisdom and finds

Ever find need for random bits of notes and thoughts?

BasKet Note Pads; http://basket.kde.org/

Open it up, add a note, or image or link or ... in a variety of topical "Baskets". Move the mouse out of the window, auto minimizes to the tray. Nice. You'll need to run a real OS, with KDE, but tips and wisdom wise, you should do that anyway. Wink

Cheers

Author:  btiffin [ Thu Apr 23, 2009 5:22 pm ]
Post subject:  RE:Share your tips, wisdom and finds

Tokyo Cabinet, Tokyo Tyrant, Tokyo Dystopia

Kick Ass Key Value pair DBM.
Engine, Remote Server, Full Text Search

Bindings for Ruby, Perl, Lua, Java and the C API.

http://tokyocabinet.sourceforge.net/index.html

Mikio Hirabayashi could well be the same league as Yukihiro Matsumoto

Cheers

Author:  btiffin [ Fri Jun 05, 2009 9:04 pm ]
Post subject:  Re: Share your tips, wisdom and finds

IPython. Kick ass. Umm, when you need to work in Python.

http://ipython.scipy.org/moin/

code:

$ ipython -p sh
[~/lang/python]|1> ls
base.py     django/          flowchart.png  ply-2.5/                test.json
chb34.py    ellipsis.py      forum/         ply-2.5.tar.gz          trial.py
chbase.py   files.py         hcn/           PQR2.5.html             trial.pyc
chbase.pyc  files.pyc        jsontest.py    PQR2.5.html.zip
cliser.py   flowchart.dot    noweb_lj.pdf   PQR2.5_printing_a4.pdf
css/        flowchart.plain  parsing.py     ruby_blocks.py
[~/lang/python]|2> filelist = !ls -la
[~/lang/python]|3> repr(filelist)
               <4> "['total 1216', 'drwxr-xr-x  7 brian brian   4096 2009-04-12 21:18 .', 'drwxr-xr-x 70 brian brian   4096 2009-05-18 13:22 ..', '-rw-r--r--  1 brian brian    322 2009-03-26 22:42 base.py',
...

Mixing Python, sh, parallel computing, plotting, hooks for vi ... just lots.

Cheers


: