Post your Command line tricks

Forum rules
Share your brain ;)
User avatar
stark
MILF
Posts: 521
Joined: Sat Sep 27, 2014 6:38 pm
Location: Arpanet
Contact:

Re: Post your Command line tricks

Unread post by stark » Sat Feb 14, 2015 10:09 pm

If you can do it go ahead and do it, if you can't do it then don't even criticize it. - gingerdesu

User avatar
kiiroitori
dpkg-reconfigure
Posts: 72
Joined: Tue Aug 27, 2013 12:22 pm

Re: Post your Command line tricks

Unread post by kiiroitori » Mon Feb 16, 2015 12:39 am

Thanks to stark I know now that Ctrl+r searches your history recursively. Yes I didn't know that! This command is the dmenu of bash! It's like realizing the sunglasses you were looking for are actually on your forehead and that they are polarized expensive cool as fuck sunglasses! Thanks stark (heart icon here)

User avatar
dkeg
Configurator
Posts: 3782
Joined: Sun Nov 18, 2012 9:23 pm
Location: Mid-Atlantic Grill

Re: Post your Command line tricks

Unread post by dkeg » Mon Feb 16, 2015 1:11 am

that's why this thread is so great. So much out there, so much to remember (which none of us can).

Work hard; Complain less

User avatar
Dr_Chroot
Alfalfa
Posts: 1100
Joined: Mon Jun 09, 2014 9:49 pm
Location: among the sagebrush
Contact:

Re: Post your Command line tricks

Unread post by Dr_Chroot » Mon Feb 16, 2015 2:07 am

Yes, it is all good stuff fo sho! Thanks stark :D (I hadn't the faintest idea about reverse searching history either.)
Fight internet censorship.
EFF | Tor Project | Bitcoin

"There have been times throughout American history where what is right is not the same as what is legal. Sometimes to do the right thing you have to break the law." - Edward Snowden

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

Re: Post your Command line tricks

Unread post by wuxmedia » Mon Feb 16, 2015 8:12 am

wow, yeah you guys need to go through this thread then :P
I was going to moan at simple thread postage, but that seems to have worked.

ctrl-r is massive, combine it with a '#' and a unique line you have a marker.
yes you can comment out on the cmd line.

My fav is alt dot - which is in this and one of those threads too.
All these things make the CLI a lot more friendly
"Seek, and Ye shall find"
"Github | Chooons | Site"

User avatar
kiiroitori
dpkg-reconfigure
Posts: 72
Joined: Tue Aug 27, 2013 12:22 pm

Re: Post your Command line tricks

Unread post by kiiroitori » Mon Feb 16, 2015 1:32 pm

wuxmedia wrote:ctrl-r is massive, combine it with a '#' and a unique line you have a marker.
This stuff just keeps getting better. Thanks Wux!

User avatar
stark
MILF
Posts: 521
Joined: Sat Sep 27, 2014 6:38 pm
Location: Arpanet
Contact:

Re: Post your Command line tricks

Unread post by stark » Mon Feb 16, 2015 7:08 pm

Thanks Everyone. I'm just trying to stay away from zsh ( no offence ).

https://github.com/revans/bash-it
If you can do it go ahead and do it, if you can't do it then don't even criticize it. - gingerdesu

pidsley
Hermit
Posts: 2539
Joined: Wed Oct 17, 2012 12:31 pm

Re: Post your Command line tricks

Unread post by pidsley » Mon Feb 16, 2015 11:35 pm

Can I put a nano tip here? I often load a second file into vim so I can copy a snippet and paste it into the file I'm working on. nano can do this too. I've used this in the past, but so infrequently that I had to look it up every time. I think I can remember it this time.

1. If you are already running nano, turn on multibuffer mode with "alt F" -- if this is something you like and want to use all the time, put "set multibuffer" in your nanorc, or start nano with "nano --multibuffer" or "nano -F".

2. Once you are editing one file, load more files with "ctrl r"

3. To switch between the buffers, use "alt ," and "alt ."

Now you can cut lines from one file and paste them into the other.

http://www.nano-editor.org/dist/v2.2/faq.html#3.7

Finally, if you know you want two (or more) files loaded at once, use "nano <file1> <file2> ..." -- then "alt ," or "alt ." will switch between them.

Thanks to stark for reminding me to look this up and learn it again.

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

Re: Post your Command line tricks

Unread post by wuxmedia » Mon Feb 16, 2015 11:51 pm

^ that's handy, most of the work installs have vim as default, but some don't. so that's a great way of visually diffing files, or indeed c/p from/to files.
Again. it's nice having your own system as custom as you can make it, but that just doesn't happen in most work environments. Unless you are the CTO...
So always good to know the defaults of bash certainly.
"Seek, and Ye shall find"
"Github | Chooons | Site"

pidsley
Hermit
Posts: 2539
Joined: Wed Oct 17, 2012 12:31 pm

Re: Post your Command line tricks

Unread post by pidsley » Tue Feb 17, 2015 12:46 am

^ "vimdiff <file1> <file2>" is still my favorite way to compare two files (like kernel configs).

User avatar
dkeg
Configurator
Posts: 3782
Joined: Sun Nov 18, 2012 9:23 pm
Location: Mid-Atlantic Grill

Re: Post your Command line tricks

Unread post by dkeg » Tue Feb 17, 2015 1:04 am

so I'm wondering now ....

vim T & T thread?
nano T & T thread?

Work hard; Complain less

pidsley
Hermit
Posts: 2539
Joined: Wed Oct 17, 2012 12:31 pm

Re: Post your Command line tricks

Unread post by pidsley » Tue Feb 17, 2015 1:06 am

I am also thinking about tmux T&T ;)

