Page 1 of 15

Post your Command line tricks

Posted: Sun Sep 22, 2013 2:48 pm
by wuxmedia
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 *

Re: Post your Command line tricks

Posted: Sun Sep 22, 2013 2:54 pm
by DebianJoe

Code: Select all

sudo !!
!! executes last command in bash/zsh.

Re: Post your Command line tricks

Posted: Sun Sep 22, 2013 3:02 pm
by wuxmedia
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$

Re: Post your Command line tricks

Posted: Sun Sep 22, 2013 5:08 pm
by rhowaldt
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 -

Re: Post your Command line tricks

Posted: Sun Sep 22, 2013 8:46 pm
by wuxmedia
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

Re: Post your Command line tricks

Posted: Sun Sep 22, 2013 10:04 pm
by gutterslob

Code: Select all

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

Re: Post your Command line tricks

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

Re: Post your Command line tricks

Posted: Mon Sep 23, 2013 5:06 am
by dkeg
what happened on this date

Code: Select all

calendar

Re: Post your Command line tricks

Posted: Mon Sep 23, 2013 5:42 am
by machinebacon
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/

Re: Post your Command line tricks

Posted: Mon Sep 23, 2013 7:44 am
by wuxmedia
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.

Re: Post your Command line tricks

Posted: Mon Sep 23, 2013 9:09 pm
by ivanovnegro
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

Re: Post your Command line tricks

Posted: Fri Sep 27, 2013 4:37 am
by kiiroitori
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/

Re: Post your Command line tricks

Posted: Fri Sep 27, 2013 5:36 pm
by xaos52
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.

Re: Post your Command line tricks

Posted: Fri Sep 27, 2013 6:38 pm
by machinebacon
...or type: 'poweroff' or 'reboot' (alternatively: pow[TAB] or reb[TAB]) :D

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

Re: Post your Command line tricks

Posted: Fri Sep 27, 2013 6:45 pm
by GekkoP
I got my own aliases for those: s for "shutdown -h now", r for reboot. I know, lazy bastard.

Re: Post your Command line tricks

Posted: Fri Sep 27, 2013 7:26 pm
by ivanovnegro
@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. :)

Re: Post your Command line tricks

Posted: Sat Oct 05, 2013 2:17 pm
by johnraff
Create a file:

Code: Select all

:>filename
Fewer keystrokes than 'touch filename' - unless you're one of those touch typists...Image

Re: Post your Command line tricks

Posted: Sat Oct 05, 2013 2:19 pm
by johnraff
machinebacon wrote:Before I duplicate stuff: http://www.ukuug.org/events/linux2003/papers/bash_tips/
+1 for #11 here. Use it all the time.

Re: Post your Command line tricks

Posted: Sat Oct 05, 2013 2:42 pm
by johnraff
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

Re: Post your Command line tricks

Posted: Sat Oct 05, 2013 3:34 pm
by rhowaldt
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.