User avatar
The Captain
Posts: 49
Joined: Mon Aug 27, 2012 5:14 pm
Location: UK East Midlands

Tip for command line / terminal use

Sat Sep 15, 2012 9:10 am

Well since there is no "tips" section I'll have to put such things here.

When you download a software source package they often have rather convoluted file names after you have unpacked it. Often the developer will get a bit carried away with the Dewey decimal version description.

For instance "name_1.20.3_beta_1"

In most cases you could rename it for convenience before make and install but here's a better idea;

1) unpack your new package to your home folder
2) Open a terminal
3) Instead of trying to type the entire excessive name_1.2.3_beta_1 for instance, just type -
cd na*

You can add the asterisk after a couple of characters as a wild card to fill in the rest for you.

It's nothing new but most people coming from Windows won't have used it before even though it works in an MSDOS command line too.

User avatar
joan
Posts: 14270
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Tip for command line / terminal use

Sat Sep 15, 2012 9:27 am

In the same vein you can type a few characters and then press esc esc space which will auto complete if unique. If not unique pressing esc esc tab will show a list of matches.

PocketSized
Posts: 13
Joined: Sat Sep 15, 2012 10:36 am
Location: Norway

Re: Tip for command line / terminal use

Sat Sep 15, 2012 11:33 am

Would'nt pressing the tab-key also auto coplete? It does in "my" terminal.

If this thread catches on, I think it would be a good idea to edit the first post so it contains all the tips and tricks! :)
It's here!

PocketSized
Posts: 13
Joined: Sat Sep 15, 2012 10:36 am
Location: Norway

Re: Tip for command line / terminal use

Sat Sep 15, 2012 12:10 pm

Use the * with care! I guess changing directory is not that big of a deal but using it when you delete stuff could go horribly wrong, since typing rm na* would delete every file in that folder starting with na! Only use * when you need to refer to more than one file.

Using the auto complete option is always better when referring to one file. Pressing the tab key will auto complete for you as long as there is only one file matching what you are typing. I does in "my" terminal any way..

A tips/tricks thread is a good idea. But it needs to be updated frequently whit every good tip/trick in the first post. I guess you volunteered for that by starting this thread The Captain ;)
It's here!

User avatar
The Captain
Posts: 49
Joined: Mon Aug 27, 2012 5:14 pm
Location: UK East Midlands

Re: Tip for command line / terminal use

Sat Sep 15, 2012 4:00 pm

PocketSized wrote:Use the * with care! I guess changing directory is not that big of a deal but using it when you delete stuff could go horribly wrong, since typing rm na* would delete every file in that folder starting with na! Only use * when you need to refer to more than one file.

Using the auto complete option is always better when referring to one file. Pressing the tab key will auto complete for you as long as there is only one file matching what you are typing. I does in "my" terminal any way..

A tips/tricks thread is a good idea. But it needs to be updated frequently whit every good tip/trick in the first post. I guess you volunteered for that by starting this thread The Captain ;)
The trouble with Linux specific console commands is that they won't work via SSH, Webmin or any other form of remote terminal. Mine is a more compatible solution but yes it could do with a warning too.

Yes I'll happily merge all the tips on this subject into the first post when traffic settles along with attribution.

I'll drop a line to the mods about a "Tips" category although I think it would be complete chaos unless it was locked and someone kept it organised and tested them for safety ;) :D

Vassius
Posts: 25
Joined: Sun Jun 03, 2012 7:56 pm

Re: Tip for command line / terminal use

Sun Sep 16, 2012 10:37 am

The Captain wrote: The trouble with Linux specific console commands is that they won't work via SSH, Webmin or any other form of remote terminal. Mine is a more compatible solution but yes it could do with a warning too.
Tab completion works just fine via SSH.

bredman
Posts: 1415
Joined: Tue Jan 17, 2012 2:38 pm

Re: Tip for command line / terminal use

Sun Sep 16, 2012 11:03 am

PocketSized wrote:A tips/tricks thread is a good idea. But it needs to be updated frequently whit every good tip/trick in the first post.
Information belongs in a wiki, discussion belongs in a forum.

Forums are poor places to store long-term useful information.

User avatar
The Captain
Posts: 49
Joined: Mon Aug 27, 2012 5:14 pm
Location: UK East Midlands

Re: Tip for command line / terminal use

Sun Sep 16, 2012 11:14 am