Maybe "non emacs T&T?"

User avatar
dkeg
Configurator
Posts: 3782
Joined: Sun Nov 18, 2012 9:23 pm
Location: Mid-Atlantic Grill

Re: Post your Command line tricks

Unread post by dkeg » Tue Feb 17, 2015 1:15 am

Good timing, I just learned one tmux trick. You can hide the status bar!

Work hard; Complain less

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 Feb 18, 2015 10:22 am

pidsley wrote:Can I put a nano tip here? I often load a second file into vim so I can copy a snippet and paste it into the file I'm working on. nano can do this too. I've used this in the past, but so infrequently that I had to look it up every time. I think I can remember it this time.

1. If you are already running nano, turn on multibuffer mode with "alt F" -- if this is something you like and want to use all the time, put "set multibuffer" in your nanorc, or start nano with "nano --multibuffer" or "nano -F".

2. Once you are editing one file, load more files with "ctrl r"

3. To switch between the buffers, use "alt ," and "alt ."

Now you can cut lines from one file and paste them into the other.

http://www.nano-editor.org/dist/v2.2/faq.html#3.7

Finally, if you know you want two (or more) files loaded at once, use "nano <file1> <file2> ..." -- then "alt ," or "alt ." will switch between them.

Thanks to stark for reminding me to look this up and learn it again.
That's super-neat, thanks for the tip. I only knew about multiple files,but not that new buffers can be created. I should RTFM more :)
..gnutella..

User avatar
z3bra
Window Manager
Posts: 53
Joined: Fri Jun 27, 2014 8:34 am
Location: France
Contact:

Re: Post your Command line tricks

Unread post by z3bra » Thu Apr 09, 2015 8:48 pm

A small, but cool one:

Code: Select all

markdown < body.md | cat header.html - footer.html > index.html
To generate an HTML page out of a markdown page, and add a header/footer meanwhile.
BANGARANG, MOTHERFUCKER.

User avatar
doubledutch
killall X
Posts: 163
Joined: Sun Aug 10, 2014 1:25 pm

Re: Post your Command line tricks

Unread post by doubledutch » Fri Apr 10, 2015 5:40 pm

One I had to search for last week:
Disk Usage, human readable, 3 folders deep. Feel free to change depth and directory:

Code: Select all

du -ax --max-depth=3 /tmp/ | sort -n | awk '{if($1 > 102400) print $1/1024 "MB" " " $2; else print $0 }'
Generation after generation:

Code: Select all

perl -e '@r=(a..z,A..Z,0..9);$p.=$r[int(rand(@r))],$i++while($i<8);print"$p\n"'
ccrypt is my tool of choice, but I use this in scripts all the time:

encrypt:

Code: Select all

tar zcvf - /home/user | openssl des3 -salt -k secretpassword | dd of=/dev/st0
decrypt:

Code: Select all

openssl des3 -d -k secretpassword < stuff.des3 | tar zxf -
All of that being said, here's a PowerShell gem:

Code: Select all

psexec \\computername cmd
and then

Code: Select all

reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server" /v fDenyTSConnections /t REG_DWORD /d 0 /f
For enabling remote desktop protocol remotely.

User avatar
simgin
Meme Fodder
Posts: 1167
Joined: Sun Jan 06, 2013 12:07 am
Location: Bradford-on-Avon, UK

Re: Post your Command line tricks

Unread post by simgin » Sat Apr 11, 2015 12:25 am

^ sounds like a hack ;)
Someone told me that I am delusional, I almost fell off my unicorn.

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

Re: Post your Command line tricks

Unread post by wuxmedia » Sat Apr 11, 2015 9:45 am

must have been old (or non-gnu) to use du with no '-h' option?
in the spirit of du'ing;

Code: Select all

 du -sh /dir/ | grep [0-9]G
only find big files.
"Seek, and Ye shall find"
"Github | Chooons | Site"

pidsley
Hermit
Posts: 2539
Joined: Wed Oct 17, 2012 12:31 pm

Re: Post your Command line tricks

Unread post by pidsley » Mon Apr 27, 2015 4:32 pm

Kind of a script (not cli) tip, but if you want to loop a sequence in bash, there is no need to use seq; bash can do this by itself.

Code: Select all

 $ for n in {1..7}; do echo $n; done                                                                                                                                         
1
2
3
4
5
6
7

User avatar
stark
MILF
Posts: 521
Joined: Sat Sep 27, 2014 6:38 pm
Location: Arpanet
Contact:

Re: Post your Command line tricks

Unread post by stark » Mon Apr 27, 2015 5:59 pm

^ Thank You, very nice :)
If you can do it go ahead and do it, if you can't do it then don't even criticize it. - gingerdesu

Post Reply