Post your Command line tricks

Forum rules
Share your brain ;)
User avatar
wuxmedia
Grasshopper
Posts: 6445
Joined: Wed Oct 17, 2012 11:32 am
Location: Back in Blighty
Contact:

Post your Command line tricks

Unread post by wuxmedia » Sun Sep 22, 2013 2:48 pm

Please. :geek:
As before, brief description, code, done.

just on the off chance you totally screw up your $PATH.
emergency 'ls'

Code: Select all

echo *
"Seek, and Ye shall find"
"Github | Chooons | Site"

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 » Sun Sep 22, 2013 2:54 pm

Code: Select all

sudo !!
!! executes last command in bash/zsh.
|>>BBQ Roaster, Alpha Branch<< | >> clinky << | >> X11 must die << |
Thanks BASIC

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 » Sun Sep 22, 2013 3:02 pm

oh oh i got another.
working ankle deep in the filesystem, need to skip out for a breath of air, then go back to where you were?

Code: Select all

wux@chauvin/im/so/deep/in/the/files/i/dont/wann/have/to/type/this/again$ pushd /oh/my/dang/why/so/many/directory/levels
wux@chauvin/oh/my/dang/why/so/many/directory/levels$ pushd
wux@chauvin/im/so/deep/in/the/files/i/dont/wann/have/to/type/this/again$
"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 » Sun Sep 22, 2013 5:08 pm

inspired by seeing wux jump back and forth between directories, i suddenly remembered this one.
go back to the previous directory

Code: Select all

cd -
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: 6445
Joined: Wed Oct 17, 2012 11:32 am
Location: Back in Blighty
Contact:

Re: Post your Command line tricks

Unread post by wuxmedia » Sun Sep 22, 2013 8:46 pm

have you got a whole bunch of dirs you need to access? keep pushd'ing
pushd displays the stack once it's added

Code: Select all

pushd -2
to get to saved dir 1 (starts at zero)
forget the stack?

Code: Select all

dirs -p
don't need the '-p' just looks nicer.
from here
"Seek, and Ye shall find"
"Github | Chooons | Site"

User avatar
gutterslob
Resident Tranny
Posts: 1124
Joined: Thu Aug 08, 2013 7:13 pm

Re: Post your Command line tricks

Unread post by gutterslob » Sun Sep 22, 2013 10:04 pm

Code: Select all

whoami
Useful for those times I wake up and can't remember who I am. =P

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 » Mon Sep 23, 2013 4:20 am

BASH:
If you start an X-app from the terminal, press Ctrl-z to escape it while keeping it open.
And Ctrl-z without running an instance of another app closes the terminal.
Pressing Ctrl-l cears the screen
Of course this one everyone knows: Ctrl-r to search the bash history
..gnutella..

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 Sep 23, 2013 5:06 am

what happened on this date

Code: Select all

calendar

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 » Mon Sep 23, 2013 5:42 am

Always good to have: http://www.gnu.org/software/bash/manual/bashref.html
Before I duplicate stuff: http://www.ukuug.org/events/linux2003/papers/bash_tips/
And of course: http://www.shell-fu.org/lister.php?tag=bash

Neat one similar to !!:* is pressing "Alt ." or "Esc ."

Code: Select all

cd /some/ultra/long/path/to/some.file
cp [Alt] + [.] /new/path/
performs a

Code: Select all

cp /some/ultra/long/path/to/some.file /new/path/
..gnutella..

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 Sep 23, 2013 7:44 am

Just to add, Ctrl+g and 'ESC' gets you neatly out of search-mode, not much point as Ctrl-c works fine, but there you are.
Ctrl+r twice remembers your last search string.
"Seek, and Ye shall find"
"Github | Chooons | Site"

User avatar
ivanovnegro
Minister of Truth
Posts: 5448
Joined: Wed Oct 17, 2012 11:12 pm

Re: Post your Command line tricks

Unread post by ivanovnegro » Mon Sep 23, 2013 9:09 pm

Useful for those times I upgrade packages and can't remember what version I am running. =P

Code: Select all

<package> --version
E.g.

Code: Select all

ncmpcpp --version
ncmpcpp version: 0.5.10

optional screens compiled-in:
 - tag editor
 - tiny tag editor
 - artist info
 - outputs
 - visualizer
 - clock

encoding detection: enabled
built with support for: curl fftw ncurses taglib unicode

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 » Fri Sep 27, 2013 4:37 am