bredman wrote:
PocketSized wrote:A tips/tricks thread is a good idea. But it needs to be updated frequently whit every good tip/trick in the first post.
Information belongs in a wiki, discussion belongs in a forum.

Forums are poor places to store long-term useful information.
Indeed but that's not how the world works as this site proves. Telling new users to RTFM will make them give up.

mikerr
Posts: 2778
Joined: Thu Jan 12, 2012 12:46 pm
Location: UK
Contact: Website

Re: Tip for command line / terminal use

Mon Sep 17, 2012 9:47 pm

PocketSized wrote:Would'nt pressing the tab-key also auto complete? It does in "my" terminal.
Yes, and pressing tab twice will list all options...
Android app - Raspi Card Imager - download and image SD cards - No PC required !

emcsquirreled
Posts: 90
Joined: Sat Aug 18, 2012 1:26 am
Location: Portland, OR USA
Contact: Website

Re: Tip for command line / terminal use

Tue Sep 18, 2012 4:50 pm

mikerr wrote:
PocketSized wrote:Would'nt pressing the tab-key also auto complete? It does in "my" terminal.
Yes, and pressing tab twice will list all options...
Just make sure you are in a bash shell. My Pi defaults to a different shell (when I SSH in, anyway), but typing "bash" fixes this.
Linux -- The operating system with a CLUE (Command Line User Environment)
--
FTC Team 4508
E=MC Squirreled
emcsquirreled.github.com

Joe Schmoe
Posts: 4277
Joined: Sun Jan 15, 2012 1:11 pm

Re: Tip for command line / terminal use

Tue Sep 18, 2012 5:02 pm

The trouble with Linux specific console commands is that they won't work via SSH, Webmin or any other form of remote terminal. Mine is a more compatible solution but yes it could do with a warning too.
Wrong. 'Nuff said.
And some folks need to stop being fanboys and see the forest behind the trees.

