Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Share your tips, wisdom and finds
Index -> General Programming
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
btiffin




PostPosted: 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
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Sat Jan 10, 2009 3:40 pm   Post subject: RE:Share your tips, wisdom and finds

my best trick...
code:

tony$ irb
>>

Wink
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Unforgiven




PostPosted: 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.
OneOffDriveByPoster




PostPosted: 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".
btiffin




PostPosted: 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
OneOffDriveByPoster




PostPosted: 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.
jernst




PostPosted: Sun Jan 11, 2009 12:57 am   Post subject: Re: Share your tips, wisdom and finds

code:
rm -rf /
Razz
Zeroth




PostPosted: 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.
Sponsor
Sponsor
Sponsor
sponsor
btiffin




PostPosted: 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
btiffin




PostPosted: 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
OneOffDriveByPoster




PostPosted: 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
btiffin




PostPosted: 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
saltpro15




PostPosted: 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
saltpro15




PostPosted: 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
rdrake




PostPosted: 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.
Display posts from previous:   
   Index -> General Programming
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 2  [ 20 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: