Please enable JavaScript.
Coggle requires JavaScript to display documents.
Command Line (Commands (Redirection (grep (grep -Rl (Searches all files in…
Command Line
-
Functions:
-
Copy, move, and remove files and directories
-
-
-
Commands
-
-
-
-
Manipulation
cp
-
-
-
-
Wildcards
-
*
-
e.g. uses cp to copy all files into the satire/ directory.
e.g. **m.txt selects all files in the working directory starting with "m" and ending with ".txt", and copies them to scifi/*.
mv
-
-
-
-
Rename a file
-
e.g. By moving batman.txt into spiderman.txt, we rename the file as spiderman.txt.
rm
-
Removing files
e.g. Here we remove the file waterboy.txt from the filesystem.
-
WARNING:Be careful when you use rm! It deletes files and directories permanently. There isn't an undelete command, so once you delete a file or directory with rm, it's gone.
-
Redirection
Direct the input and output (I/O) of a command to and from other files and programs, and chain commands together in a pipeline.
-
-
-
e.g. The echo command accepts the string "Hello" as standard input, and echoes the string "Hello" back to the terminal as standard output.
Redirection reroutes standard input, standard output, and standard error to or from a different location.
-
>>
Takes the standard output of the command on the left and appends (adds) it to the file on the right.
-
e.g. Here, the output data of rivers.txt will contain the original contents of rivers.txt with the content of glaciers.txt appended to it.
<
-
e.g. Here, lakes.txt is the standard input for the cat command. The standard output appears in the terminal.
|
-
Takes the standard output of the command on the left, and pipes it as standard input to the command on the right.
-
e.g.
The wc command outputs the number of lines, words, and characters in volcanoes.txt, respectively.
Here the output of cat volcanoes.txt is the standard input of wc. in turn,
-
sort
-
e.g. Here, the lakes in sort lakes.txt are listed in alphabetical order.
e.g.
Here, the command takes the standard output from cat lakes.txt and "pipes" it to sort.
-
uniq
Filters out adjacent, duplicate lines in a file.
-
e.g.
Here uniq deserts.txt filters out duplicates of "Sahara Desert", because the duplicate of 'Sahara Desert' directly follows the previous instance.
The "Kalahari Desert" duplicates are not adjacent, and thus remain
e.g.
A more effective way to call uniq is to call sort to alphabetize a file, and "pipe" the standard output to uniq.
-
Here by piping sort deserts.txt to uniq, all duplicate lines are alphabetized (and thereby made adjacent) and filtered out.
grep
-
-
-
e.g. Here, grep searches for "Mount" in mountains.txt.
grep -i
-
e.g. grep searches for capital or lowercase strings that match Mount in mountains.txt.
grep -R
-
e.g. Here grep -R searches the /home/ccuser/workspace/geography directory for the string "Arctic" and outputs filenames and lines with matched results.
grep -Rl
-
-
e.g. Here grep -Rl searches the /home/ccuser/workspace/geography directory for the string "Arctic" and outputs filenames with matched results.
sed
-
Accepts standard input and modifies it based on an expression, before displaying it as output data.
-
e.g. 's/snow/rain/'
-
snow:
The search string, the text to find.
rain:
The replacement string, the text to add in place.
-
-
e.g.
The above command uses the g expression, meaning "global".
Here sed searches forests.txt for the word "snow" and replaces it with "rain", globally.
-
Environment
-
This enables us to customize greetings and command aliases, and create variables to share across commands and programs.
nano
-
It works just like a desktop text editor like TextEdit or Notepad, except that it is accessible from the command line and only accepts keyboard input.
e.g.
- opens a new text file named hello.txt in the nano text editor.
- a text string entered in nano through the cursor.
3. Menu of Commands
-
- Ctrl + O saves a file. 'O' stands for output.
- Ctrl + X exits the nano program. 'X' stands for exit.
- Ctrl + G opens a help menu.
Clear: clears the terminal window, moving the command prompt to the top of the screen.
The Bash Profile
-
When a session starts, it will load the contents of the bash profile before executing commands.
-
-
e.g.
-
- text
Creates a greeting in the bash profile, which is saved.
It tells the command line to echo the string "Welcome, Jane Doe" when a terminal session begins.
- Command
-
Instead of closing the terminal and needing to start a new session, source makes the changes available right away in the session we are in.
The name ~/.bash_profile is important, since this is how the command line recognises the bash profile.
alias
Command that allows you to create keyboard shortcuts, or aliases, for commonly used commands.
-
e.g.
Creates the alias pd for the pwd command, which is then saved in the bash profile.
-
Each time we open up the terminal, we can use the pd alias.
history
-
e.g.
-
-
By typing hy, the command line outputs a history of commands that were entered in the current session.
e.g.
-
By typing ll, the command line now outputs all contents and directories in long format, including all hidden files.
-
Filesystem:
-
e.g.