Learning to use the bash command line

Vince53

Junior Member
Oct 22, 2009
3,011
599
71
Mexico
Visit site
✟37,294.00
Country
Mexico
Faith
Baptist
Marital Status
Married
Politics
US-Republican
Folks, "bash" is a command-line program in Linux. In early August, it will be introduced to Windows 10. I am struggling to learn how to use it, although (being a geek) it is interesting.

If you don't know what I'm talking about, in your Linux program, find "Terminal." That will get you to the bash command line.

Since no one has written "Bash for Dummies," elementary suggestions are appreciated.
 

elytron

Well-Known Member
Oct 5, 2008
467
194
California
✟290,767.00
Country
United States
Faith
Christian
Marital Status
Single
Folks, "bash" is a command-line program in Linux. In early August, it will be introduced to Windows 10. I am struggling to learn how to use it, although (being a geek) it is interesting.

If you don't know what I'm talking about, in your Linux program, find "Terminal." That will get you to the bash command line.

Since no one has written "Bash for Dummies," elementary suggestions are appreciated.

Some times I use the Terminal on Linux. The Command Line is a power full tool.

One basic example that I will share, to quickly install software on Ubuntu. Is the "sudo apt-get install" command. I find it faster than the graphical software centers. Just open a Terminal and type "sudo apt-get install packagename" replace "packagename" with the name of the package you wish to install.

It will prompt you for your password, then apt will download the packages from the Ubuntu software repository, and install them.

If you wish to remove the same package then "sudo apt-get remove packagename" should work.

Use some caution though, with some command examples posted on the Internet by malicious persons. Some malicious commands can delete your entire home folder and hard drive.
 
  • Like
Reactions: Vince53
Upvote 0

Vince53

Junior Member
Oct 22, 2009
3,011
599
71
Mexico
Visit site
✟37,294.00
Country
Mexico
Faith
Baptist
Marital Status
Married
Politics
US-Republican
Use some caution though, with some command examples posted on the Internet by malicious persons. Some malicious commands can delete your entire home folder and hard drive.

Wow! Thanks for the warning.
 
Upvote 0

Vince53

Junior Member
Oct 22, 2009
3,011
599
71
Mexico
Visit site
✟37,294.00
Country
Mexico
Faith
Baptist
Marital Status
Married
Politics
US-Republican
I feel ridiculous, teaching readers how to use Bash when I don't understand it myself (yet). But let's give it a go.

Find "Terminal" in your Linux system and open it. It will give you the bash command line. Make sure that the line ends in a $. That means that none of your commands can change your system. If your command line ends in #, you need to get out. Something is wrong, and you have the ability to really foul yourself up.

Here are some harmless commands for getting information. Remember that these commands are case-sensitive:

pwd Print working directory

ls List files and directories

cd Change directory

ls -l List the files in the working directory in long format

ls /bin List the files in the bin directory, or in any other directory specified

less --help opens a list of possible less commands

cd /home takes you to the home file. The user is allowed to use this file.

cat /etc/shells opens a list of shells available on your system..Huh? Bash is a "shell." If you have bash, then you also have a simpler shell called "sh." You probably have other shells as well.
 
Upvote 0

Vince53

Junior Member
Oct 22, 2009
3,011
599
71
Mexico
Visit site
✟37,294.00
Country
Mexico
Faith
Baptist
Marital Status
Married
Politics
US-Republican
Okay, I need some help.

Typing vim :syntax enable onto the bash command line opens a word processor. It gives me a list of options:

The program 'vim' can be found in the following packages:
* vim
* vim-gnome
* vim-tiny
* vim-athena
* vim-athena-py2
* vim-gnome-py2
* vim-gtk
* vim-gtk-py2
* vim-gtk3
* vim-gtk3-py2
* vim-nox
* vim-nox-py2
Try: sudo apt install <selected package>

If I understand correctly, I only want one of these packages. If so, which one?
 
Upvote 0

Vince53

Junior Member
Oct 22, 2009
3,011
599
71
Mexico
Visit site
✟37,294.00
Country
Mexico
Faith
Baptist
Marital Status
Married
Politics
US-Republican
"Bash on Fire" is one of several harmless Bash programs that don't accomplish anything useful. They don't work on every computer. But this harmless program makes multi-colored symbols scroll across your terminal.

Open a terminal and cut and paste this into it, then press Enter. Let me know if it works on your rig. I've tried three others that don't work on mine.

