Post your Command line tricks

Forum rules
Share your brain ;)
machinebacon
Baconator
Posts: 10253
Joined: Thu Sep 16, 2010 11:03 am
Location: Pfälzerwald
Contact:

Re: Post your Command line tricks

Unread post by machinebacon » Tue Oct 08, 2013 6:29 am

Good afternoon, John :)
No difference it seems. Wikipedia (!) states:

Code: Select all

alias # Used without arguments; displays a list of all current aliases 
alias -p # Analogous to the above; not available in 4DOS/4NT and PowerShell
Also the 'official' GNU Bash manual on bash builtins says the same: http://www.gnu.org/software/bash/manual ... ltins.html
..gnutella..

User avatar
rhowaldt
Dog
Posts: 4565
Joined: Wed Oct 17, 2012 9:01 am
Contact:

Re: Post your Command line tricks

Unread post by rhowaldt » Tue Oct 08, 2013 9:59 am

Code: Select all

       alias [-p] [name[=value] ...]
              Alias with no arguments or with the -p option prints  the  list
              of  aliases  in  the  form alias name=value on standard output.
All statements are true in some sense, false in some sense, meaningless in some sense, true and false in some sense, true and meaningless in some sense, false and meaningless in some sense, and true and false and meaningless in some sense.

machinebacon
Baconator
Posts: 10253
Joined: Thu Sep 16, 2010 11:03 am
Location: Pfälzerwald
Contact:

Re: Post your Command line tricks

Unread post by machinebacon » Tue Oct 08, 2013 10:26 am

lol, now we need a forth opinion :D
..gnutella..

User avatar
wuxmedia
Grasshopper
Posts: 6454
Joined: Wed Oct 17, 2012 11:32 am
Location: Back in Blighty
Contact:

Re: Post your Command line tricks

Unread post by wuxmedia » Tue Oct 08, 2013 10:56 am

must be historical - to keep some old scripts working?
There a couple of other commands, with listing functions, that have -p as a display list to STDOUT.
bind & complete... there's the fourth man's opinion 8)
"Seek, and Ye shall find"
"Github | Chooons | Site"

User avatar
rhowaldt
Dog
Posts: 4565
Joined: Wed Oct 17, 2012 9:01 am
Contact:

Re: Post your Command line tricks

Unread post by rhowaldt » Tue Oct 08, 2013 1:57 pm

well, i think it's just the same thing. maybe some systems require flags in orde to execute commands, and they decided to add the '-p' flag. or maybe it was already there and somebody decided that just typing 'alias' by itself did nothing so would be nice to have it show you your aliases, then later somebody said 'but we already have -p for that', then the other guy says 'too bad i already programmed it, fuck it let's just have them both and let people wonder why the fuck there is 2 options for the same thing trollolol' :D
All statements are true in some sense, false in some sense, meaningless in some sense, true and false in some sense, true and meaningless in some sense, false and meaningless in some sense, and true and false and meaningless in some sense.

User avatar
wuxmedia
Grasshopper
Posts: 6454
Joined: Wed Oct 17, 2012 11:32 am
Location: Back in Blighty
Contact:

Re: Post your Command line tricks

Unread post by wuxmedia » Tue Oct 08, 2013 2:01 pm

^ that 8D
"Seek, and Ye shall find"
"Github | Chooons | Site"

machinebacon
Baconator
Posts: 10253
Joined: Thu Sep 16, 2010 11:03 am
Location: Pfälzerwald
Contact:

Re: Post your Command line tricks

Unread post by machinebacon » Tue Oct 08, 2013 2:12 pm

^^ just me dorkin' around / no harm done / just sayin' / end babblin'? :D
..gnutella..

User avatar
johnraff
Sperminator
Posts: 199
Joined: Wed Oct 17, 2012 6:38 pm
Location: Japan
Contact:

Re: Post your Command line tricks

Unread post by johnraff » Tue Oct 08, 2013 5:39 pm

...and I hadn't even noticed there was a whole page of different stuff after the alias posts...

Bizkit, sorry you got dragged into this.
All code is one.

User avatar
johnraff
Sperminator
Posts: 199
Joined: Wed Oct 17, 2012 6:38 pm
Location: Japan
Contact:

Re: Post your Command line tricks

Unread post by johnraff » Fri Oct 11, 2013 6:50 pm

Didn't seem worth starting a whole new thread, so I'll post this here:
http://texteditors.org/cgi-bin/wiki.pl?HomePage
...more text editors than you could imagine.
All code is one.

User avatar
DebianJoe
Frame Buffer
Posts: 1915
Joined: Mon Jul 01, 2013 5:41 am
Location: emacs.d

Re: Post your Command line tricks

Unread post by DebianJoe » Wed Oct 16, 2013 10:50 am

Neat little whatnot I figured out while playing with killx and w3m.

So, you want to take some random website and quickly get a cli readout of something there, but without having to actually go look at the page, use w3m and the "-dump" switch to get raw data out of it, and then grep out what you want.

Code: Select all

