Bash
Bash is a Unix shell and command language written by Brian Fox for the GNU Project as a free software replacement for the Bourne shell. First released in 1989, it has been distributed widely as the shell for the GNU operating system and as a default shell on Linux and OS X.
Tip
Think of Bash as a program that takes in commands and executes them. It is a command-line interpreter that allows you to interact with your computer using text commands, but it can also run scripts that automate tasks.
Basic Commands
List
Lists files in the current directory.
foo@bar:~$ ls
Some flags that can be used with ls:
-l: long listing format-a: list all files, including hidden files-h: human-readable file sizes
ls can also take a directory as an argument to list files in that directory.
ls /path/to/directory
Print Working Directory
Prints the current working directory.
foo@bar:~$ pwd
Echo
Prints a message to the terminal.
foo@bar:~$ echo "Hello, World!"
Change Directory
Changes the current working directory.
foo@bar:~$ cd /path/to/directory
To move up one directory (the parent directory), use ...
foo@bar:~$ cd ..
To move to the home directory, use ~.
foo@bar:~$ cd ~
Make Directory
Creates a new directory.
foo@bar:~$ mkdir new_directory
Copy
Copies files or directories.
foo@bar:~$ cp file1 file2
Concatenate
Concatenates and displays the contents of files.
foo@bar:~$ cat file1 file2
Tip
Most of the time to display the contents of a file, you can use
catorless.catis used to display the entire file at once, whilelessis used to display the file one page at a time.
Remove
Removes files or directories.
foo@bar:~$ rm file1
To remove a directory and its contents, use the -r flag (recursive).
foo@bar:~$ rm -r directory
Tip
Typically, this is appended with the
-fflag to force the removal of files without prompting for confirmation.
Connections
Obvious technical and formatting errors repaired.