#!/bin/bash
X=`tput cols` Y=`tput lines` e=echo M=`eval $e {1..$[X*Y]}` P=`eval $e {1..$X}`;
B=(' ' '\E[0;31m.' '\E[0;31m:' '\E[1;31m+' '\E[0;33m+' '\E[1;33mU' '\E[1;33mW');
$e -e "\E[2J\E[?25l" ; while true; do p=''; for j in $P; do p=$p$[$RANDOM%2*9];
done;O=${C:0:$[X*(Y-1)]}$p;C='' S='';for p in $M;do # _-=[ BruXy.RegNet.CZ ]=-_
read a b c d <<< "${O:$[p+X-1]:1} ${O:$[p+X]:1} ${O:$[p+X+1]:1} ${O:$[p+X+X]:1}"
v=$[(a+b+c+d)/4] C=$C$v S=$S${B[$v]}; done; printf "\E[1;1f$S"; done # (c) 2012
 
Upvote 0

Vince53

Junior Member
Oct 22, 2009
3,011
599
71
Mexico
Visit site
✟37,294.00
Country
Mexico
Faith
Baptist
Marital Status
Married
Politics
US-Republican
Okay, I didn't set a password when I set up Linux, but now I need one. Open the terminal and type this into the command line:

The traditional method to set a password is this command:
sudo passwd [user]
Where [user] is replaced with your username.
It should let you set a password without prompting for one since none currently exists.

My first successful Linux improvement with Bash!
 
Upvote 0
This site stays free and accessible to all because of donations from people like you.
Consider making a one-time or monthly donation. We appreciate your support!
- Dan Doughty and Team Christian Forums

skalle

Delete system32.
Jun 17, 2016
167
86
USA
✟17,101.00
Faith
Atheist
Marital Status
Married
Politics
US-Green
Okay, I need some help.

Typing vim :syntax enable onto the bash command line opens a word processor. It gives me a list of options:

The program 'vim' can be found in the following packages:
* vim
* vim-gnome
* vim-tiny
* vim-athena
* vim-athena-py2
* vim-gnome-py2
* vim-gtk
* vim-gtk-py2
* vim-gtk3
* vim-gtk3-py2
* vim-nox
* vim-nox-py2
Try: sudo apt install <selected package>

If I understand correctly, I only want one of these packages. If so, which one?

Go with vim. Any necessary dependencies will be handled by apt automatically. Note: vim is not a word processor. It is a text editor usually used to edit code, and the learning curve is very steep. Also, take it from a coder: emacs is better. ;)
 
  • Like
Reactions: Vince53
Upvote 0

skalle

Delete system32.
Jun 17, 2016
167
86
USA
✟17,101.00
Faith
Atheist
Marital Status
Married
Politics
US-Green
Skalle, you are correct. I doubt that I'll be using Vim. But what is an "emac"?
Emacs is a venerable text editor created by the founder of the GNU Project himself, Richard Stallman (RMS). There is a long-standing feud among Unix coders over whether one should use vi(m) or emacs. Indeed, there is a way to use vim keybindings in emacs, which is done by enabling "evil mode." The whole thing has turned into something of a big joke; there's even a Church of Emacs. I go with emacs. :p
 
  • Like
Reactions: Vince53
Upvote 0
This site stays free and accessible to all because of donations from people like you.
Consider making a one-time or monthly donation. We appreciate your support!
- Dan Doughty and Team Christian Forums

skalle

Delete system32.
Jun 17, 2016
167
86
USA
✟17,101.00
Faith
Atheist
Marital Status
Married
Politics
US-Green
Don't get frustrated if it doesn't make a lot of sense. You're probably better served by something like gedit if you need to edit text. Emacs is something of an acquired taste, and honestly I don't know many coders who still use it. Personally I use Atom nowadays.
 
Upvote 0

TheGoodLight

Well-Known Member
Site Supporter
Aug 1, 2016
883
639
39
PA
✟412,781.00
Country
United States
Faith
Non-Denom
Marital Status
Single
Ah... bash. Stuff I've studied for my Linux Essentials certification, and will keep studying for future certs. :floppy:

Kinda wish I had a virtual terminal set up in which I could try out various bash commands and not actually blow anything up... !
 
Upvote 0
This site stays free and accessible to all because of donations from people like you.
Consider making a one-time or monthly donation. We appreciate your support!
- Dan Doughty and Team Christian Forums

Qyöt27

AMV Editor At Large
Apr 2, 2004
7,879
573
38
St. Petersburg, Florida
✟81,859.00
Faith
Methodist
Marital Status
Single
Politics
US-Others
Really, just stay away from mv and rm and most of the threat is gone (not that the GNU userland has anything to do with the scripting language in the shell, though). What remains is not to redirect to an existing file, or for those tools that support it (sed), avoiding in-place writing.
 
Upvote 0