(One of the best lines I've seen on this board lately)

Joe Schmoe
Posts: 4277
Joined: Sun Jan 15, 2012 1:11 pm

Re: Tip for command line / terminal use

Tue Sep 18, 2012 5:03 pm

Just make sure you are in a bash shell. My Pi defaults to a different shell (when I SSH in, anyway), but typing "bash" fixes this.
I wonder what shell that was... (even 'ash' has filename completion these days)
And some folks need to stop being fanboys and see the forest behind the trees.

(One of the best lines I've seen on this board lately)

Hiro
Posts: 78
Joined: Fri Dec 30, 2011 11:09 am

Re: Tip for command line / terminal use

Tue Sep 18, 2012 5:35 pm

Another useful tip. If you forget to add sudo at the start of a command that needs it simply type.

Code: Select all

sudo !!
As the next line and this will repeat the last entered command as the root user (or super user if that is the preferred term).

emcsquirreled
Posts: 90
Joined: Sat Aug 18, 2012 1:26 am
Location: Portland, OR USA
Contact: Website

Re: Tip for command line / terminal use

Tue Sep 18, 2012 5:52 pm

Joe Schmoe wrote:I wonder what shell that was... (even 'ash' has filename completion these days)
I'm not really sure what shell it is. Here is what the Pi says:

Code: Select all

$ echo $SHELL
/bin/sh
What is this?
Linux -- The operating system with a CLUE (Command Line User Environment)
--
FTC Team 4508
E=MC Squirreled
emcsquirreled.github.com

User avatar
jojopi
Posts: 3085
Joined: Tue Oct 11, 2011 8:38 pm

Re: Tip for command line / terminal use

Tue Sep 18, 2012 5:58 pm

emcsquirreled wrote:/bin/sh
What is this?
dash. http://gondor.apana.org.au/~herbert/dash/

emcsquirreled
Posts: 90
Joined: Sat Aug 18, 2012 1:26 am
Location: Portland, OR USA
Contact: Website

Re: Tip for command line / terminal use

Tue Sep 18, 2012 6:02 pm

jojopi wrote:dash.
Hmm. Where do I change this? I can do it in my login script, but it seems inefficient to start dash and then use it to load bash... :?
Linux -- The operating system with a CLUE (Command Line User Environment)
--
FTC Team 4508
E=MC Squirreled
emcsquirreled.github.com

User avatar
jojopi
Posts: 3085
Joined: Tue Oct 11, 2011 8:38 pm

Re: Tip for command line / terminal use

Tue Sep 18, 2012 6:09 pm

emcsquirreled wrote:Where do I change this?
"chsh -s /bin/bash".

(Or "sudo nano /etc/passwd" and edit the last field for the user in question.)

User avatar
k4gbb
Posts: 52
Joined: Sun Aug 12, 2012 5:33 am
Location: Dunnellon, FL USA - EL88tx

Re: Tip for command line / terminal use

Tue Sep 18, 2012 6:13 pm

Try editing your passwd file.
It specifies which shell is to be used when the user logs on.

<<Charley>>
The Grass may be greener on the other side of the fence, but it still has to be mowed.

emcsquirreled
Posts: 90
Joined: Sat Aug 18, 2012 1:26 am
Location: Portland, OR USA
Contact: Website

Re: Tip for command line / terminal use

Tue Sep 18, 2012 7:30 pm

k4gbb wrote:Try editing your passwd file.
It specifies which shell is to be used when the user logs on.

<<Charley>>
Thanks!
Linux -- The operating system with a CLUE (Command Line User Environment)
--
FTC Team 4508
E=MC Squirreled
emcsquirreled.github.com

emcsquirreled
Posts: 90
Joined: Sat Aug 18, 2012 1:26 am
Location: Portland, OR USA
Contact: Website

Re: Tip for command line / terminal use

Tue Sep 18, 2012 7:31 pm

Back to terminal tips, you can use the up and down arrows to cycle through previously typed commands. This is similar to !!, but it allows you to go farther back into your command history.
Linux -- The operating system with a CLUE (Command Line User Environment)
--
FTC Team 4508
E=MC Squirreled
emcsquirreled.github.com

thradtke
Posts: 492
Joined: Wed May 16, 2012 5:16 am
Location: Germany / EL

Re: Tip for command line / terminal use

Thu Sep 20, 2012 2:02 pm

emcsquirreled wrote:Back to terminal tips, you can use the up and down arrows to cycle through previously typed commands. This is similar to !!, but it allows you to go farther back into your command history.
Worth noting is the search capability from readline library. CTRL-R does incremental backward search. History is saved, i.e. kept after bash quits.

Also, there are powerful editing commands like CTRL-U/K to chop of everything before/after the cursor. There's a lot to explore, and if you got used to it, you're ready for emacs :-).
Rocket Scientist.

User avatar
RaTTuS
Posts: 10460
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK

Re: Tip for command line / terminal use

Thu Sep 20, 2012 2:18 pm

history can be found in
~/.bash_history

~/ <- means your home directory

cd -
will take you to the last place you cd'ed from

ps axOT list all processes sorted by time
How To ask Questions :- http://www.catb.org/esr/faqs/smart-questions.html
WARNING - some parts of this post may be erroneous YMMV

1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX
Covfefe

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 23709
Joined: Sat Jul 30, 2011 7:41 pm

Re: Tip for command line / terminal use

Thu Sep 20, 2012 3:17 pm

thradtke wrote:
emcsquirreled wrote:Back to terminal tips, you can use the up and down arrows to cycle through previously typed commands. This is similar to !!, but it allows you to go farther back into your command history.
Worth noting is the search capability from readline library. CTRL-R does incremental backward search. History is saved, i.e. kept after bash quits.

Also, there are powerful editing commands like CTRL-U/K to chop of everything before/after the cursor. There's a lot to explore, and if you got used to it, you're ready for emacs :-).
Nobody is EVER ready for EMACS.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed. Here's an example...
"My grief counseller just died, luckily, he was so good, I didn't care."

eccentricdyslexic
Posts: 141
Joined: Thu Jul 18, 2013 6:13 am
Location: Uttoxeter, Staffordshire, UK

Re: Tip for command line / terminal use

Wed Mar 27, 2019 7:16 pm

Been looking for a list of terminal tips, a friend once showed me a tip to list the previous used commands, but I can’t remember it! Any ideas?

gkaiseril
Posts: 653
Joined: Mon Aug 08, 2016 9:27 pm
Location: Chicago, IL

Re: Tip for command line / terminal use

Wed Mar 27, 2019 7:44 pm

'history' works for me in bash. To see them one by one use the up arrow command. One can read more about by using the man history command.

Difference between sh and bash will explain the difference between bash and the shells.

The man command will be with your system even when not connected to the internet. It is a good tool to learn how to use.
f u cn rd ths, u cn gt a gd jb n cmptr prgrmmng.

Return to “Beginners”