A ________ is several commands that are normally written out one-by-one, chained together in order to create a new command.
A **compound command** is several commands that are normally written out one-by-one, chained together in order to create a new command.
What are the three components of a command?
program -options arguments
Compound commands typically follow this format:
program -options arguments | program -options | program -options | program -options
Breakdown this command:
file $(find / -iname *.txt 2>/dev/null) > ~/Desktop/text_files ; tail ~/Desktop/text_files
Explain these command:
ls command and sends it into a new file named list.txt. _If_ the file list.txt already exists, it is overwritten with the output of the ls command.\> so there is no output to send to the list.txt file.list.txt exists, it is overwritten with nothing.ls command to the list.txt file.list.txt file does not exist, it is created.\>\> instead of \> is always safer, unless you want the file to be overwritten.What do pipes ( | ) do?
The pipe ( | ) takes the output of one command and sends it to the input of another command.
Explain this command:
ls -l | grep *.txt
The pipe ( | ) takes the output of one command and sends it to the input of another command.
ls -l creates a list of files.| pipes the list from ls into the command that follows.grep searches the files from ls for the string that follows.*.txt matches any file that ends with .txt.Compound commands with pipes typically follow this format:
program -options arguments | program -options | program -options | program -options
What are some common programs users pipe to:(5)
Explain this command:
cat /etc/passwd | grep sysadmin | awk -F ‘:’ ‘{print $6}’
cat /etc/passwd dumps the contents of /etc/passwd to output.| pipes that output into the command that follows.grep sysadmin displays lines that contain sysadmin.| pipes that output into the command that follows.awk -F ':' '{print $6}' prints only the sixth field of the line.awk usually looks for a space to use as a field separator, but in this case we want it to separate the line by a colon, because /etc/passwd uses colons to separate its fields.In addition to |, you can use ____ to run a series of commands back to back.
You can also use a ; to run a series of commands back to back.
Rather than typing the following, how would you use ; :
bash $ mkdir dir $ cd dir $ touch file $ ls -l -rw-r--r-- 1 user user 0 Sep 4 15:33 file
mkdir dir; cd dir; touch file; ls -l
Each command will happen in succession.
- First, the mkdir command, then cd, touch, and finally ls.
Compound commands using ; typically follow this format:
program -options arguments ; program -options arguments ; program -options arguments ; program -options arguments
For example: `mkdir dir; cd dir; touch file; ls -l
bash $ mkdir dir; cd dir; touch file; ls -l -rw-r--r-- 1 user user 0 Sep 4 15:33 file
If you only want to run the second command if the fist command was successful, what operator would you use?
&&
Explain this command:
mkdir dir && cd dir && touch file && ls -l
cd would only run if mkdir were successful, touch would only run if cd were successful and ls would only run if touch were successful.
Compound commands using && typically follow this format:
program -options arguments && program -options arguments && program -options arguments && program -options arguments
Explain these operators:
Compound commands are useful but _do_ require a lot of typing. If you use a compound command often, it might be nice to save it somewhere so you can easily reference it. You can do this by creating an ________.
Alias
An _______ is a shorthand or custom command that you can define, which will launch any command or compound command, including arguments and redirection.
An **alias** is a shorthand or custom command that you can define, which will launch any command or compound command, including arguments and redirection.
In computer programing, a ________ is a location that stores some kind of data.
In computer programing, a variable is a location that stores some kind of data.
Bash has a number of built-in variables called _______. They are also known as _______.
Bash has a number of built-in variables called **environment variables**. They are also known as **shell variables**.
True or False:
Built-in variables are always defined with all lower case letters.
False
They are always defined with all upper case letters. For example, $PWD is an environment variable that returns the pwd command.
What do these built-in variables do?
echo "My name is $USER"echo "My home directory is $HOME"echo "The name of my computer is $HOSTNAME"echo "My type of computer is a $MACHTYPE"echo "My user ID is $UID":echo "My name is $USER": Provides the user name of the current user.echo "My home directory is $HOME": Provides the home folder of the current user.echo "The name of my computer is $HOSTNAME": Provides the name of the computer.echo "My type of computer is a $MACHTYPE": Provides the type of computerecho "My user ID is $UID": Provides the UID of the current user.________ in bash refers to any time something on the command line expands or morphs into something else.
**Expansion** in bash refers to any time something on the command line expands or morphs into something else.