w3m http://weather.weatherbug.com/MY_STATE/MY_TOWN-weather.html -dump\
| grep -i 'hi:\|lo:\|rain:\|humidity:\|dew point:'
^^Cool for little scripts or perhaps a function.
|>>BBQ Roaster, Alpha Branch<< | >> clinky << | >> X11 must die << |
Thanks BASIC

machinebacon
Baconator
Posts: 10253
Joined: Thu Sep 16, 2010 11:03 am
Location: Pfälzerwald
Contact:

Re: Post your Command line tricks

Unread post by machinebacon » Wed Oct 16, 2013 10:55 am

Nice, I think (!) curl does exactly the same like w3m; we might try it.
..gnutella..

User avatar
DebianJoe
Frame Buffer
Posts: 1915
Joined: Mon Jul 01, 2013 5:41 am
Location: emacs.d

Re: Post your Command line tricks

Unread post by DebianJoe » Wed Oct 16, 2013 10:59 am

^^Pretty sure you're right, was just playing with different w3m stuffs when I thought about trying this. It should work fine with curl as well (perhaps even a bit easier on the system.)

Edit: Curl gives raw HTML, not as pretty. :(
|>>BBQ Roaster, Alpha Branch<< | >> clinky << | >> X11 must die << |
Thanks BASIC

machinebacon
Baconator
Posts: 10253
Joined: Thu Sep 16, 2010 11:03 am
Location: Pfälzerwald
Contact:

Re: Post your Command line tricks

Unread post by machinebacon » Wed Oct 16, 2013 11:01 am

Hah, it wasn't curl that took it 1:1, it was links2 - it has a -dump option too.
There are some neat little scripts like wikipedia-fetcher or news reader for the command line, usually as functions or alias, I should check my old Debian installation...

Edit: saw your edit, yup. Though the curl output is good if you want to pipe stuff 1:1 into some other document for local storage. Good to know it looks like that.
..gnutella..

User avatar
DebianJoe
Frame Buffer
Posts: 1915
Joined: Mon Jul 01, 2013 5:41 am
Location: emacs.d

Re: Post your Command line tricks

Unread post by DebianJoe » Fri Oct 18, 2013 3:46 am

Another neat little trick: 'ls' in a tree-like structure:

Code: Select all

ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/   /' -e 's/-/|/'
|>>BBQ Roaster, Alpha Branch<< | >> clinky << | >> X11 must die << |
Thanks BASIC

machinebacon
Baconator
Posts: 10253
Joined: Thu Sep 16, 2010 11:03 am
Location: Pfälzerwald
Contact:

Re: Post your Command line tricks

Unread post by machinebacon » Fri Oct 18, 2013 3:58 am

^ wow, check that sed goodness there!
..gnutella..

User avatar
GekkoP
Emacs Sancho Panza
Posts: 5878
Joined: Tue Sep 03, 2013 7:05 am

Re: Post your Command line tricks

Unread post by GekkoP » Fri Oct 18, 2013 8:27 am

^^ wow, simply beautiful

User avatar
johnraff
Sperminator
Posts: 199
Joined: Wed Oct 17, 2012 6:38 pm
Location: Japan
Contact:

Re: Post your Command line tricks

Unread post by johnraff » Tue Oct 22, 2013 5:20 am

^^^DJ that's a great bit of code! New entry for .bash_aliases :)

Here's a little trick you probably all know - run this in a terminal window for live system messages:

Code: Select all

sudo tail -f /var/log/messages
Handy when debugging automount and the like.
Or for a little light entertainment:

Code: Select all

 sudo tail -fn1 /var/log/messages | espeak
All code is one.

User avatar
wuxmedia
Grasshopper
Posts: 6454
Joined: Wed Oct 17, 2012 11:32 am
Location: Back in Blighty
Contact:

Re: Post your Command line tricks

Unread post by wuxmedia » Tue Oct 22, 2013 10:02 am

running fc-list dumps a ton of crap all over my console. "I just wanna know what to type into .Xresource etc.."

Code: Select all

fc-list | cut -d : -f 2 | sort -u | uniq
cleans it up.
"Seek, and Ye shall find"
"Github | Chooons | Site"

User avatar
johnraff
Sperminator
Posts: 199
Joined: Wed Oct 17, 2012 6:38 pm
Location: Japan
Contact:

Re: Post your Command line tricks

Unread post by johnraff » Sat Oct 26, 2013 5:37 pm

Joe's recursive ls reminded me,

Code: Select all

pstree
to see your processes and their parentage.
Last edited by johnraff on Tue Oct 29, 2013 6:12 pm, edited 1 time in total.
All code is one.

User avatar
johnraff
Sperminator
Posts: 199
Joined: Wed Oct 17, 2012 6:38 pm
Location: Japan
Contact:

Re: Post your Command line tricks

Unread post by johnraff » Sat Oct 26, 2013 5:46 pm

Does file A contain the contents of file B? (sort of multi-line grepping)

Check if string contains substring (there are other ways of course):

Code: Select all

[[ $string = *$substring* ]] && echo "$substring is in $string"
This works even if the strings contain newlines, so you can compare text file contents the same way:

Code: Select all

[[ $(<fileA) = *$(<fileB)* ]] && echo "fileA contains fileB"
All code is one.

Post Reply