Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Looking for cheat sheets
#1
I am new to the world of Linux and I am trying to learn bash shell commands and how to create my own scripts to run. I was wondering if there is a cheat sheet out there that can tell me what the commands mean?

I am trying to learn this without having to bug people too much.

I am looking for something that can show me what the -e means in the command line
 echo -e "${RED}REBOOT REQUIRED!${NOCOLOR}"
Reply
#2
You can use a search engine like bing or google to find a bash cheat sheet.   Which one is best is probably very subjective.

The "-e" echo option causes the echo command enables interpretation of backslash escapes.


Code:
$ echo "\n backslash n"
\n backslash n
$ echo -e "\n backslash n"

backslash n
$

Notice the echo -e example did not print the \n like the first example but instead, it interprets the "\n" by printing a new line.

Reference:

man echo 
man bash
Idea Give a person a fish, and you feed them for a day. Teach a person how to fish, and you feed them for a lifetime. ✝️ Proverbs 4:7 Wisdom is the principal thing; therefore get wisdom: and with all thy getting get understanding.  (Linux Mint 19 XFCE)
Reply
#3
If you want an overview about a command and its options, try this:
Code:
man command  # displays the manual pages for 'command'
info command  # displays the GNU info page for 'command'

Here is a small cheat sheet for starting with the command line:
Code:
cd  # change directory, move to another "folder"
rm  # remove a file
rm -rf  # remove a directory
mv  # move a file or directory from one path to antoher, also used for renamng
cp  # copy a file from one path to another
cp -r  # copy a directory
cat  # concatenate files or streams to a single file or stream

Here are some examples:
Code:
echo "Hi" > test  # overwrite / create file 'test' with the word 'Hi' in it
cat test  # prints content of file 'test' to terminal
cat test > test2  # writes contents of file 'test' to file 'test2'
cat test test2  # prints contents of files 'test' and 'test2' to terminal
command &  # forks 'command' into the background

If you want to get into scripting, you should learn about streams.
There are three streams:
'stdout', which is the standard output of a program, normaly gets printed to the terminal but can be rerouted to files and other programs
'stdin', which is the standard input of a command; It is used when you pipe something into a commans
'stderr', which is the error ouput of a program, it will basically always go to the terminal, even if  'stdout' is rerouted.

How to work with stream:
Code:
command > file  # writes output (stdout) of 'command' to 'file', previous content of 'file' is overwritten
command >> file  # appends ouput (stdout) of 'command' to 'file', previous content of 'file' is still there
command1 | command2  # pipes output (stdout) of 'command1' into input (stdin) of 'command2'

You can experiment with this in multiple ways.
A nice example you can try:
1. Write some text to a file: 'echo Hello World > test-file'
2. Display contents of the file: 'cat test-file'
3. Pipe content of the file into another program: 'cat test-file | base64'
4. Pipe output of other program to a file: 'cat test-file | base64 > test-file2'
Congratualations! You have written something to a file, encoded it to base64 and written that to another file!
If you want to reencode the base64 back into something you can read: 'cat test-file2 | base64 -d'
Reply
#4
Saluton!
A quick way to find programs by a search query is to use the `apropos' command:
Code:
apropos example

If you are getting into scripts and commands, you may want to try fish, as an alternative to bash. It's a different shell, usually available in the repositories.
It makes using the command line rather fast, and has a scripting language that is described by many to be `more sane'.
fishshell.com/

Fish also has help documentation that can provide information about things like `if' and `for' that will help you learn scripting.
Code:
help example

Scripting is often just chaining together existing programs with some conditions. Off the top of my head, these are the most-useful, generally-universal tools who's info pages are well worth a read:
  • grep - ReGex search files and text
  • sed - The stream editor
  • awk - Like sed, more powerful
  • find - look for files
  • tee - read file once, modify in many ways
Quick example:
I wanted a command to find out what removable devices. I searched for `devices' with apropos, before looking at the manpage for `lsblk'. After that I got up the info page for `sed' and wrote this:
Code:
lsblk -lno RM,NAME,SIZE,MOUNTPOINT|sed '/^ 0/d ; s/ 1//'
To make an executable, I put it in a file named `example with a shell-type header:
Code:
#!/bin/sh
lsblk -lno RM,NAME,SIZE,MOUNTPOINT|sed '/^ 0/d ; s/ 1//'
Before copying it into the /usr/bin/ directory and changing the file permissions to make it executable by any user:
Code:
sudo mv example /usr/bin/; sudo chmod 755 /usr/bin/example

Hope that this helps, PM me if you want me to explain anything mentioned!
Lernu, uzu, amu Linukson!
Reply
#5
(08-22-2018, 10:14 PM)deck_luck Wrote: You can use a search engine like bing or google to find a bash cheat sheet.   Which one is best is probably very subjective.

The "-e" echo option causes the echo command enables interpretation of backslash escapes.


Code:
$ echo "\n backslash n"
\n backslash n
$ echo -e "\n backslash n"

backslash n
$

Notice the echo -e example did not print the \n like the first example but instead, it interprets the "\n" by printing a new line.

Reference:

man echo 
man bash

Yes, at this point MAN and Google are your best friends. Of corse we are too.
anytime you want to learn more about a command, like echo, touch, mv, cp, rm,  and the likes. just use man. <man echo> usually man has info on it. If not, Google it.

also Ubuntu has a good wiki page. But Arch has the best wiki IMHO
and then there is this new knowledge factory. (Wink)
A computer without Microsoft is like a piece of chocolate cake without ketchup and mustard.


Telegram @eliasw4u
Reply
#6
The -e command just refers to Exit as far as I'm aware.
Reply
#7
This helped me more than 'man' or 'help'. its called cheat 2.2.3 and once up and running you can create your own cheat sheets inside bash in terms that you will understand.
"Cheat is an interactive cheat-sheet application released under GNU General Public License for Linux Command line users which serves the purpose of showing, use cases of a Linux command with all the options and their short yet understandable function."

https://www.tecmint.com/cheat-command-li...nux-users/
Reply
#8
I wrote a short Medium article on getting help for bash  https://medium.com/@tomsfccemail/help-me...74950c77d4
It covers man, info, help and cheat.sh

As for bash cheat sheets, I collated a number of resources and tried to fit them into the basic professional cert LPIC-1  https://github.com/appijumbo/Linux-LPIC-1/wiki   see '999 References' for cheat sheets Smile
Reply
#9
Joe has some great bash videos on his youtube channel
Reply
#10
(08-29-2018, 07:45 PM)Hozee78 Wrote: This helped me more than 'man' or 'help'. its called cheat 2.2.3 and once up and running you can create your own cheat sheets inside bash in terms that you will understand.
"Cheat is an interactive cheat-sheet application released under GNU General Public License for Linux Command line users which serves the purpose of showing, use cases of a Linux command with all the options and their short yet understandable function."

https://www.tecmint.com/cheat-command-li...nux-users/

Thank you for this. This has been very helpful and I like how I can add my own notes to the cheat pages. Makes things a lot easier.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)