fix(guide): simplify directory structure

This commit is contained in:
Mrugesh Mohapatra
2018-10-16 21:26:13 +05:30
parent f989c28c52
commit da0df12ab7
35752 changed files with 0 additions and 317652 deletions

View File

@ -0,0 +1,38 @@
---
title: Bash Cat
---
## Bash Cat
Cat is one of the most frequently used commands in Unix operating systems.
Cat is used to read a file sequentially and print it to the standard output.
The name is derived from its function to con**cat**enate files.
### Usage
```bash
cat [options] [file_names]
```
Most used options:
* `-b`, numer non-blank output lines
* `-n`, number all output lines
* `-s`, squeeze multiple adjacent blank lines
* `-v`, display nonprinting characters, except for tabs and the end of line character
### Example
Print in terminal the content of file.txt:
```bash
cat file.txt
```
Concatenate the content of the two files and display the result in terminal:
```bash
cat file1.txt file2.txt
```
#### More Information:
* Wikipedia: https://en.wikipedia.org/wiki/Cat_(Unix)

View File

@ -0,0 +1,18 @@
---
title: Bash cd
---
## Bash command: cd
**Change Directory** to the path specified, for example `cd projects`.
There are a few really helpful arguments to aid this:
- `.` refers to the current directory, such as `./projects`
- `..` can be used to move up one folder, use `cd ..`, and can be combined to move up multiple levels `../../my_folder`
- `/` is the root of your system to reach core folders, such as `system`, `users`, etc.
- `~` is the home directory, usually the path `/users/username`. Move back to folders referenced relative to this path by including it at the start of your path, for example `~/projects`.
- `~[number]` will cd to that entry from the output of `dirs` directories can be pushed on poped to the 'dirs' stack using `pushd` and `popd` respectively.
- Typing only `cd` will move to the home directory works same as `cd ~`
### More Information:
* [Wikipedia](https://en.wikipedia.org/wiki/Cd_(command))

View File

@ -0,0 +1,11 @@
---
title: Bash chmod
---
## Bash command: chmod
**Change the permissions of a File/Directory** ,for example `chmod u+x hello.py`.(Gives the user the permission to execute the file)
### More Information:
* [Wikipedia](https://en.wikipedia.org/wiki/Chmod)

View File

@ -0,0 +1,37 @@
---
title: Bash Copy
---
## Bash command: cp
`cp` is used to copy files and directories.
It can be used to copy a file, copy a file to a directory, or copy a directory.
### Usage
```
cp [options] source target
```
Commonly used options:
* `-p` (preserve) - used to preserve time of the last data modification, time of last access, ownership, and permissions of the source for the target
* `-R or -r` (recursive) - used to recursively copy directories
### Examples
#### Copy a file
```bash
cp somefile.txt newfile.txt
```
Run `ls` and you will see you have a new file called `newfile.txt`
#### Copy a file to a directory
```bash
cp -p somefile.txt your/target/directory
```
`cd` into the target directory, `ls`, and you will see a copy of your file. The `-p` option is added to preserve the files attributes.
#### Copy multiple files to a directory
```bash
cp file1.txt file2.txt fileN.txt your/target/directory
```
`cd` into the target directory, `ls`, and you will see copies of all of the files.
#### Copy a directory
```bash
cp -R directory/to/copy your/target/directory
```
`cd` into the target directory and `ls` to see your directory. The `-R` option is added to recursively copy everything in the directory.
### More Information
* run `man cp` to get a list of all options for this command
* [Wikipedia](https://en.wikipedia.org/wiki/Cp_(Unix))

View File

@ -0,0 +1,46 @@
---
title: Bash Head
---
## Bash command: head
Head is used to print the first ten lines (by default) or any other amount specified of a file or files.
Cat is used to read a file sequentially and print it to the standard output. <br>
ie prints out the entire contents of the entire file. - that is not always necessary, perhaps you just want to check the contents of a file to see if it is the correct one, or check that it is indeed not empty.
The head command allows you to view the first N lines of a file.
if more than on file is called then the first ten lines of each file is displayed, unless specific number of lines are specified.
Choosing to display the file header is optional using the option below
### Usage
```bash
head [options] [file_name(s)]
```
Most used options:
* `-n N`, prints out the first N lines of the file(s)
* `-q`, doesn't print out the file headers
* `-v`, always prints out the file headers
### Example
```bash
head file.txt
```
Prints in terminal the first ten lines of file.txt (default)
```bash
head -n 7 file.txt
```
Prints in terminal the first seven lines of file.txt
```bash
head -q -n 5 file1.txt file2.txt
```
Print in terminal the first 5 lines of file1.txt, followed by the first 5 lines of file2.txt
### More Information:
* [Wikipedia](https://en.wikipedia.org/wiki/Head_(Unix))

View File

@ -0,0 +1,40 @@
---
title: Bash ls
---
## Bash ls
`ls` is a command on Unix-like operating systems to list contents of a directory, for example folder and file names.
### Usage
```bash
cat [options] [file_names]
```
You can list the items in any directory without even entering the directory. Consider you are in a directory with folders- Test1,Test2. You're in the parent directory you can list all files in Test1 as follows-
`ls Test1`
Most used options:
* `-a`, all files and folders, including ones that are hidden and start with a `.`
* `-l`, List in long format
* `-G`, enable colorized output.
* `-s`, List File Size.
### Example:
List files in `freeCodeCamp/guide/`
```bash
ls ⚬ master
CODE_OF_CONDUCT.md bin package.json utils
CONTRIBUTING.md gatsby-browser.js plugins yarn.lock
LICENSE.md gatsby-config.js src
README.md gatsby-node.js static
assets gatsby-ssr.js translations
```
#### More Information:
* [Wikipedia](https://en.wikipedia.org/wiki/Ls)

View File

@ -0,0 +1,32 @@
---
title: Bash Man
---
## Man
Man, the abbreviation of **man**ual, is a bash command used to display on-line reference manuals of the given command.
Man displays the reletive man page (short for **man**ual **page**) of the given command.
### Usage
```bash
man [options] [command]
```
Most used options:
* `-f`, print a short description of the given command
* `-a`, display, in succession, all of the available intro manual pages contained within the manual
### Example
Display the man page of ls:
```bash
man ls
```
#### More information:
* Wikipedia: https://en.wikipedia.org/wiki/Man_page

View File

@ -0,0 +1,22 @@
---
title: Bash mkdir
---
## Bash command: mkdir
**Creates a directory**
```
mkdir directory_name
```
Make directory(ies) with the provided name if they do not already exist.
Commonly used options:
- `-p` no error if existing, make parent directories as needed.
- `-v` prints message for each created directory.
Let's say we need to create a directory `dir` in the path `a/b/c/dir`, but directory `b` and `c` don't exist. In this case, `mkdir -p a/b/c/dir` will create the missing directories in the path.
### More Information:
* [Wikipedia - Mkdir](https://en.wikipedia.org/wiki/Mkdir)

View File

@ -0,0 +1,21 @@
---
title: Bash mv
---
## Bash command: mv
**Moves files and folders.**
```
mv source target
mv source ... directory
```
The first argument is the file you want to move, and the second is the location to move it to. It can also be used to rename a file, by inputting 2 file names as parameters, like so: `mv originalFilename.txt newFilename.txt`
Commonly used options:
- `-f` to force move them and overwrite files without checking with the user.
- `-i` to prompt confirmation before overwriting files.
### More Information:
* [Wikipedia](https://en.wikipedia.org/wiki/Mv)

View File

@ -0,0 +1,22 @@
---
title: Bash Redirection
---
## Bash Redirection
One of the most powerful features of bash (and other shells that support similar syntax) is output and input redirection via pipes and concatination symbols. To start simply the problem of appending a sting to a file is considered. One could open the file in a terminal based editor such as Vim or Nano and manually paste the line in, though this is a bit tedious. Further more, what if one wanted to take the output of one command, say ' $echo 'hi' ' and put it into a file? Again, this could be done via a copy and paste, though this would get progressively more tedious if it had to be done repeatedly and this is not scriptable or automateable so insead something like the '>' or '>>' symbols can be used. With the previous examlpe this may look like:
echo 'hi' > output.txt
or
echo 'hi' >> output.txt
The difference between the two is a single '>' will overwrite the destination file with the input while a '>>' will append the input to the destinion file. Interestingly, the destination need not be a file for example say you had a simple program 'add' which takes two, comma delimited integers as input from the user and output the sum. Normally runnig 'add' would wait for input from the user though using a file that contains valid input this could be automated. Say "input.txt" is a text file containing "1,2" running:
input.txt > add
should output '3'
Finally, and most powerful of all, is the pipe "|" which can be used to take a running programs output and 'pipe' it into another program. For example:
sort textfile.txt | uniq
will first sort each line in the file alpahabetically and then print only the unique entries. This is only scratching the surface of the massive power of pipes though.

View File

@ -0,0 +1,15 @@
---
title: Bash rm
---
## Bash command: rm
**Delete a File/Directory** ,for example `rm hello`.
There are few commonly used arguments:
- `r` , means to recursively delete all the folders inside a directory.
- `f` , means to forcefully delete anything folder or file.
### More Information:
* [Wikipedia](https://en.wikipedia.org/wiki/Rm_(Unix))

View File

@ -0,0 +1,15 @@
---
title: Bash ssh
---
## Bash command: ssh
**Used to connect to a remote computer** ,for example `ssh 123.456.789.012` will try to establish a connection with that host. The
address of the remote computer can be provided using an IP address or, if provided, an identifier.
If the remote computer requires user login, the form `ssh username@remote_address` can be used, which will then prompt for the user
password on successful connection.
### More Information:
* [Wikipedia](https://en.wikipedia.org/wiki/Secure_Shell)

View File

@ -0,0 +1,26 @@
---
title: Bash touch
---
## Bash command: touch
**Change timestamps of files.**
```
touch [options] filename
```
Creates empty file if not exists or modify times of existing files to current time.
Commonly used options:
- `-t` change timestamp to specific date ((YYYYMMDDHHMM.SS)) instead of current time.
- `-r` use timestamp from first file to second file.
Examples:
```
touch -t YYYYMMDDHHMM.SS filename
touch -r file1 file2
```
### More Information:
* [Man pages](http://man7.org/linux/man-pages/man1/touch.1.html)

View File

@ -0,0 +1,64 @@
---
title: Bash
---
## What is Bash?
<a>Bash</a> (short for Bourne Again SHell) is a Unix shell, and a command language interpreter. A shell is simply a macro processor that executes commands. It's the most widely used shell packaged by default for most Linux distributions, and a successor for the Korn shell (ksh) and the C shell (csh).
Many things that can be done Linux operating system can be done via command line. Some examples are...
* Editing files
* Adjusting the volume of the operating system
* Fetching web pages from the internet
* Automating work you do every day
You can read more about bash <a href="https://www.gnu.org/software/bash/">here</a>, via the <a href="https://www.gnu.org/software/bash/manual/html_node/index.html#SEC_Contents">GNU Documentation</a>, and via the <a href="http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html#toc10">tldp guide</a>.
## Using bash on the command line (Linux, OS X)
You can start using bash on most Linux and OS X operating systems by opening up a terminal. Let's consider a simple hello world example. Open up your terminal, and write the following line (everything after the $ sign):
```
zach@marigold:~$ echo "Hello world!"
Hello world!
```
As you can see, we used the echo command to print the string "Hello world!" to the terminal.
## Writing a bash script
You can also put all of your bash commands into a .sh file, and run them from the command line. Say you had a bash script with the following contents:
```
#!/bin/bash
echo "Hello world!"
```
It's worth noting that first line of the script starts with `#!`. It is a special directive which Unix treats differently.
#### Why did we use #!/bin/bash at the beginning of the script file?
That is because it is a convention to let the interactive shell know what kind of interpreter to run for the program that follows. The first line tells Unix that the file is to be executed by /bin/bash. This is the standard location of the Bourne shell on just about every Unix system. Adding #!/bin/bash as the first line of your script, tells the OS to invoke the specified shell to execute the commands that follow in the script.
`#!` is often referred to as a "hash-bang", "she-bang" or "sha-bang".
Though it is only executed if you run your script as an executable. For example, when you type `./scriptname.extension`, it will look at the top line to find out the interpreter, whereas, running the script as `bash scriptname.sh`, first line is ignored.
Then you could run the script like so:
For make file executable you should call this command under sudo chmod +x "filename".
```
zach@marigold:~$ ./myBashScript.sh
Hello world!
```
The script only has two lines. The first indicates what interpreter to use to run the file (in this case, bash). The second line is the command we want to use, echo, followed by what we want to print which is "Hello World".
Sometimes the script won't be executed, and the above command will return an error. It is due to the permissions set on the file. To avoid that use:
```
zach@marigold:~$ chmod u+x myBashScript.sh
````
And then execute the script.
### More Information:
* Wikipedia: https://en.wikipedia.org/wiki/Bash_(Unix_shell)
* tldp.org Guide to Bash: http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html#toc2
* gnu.org Bash manual: https://www.gnu.org/software/bash/manual/html_node/index.html#SEC_Contents
* Shell scripting tutorial to get started: https://www.shellscript.sh/