On Github JoaoFCosta / BashIntroduction
A lightweight introduction to bash commands.
Prints the working directory.
List files and folders in the current directory.
Flag Description -a List all files and all folders. -l Long format.Change the working directory.
.. Parent directory. ~ Home directory.Create a new directory.
Flag Description -p Make parents.Remove a directory.
Flag Description -p Remove parents.Move a folder.
Copy directory to another place.
Flag Description -r Copy directories recursively.Create an empty file.
Copy a file.
Move a file.
Remove a file.
Concatenate and print a file.
Flag Description -n Number the output lines, starting at 1.View, navigate and search a file.
Flag Description --help Summary of less commands.Display first lines of a file.
Flag Description -n N Display first N lines.Display the last part of a file.
Flag Description -n N Display last N lines.Search for a pattern in a file.
Flag Description -c Display the number of matched lines. -i Ignore case sensitive. -l Display the file names. -n Display the line numbers. -w Match whole word.Count the number of words, lines, characters and bytes of a file.
Flag Description -l Line count. -c Byte count. -m Character count. -w Word count."Pipe", redirect the output of one command into another command.
Example: $ ls | more
Redirect the output of a command into a new file. If the file already exists, overwrite it.
Example: $ ls > myfiles.txt
Append the output of a command into a file. A new file is created if the file doesn't exist.
Example: $ echo "Mary 555-1234" >> phonenumbers.txt
Redirect a file as input to a program.
Example: $ more < phonenumbers.txt
u - read and write permissions; g - read permissions; o - read permissions
1 1 0 1 0 0 1 0 0 6 4 4Run commands with the security privileges of another user. Normally the root.
Change file modes or Access Control Lists.
Flag Description -r Recursively.Example: Add read and write permissions to user$ sudo chmod u+rw index.html or $ sudo chmod 644 index.html
Escape character. If you want to reference a special character, you must "escape" it first.
Example: $ touch /tmp/filename\*
Directory separator, used to separate a string of directory names.
Example: $ cd /usr/src/linux
Current directory. Can also "hide" files when it is the first character in a filename.
Example: $ cat ./file.txt
Parent directory of the current working directory.
Example: $ ls ..
User's home directory.
Example: $ ls ~/Documents
Represents 0 or more characters in a filename, or by itself, all files in a directory.
Example: pic*2015.jpg can represent 'picJan2015.jpg', 'picFeb2015.jpg', etc.
Represents a single character in a filename.
Example: hello?.txt can represent 'hello1.txt', 'helloz.txt' but not 'helloabc.txt'.
Can be used to represent a range of values, e.g. [0-9], [A-Z], etc.
Example: hello[0-2].txt represents the files 'hello0.txt', 'hello1.txt' and 'hello2.txt'.
Command separator. Allows you to execute multiple commands on a single line.
Example: $ cd /var/log ; less messages
Command separator as ';', but only runs the second command if the first one finished without errors.
Example: $ cd /var/logs &&
Execute a command in the background, and immediately get your shell back.
Example: $ which ruby > /tmp/locations.txt &