Command Line part 6
Week 1- The command line
Quick tip “man”
The “man” command takes the parameter of another command and returns a guide on what it does in specific. This can be useful if your unsure your using the correct command for the task at hand.
Intermediate Commands — Streams
What are streams you may ask? Streams in short are what a program uses to send outputs and receive inputs. Your keyboard is an input stream, The screen is an output stream and there is also an error stream for printing errors. Knowing how to redirect streams, linking streams from different programs will allow us to do some slightly more complex tasks.
So how do we redirect a stream? The answer is pipes, this is best illustrated with an example. When referring to a pipe we are talking about the | symbol, yup that’s a pipe!
An example of this in action would be
cat combined | less The pipe passes the output stream (what would normally be printed on the screen) of the command to the left of the pipe to the input stream of the command on the right. So in this example it’s passing the output of the file “combined” into the “less”.
Vise versa we can convert an input to an output, an example of this would be writing the output of “combined” into a new file “newCombined” cat combined > newCombined.
WILDCARD!

So what is a wildcard? Its a way in which we can refine searching files using a set criteria, example in terminal “ls *.txt” will list files as expected however only if they have the extension .txt. In Windows this command would be “dir *.txt”, “dir /S *.txt” If you wish to show the specified file type in all directories. The * in both cases acts as a wildcard, you can do this in a number of situations.
“find” Will allow us to access all the files in a specified directory, example “find this_file”, the windows command is the same. You can specify a path as follows “find “file_name” “pathname””.
“grep” Is a good way to search files with key words, for example “grep “Jon” names.txt”. Here we search the text file “names.txt” for the text jon, the Windows equivalent would be “findstr”, example “findstr “find this” file.txt”. This will return 3 values these are the line, word and character count.
With the“wc” we can count how many words a text document has (word count), example “wc longText.txt”. The Windows equivalent to this would be “wc” with “l” as “1 wc -l file.txt”. To count the words, use “wc” with “w” example “ wc -w file.txt”.
“whoami” can be used to determine what permissions you have, in Unix systems (Mac/Linux) there are 3 types of user permissions “user”, “group” and “others” Each type has three types of permissions, “read”, “write” and “execute” The user permission is the owner and has all permissions , the group has certain permissions, other can use read only. When using “ls” you can view the permissions of each file, The Windows equivalent is exactly the same.