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

Code: Select all

sh eyes
..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 » Sun Oct 06, 2013 11:22 am

^ hahahahaha fucking nice
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
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 » Sun Oct 06, 2013 3:26 pm

ivanovnegro wrote:
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. :)
how true. Confession, there have been times I have to open my alias file to verify the command :)

Work hard; Complain less

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 » Sun Oct 06, 2013 3:42 pm

^ no need to 'cat ~/ .bash_aliases'
try

Code: Select all

alias -p
"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 » Sun Oct 06, 2013 3:50 pm

You can also use "which" or "alias" to see a single alias.

Code: Select all

% which ver    
ver: aliased to apt-cache policy
I have an alias for editing my aliases. :)

Code: Select all

% alias aka
aka='nano ~/.zsh_aliases'

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 Oct 06, 2013 5:38 pm

^ hihi, i have aliases to edit my bashrc too :)
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
ivanovnegro
Minister of Truth
Posts: 5449
Joined: Wed Oct 17, 2012 11:12 pm

Re: Post your Command line tricks

Unread post by ivanovnegro » Sun Oct 06, 2013 5:49 pm

wuxmedia wrote:^ no need to 'cat ~/ .bash_aliases'
try

Code: Select all

alias -p
Great.

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 » Sun Oct 06, 2013 5:52 pm

or

Code: Select all

alias
Connected. Take this REPL, brother, and may it serve you well.

she_dyed
Troll
Posts: 4
Joined: Tue Sep 24, 2013 6:08 am

Re: Post your Command line tricks

Unread post by she_dyed » Sun Oct 06, 2013 6:00 pm

Need to make quick notes on that special command you just ran? Hit the arrow key up, enclose in quotes, and save in a file called RREADME. (the double RR will prevent it from getting overwritten by an accidental unzip)

echo 'conky -c myweatherrc' >> RREADME

You can add notes prior e.g. a clear line and a comment

echo ' ' >> RREADME
echo ' command for conky to display my local weather:' >> RREADME

Use your favorite editor to improve it. Save the file to a USB before your upgrade. I use it to recall steps on how to set up my dual screens on proprietary nvidia drivers.

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 Oct 06, 2013 6:29 pm

Along with useful aliases, I often scratch some rudimentary functions into my .bashrc...this one probably gets more use than anything else I have:

Code: Select all

extract () {
    # A check for flags on compressed files.
    if [ -f $1 ] ; then
	case $1 in
	    *.tar.bz2)
		tar -xvjf $1
		;;
	    *.tar.gz)
		tar -xvzf $1
		;;
	    *.bz2)
		bunzip2 $1
		;;
	    *.rar)
		unrar x $1
		;;
	    *.gz)
		gunzip $1
		;;
	    *.tar)
		tar -xf $1
		;;
	    *.tbz2)
		tar -xvjf $1
		;;
	    *.tgz)
		tar -xvzf $1
		;;
	    *.zip)
		unzip $1
		;;
	    *.Z)
		uncompress $1
		;;
	    *)
		echo "$1 is not valid for extraction"
		;;
	esac
    else
	echo "$1 is not a valid file"
    fi
}
|>>BBQ Roaster, Alpha Branch<< | >> clinky << | >> X11 must die << |
Thanks BASIC

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 » Sun Oct 06, 2013 7:40 pm

^ neat, me likey.
who needs a text editor?

Code: Select all

$ cat > Textfile.txt << EOF
(type your textfile, no need for quotes, or anything. Once finished type;
EOF
BTW the 'EOF' can be replaced by almost anything, but 'EOF' doesn't tend to crop up too often.
"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 » Sun Oct 06, 2013 7:53 pm

^^ Debian has "unp" which can unpack almost any archive format automatically. I think it's already installed on most bbq spins (even Bass and Tiny). The GRML zsh config also has a built-in unpack function.

If you use the tar commands at the command line (or in a script like Joe's), if you put all the letter options in a "clump" right after the "tar" command, you don't need a dash in front of them.

Code: Select all

tar -xzvf tarfile
is equivalent to

Code: Select all

tar xzvf tarfile
Finally, this is one place where I actually believe it is a good idea to learn the direct commands for a few common formats, just in case you find yourself on a system with no alias and no unp package. Or in front of a bomb.

Image

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 Oct 06, 2013 7:59 pm

^^ when I wrote my little addition, this very comic came to mind. :D
|>>BBQ Roaster, Alpha Branch<< | >> clinky << | >> X11 must die << |
Thanks BASIC

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

Re: Post your Command line tricks

Unread post by ivanovnegro » Sun Oct 06, 2013 8:12 pm

Great comic Pid and yes, unp is king.

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 » Sun Oct 06, 2013 8:14 pm

I haven't heard of unp...
[mnemonic]Xtract Zese Vucking Files[/mnemonic]
"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 » Sun Oct 06, 2013 8:35 pm

DJ covered "autojump" in a #! post -- it's a handy way to mark directories for later so you can easily "cd" into them. I just looked at installing it, and it wanted to pull in 17M of python3.3. No thanks.

I've been using some functions from a blog someone mentioned (I forget where) -- they use symlinks in a hidden directory in your home to accomplish the same thing. I have the functions in my .zsh_aliases file, but they work with bash too.

Code: Select all

export MARKPATH=$HOME/.marks
function go { 
    cd -P "$MARKPATH/$1" 2>/dev/null || echo "no such mark: $1"
}
function mk { 
    mkdir -p "$MARKPATH"; ln -s "$(pwd)" "$MARKPATH/$1"
}
function unmk { 
    rm "$MARKPATH/$1"
}
function mks {
    ls -o "$MARKPATH" | awk '/^lrw/ { print $8,$9,$10 }'
}
When you are in a directory you want to remember, type "mk <name>" and a symlink is created to that directory, with the name you give. Later, just type "go <name>" to go to the marked directory. "mks" lists all the named directories, and "unmk <name>" removes a symlink. The original author called these functions "mark" "jump" "unmark" and "marks" but I'm lazy so I used shorter names.

If you are using zsh, you can add the following functions to your .zshrc to give you tab autocomplete for the "go" and "unmk" functions. There is a way to do this in bash, but I don't have that in front of me right now.

Code: Select all

function _completemarks {
    reply=($(ls $MARKPATH))
}

compctl -K _completemarks go
compctl -K _completemarks unmk
(edit) found the blog with the bash autocomplete functions. http://jeroenjanssens.com/2013/08/16/qu ... -line.html

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 Oct 06, 2013 9:01 pm

that is very cool pidsley.
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
GekkoP
Emacs Sancho Panza
Posts: 5878
Joined: Tue Sep 03, 2013 7:05 am

Re: Post your Command line tricks

Unread post by GekkoP » Sun Oct 06, 2013 9:08 pm

Yes, very useful pidsley, thank you.

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 Oct 06, 2013 9:17 pm

Very clean answer pidsley. I love it.
|>>BBQ Roaster, Alpha Branch<< | >> clinky << | >> X11 must die << |
Thanks BASIC

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 6:17 am

'help alias' doesn't seem to indicate any difference between 'alias' and 'alias -p'.
Something subtle?
All code is one.

Post Reply