Shell Cheat Sheet: Difference between revisions

From XPUB & Lens-Based wiki
(Created page with "{{Null/Shell}}")
 
No edit summary
Line 1: Line 1:
{{Null/Shell}}
=Shell Cheat Sheet=
<code>cd</code> - change directory
 
<code>pwd</code> - print working directory
 
<code>ls</code> - list directory
 
<code>rm</code> - remove file or directory
 
<code>cp</code> - copy file or directory
 
<code>mv</code> - move or change name of file or directory
 
<code>cat</code> - concatenate print they content
 
<code>echo</code> - repeats what is written after
 
=== meta characters ===
Meta Characters are characters that have special meaning within the terminal
 
* <code>~</code> the tilde stands for the user's home. <code>cd ~/</code> change directory to home
* <code>.</code> dot stands for '''this''' directory. <code>ls .</code> list this directory
* <code>..</code> dot dot stands for '''the parent directory''' to this directory. <code>cp myfile.jpg ..</code> copy myfile.jpg to the parent directory
* <code>*</code> asterisk is a wildcards which represents zero or more characters <code>ls P*.jpg</code> will list all the files, in the current directory, that begin with P and end with .jpg
* <code>\</code> backslash it is a literal character. It escape the meta value of the meta-characters and display them only as literal characters. <code>echo Foo \*</code> will output <code>Foo *</code> If \ wasn't there it would output all the files in that directory.
 
=== man pages ===
'''man pages are manuals of program.''' They tells you what the program is, what it can do and how.
 
<code>man df</code> show the manual for the program '''df''' that is used to display the free disk space
 
Can you find out how to display the output from df in a human readable format?
 
 
==pipe==
'''A pipes (" | ") sends the output of one program to the input of another program'''.
 
<code>echo "my sentence"| wc</code> the echoed sentence "my sentence" is ''pipped'' into the program wc which counts the number of lines, words, and characters
 
==write==
<code>></code> Writes the output of a command to a file, rather than to print on terminal.
 
<code>df > df_output.txt </code> redirect the content of <code> man dfM </code> to a file called df_output.txt
 
If the said file doesn't exit it will create it, if it already exists it will overwrite its contents/
 
==append==
<code>>></code> appends the output of a command to a file, without overwriting the original file.
<code> echo 'also add this' >> df_output.txt </code> will add 'also add this' to the contents of df_output.txt
 
==package managers==
Package managers like <code>apt-get</code> and <code>aptitude</code> (on Debian/Ubuntu Linux distributions) and Homebrew and MacPorts on Mac, allow more (command-line, but not only) programs, than the ones that come with the operating, to be installed on our system.

Revision as of 15:06, 25 October 2016

Shell Cheat Sheet

cd - change directory

pwd - print working directory

ls - list directory

rm - remove file or directory

cp - copy file or directory

mv - move or change name of file or directory

cat - concatenate print they content

echo - repeats what is written after

meta characters

Meta Characters are characters that have special meaning within the terminal

  • ~ the tilde stands for the user's home. cd ~/ change directory to home
  • . dot stands for this directory. ls . list this directory
  • .. dot dot stands for the parent directory to this directory. cp myfile.jpg .. copy myfile.jpg to the parent directory
  • * asterisk is a wildcards which represents zero or more characters ls P*.jpg will list all the files, in the current directory, that begin with P and end with .jpg
  • \ backslash it is a literal character. It escape the meta value of the meta-characters and display them only as literal characters. echo Foo \* will output Foo * If \ wasn't there it would output all the files in that directory.

man pages

man pages are manuals of program. They tells you what the program is, what it can do and how.

man df show the manual for the program df that is used to display the free disk space

Can you find out how to display the output from df in a human readable format?


pipe

A pipes (" | ") sends the output of one program to the input of another program.

echo "my sentence"| wc the echoed sentence "my sentence" is pipped into the program wc which counts the number of lines, words, and characters

write

> Writes the output of a command to a file, rather than to print on terminal.

df > df_output.txt redirect the content of man dfM to a file called df_output.txt

If the said file doesn't exit it will create it, if it already exists it will overwrite its contents/

append

>> appends the output of a command to a file, without overwriting the original file. echo 'also add this' >> df_output.txt will add 'also add this' to the contents of df_output.txt

package managers

Package managers like apt-get and aptitude (on Debian/Ubuntu Linux distributions) and Homebrew and MacPorts on Mac, allow more (command-line, but not only) programs, than the ones that come with the operating, to be installed on our system.