In extension to ivanovnegro's tip, I use

Code: Select all

dpkg -p <package>
to get some package info (including version number).

E.g.

Code: Select all

dpkg -p conky
Package: conky
Priority: extra
Section: oldlibs
Installed-Size: 36
Maintainer: Vincent Cheng <[email protected]>
Architecture: all
Version: 1.9.0-3
Depends: conky-std | conky-cli | conky-all
Size: 34110
Description: highly configurable system monitor (transitional package)
 Conky is a system monitor that can display just about anything,
 either on your root desktop or in its own window.
 Conky has many built-in objects, as well as the ability to execute
 external programs or scripts (either external or through built-in
 lua support).
 .
 This is a dummy package to ease transition to the new packaging scheme.
 It may be safely removed after upgrade/installation.
Homepage: http://conky.sourceforge.net/

User avatar
xaos52
The Good Doctor
Posts: 190
Joined: Thu Aug 15, 2013 11:59 am
Location: Eernegem, Belgium

Re: Post your Command line tricks

Unread post by xaos52 » Fri Sep 27, 2013 5:36 pm

Shutdown from the command line:
type
Ctrl+R utd <enter>
Check the displayed line for [1] the shutdown command [2] -h or -r depending on reboot or halt wanted
If check is negative press Ctrl+R until it becomes positive
<enter>

For whom that is not fast enoug, replace 'utd' by 'ow'.
Ctrl+R searches history file backward, so 'ow' is found before 'utd', at least if toy use the 'now' argument.
You are a 'specimen' if you notice the difference.
Connected. Take this REPL, brother, and may it serve you well.

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 Sep 27, 2013 6:38 pm

...or type: 'poweroff' or 'reboot' (alternatively: pow[TAB] or reb[TAB]) :D

(of course this only works in 'recent' BBQ releases)
..gnutella..

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

Re: Post your Command line tricks

Unread post by GekkoP » Fri Sep 27, 2013 6:45 pm

I got my own aliases for those: s for "shutdown -h now", r for reboot. I know, lazy bastard.

User avatar
ivanovnegro
Minister of Truth
Posts: 5448
Joined: Wed Oct 17, 2012 11:12 pm

Re: Post your Command line tricks

Unread post by ivanovnegro » Fri Sep 27, 2013 7:26 pm

@kiiroitori: Sure, very nice.
GekkoP wrote:I got my own aliases for those: s for "shutdown -h now", r for reboot. I know, lazy bastard.
Of course, aliases are exactly for this. I have a full list of them. Though it has one disadvantage, sometimes you forget the real commands. :)

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 05, 2013 2:17 pm

Create a file:

Code: Select all

:>filename
Fewer keystrokes than 'touch filename' - unless you're one of those touch typists...Image
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 05, 2013 2:19 pm

machinebacon wrote:Before I duplicate stuff: http://www.ukuug.org/events/linux2003/papers/bash_tips/
+1 for #11 here. Use it all the time.
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 05, 2013 2:42 pm

timeout
A script trick - does that fit here?
You're running a command in the background and want to give it so many seconds to complete before you give up and do some damage control. Lots of answers on places like stackoverflow, some quite complicated. A pretty simple fix worked for me in a specific case yesterday. Here's the generic case, which I haven't aplied to other stuff, so check it out - it might work:

Code: Select all

command_which_might_hang & cmdpid=$!
(sleep 2; kill $cmdpid 2>/dev/null && cleanup_the_mess) &
After2 seconds (or whatever) if the dodgy command still hasn't finished it will be killed, and the cleanup commands run. If it's done and its pid is not available kill will return 1. Don't use this for a very long timeout because that pid might have been allocated to a different process, and get killed...

The original case, which does work, is to test if a fifo is open for writing. (If you try to write to one where noone is reading at the other end, it will just hang.)

Code: Select all

selfpid=$$
(:>/path/to/fifo) & test_pipe=$!
(sleep 2; kill $test_pipe 2>/dev/null && kill -n 13 $selfpid) &
If the pipe is broken a SIGPIPE signal gets sent back to the script which can be trapped and acted on. I was hoping the system would send that SIGPIPE itself, but the command just hung... That stuff did it though.

Image
All code is one.

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 » Sat Oct 05, 2013 3:34 pm

my favorite is still the CLI timer.

Code: Select all

time cat
then to stop it do Ctrl+C to stop the process. What is listed under 'real' is your time.
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.

Post Reply