Unix Flashcards
What is an SH file?
Files with the .sh extension are UNIX shell script files. This allows you to execute a chain of UNIX commands as a single unit of work in a convenient and repeatable way.
What is SSH?
ssh (SSH client) is a program for logging into a remote machine and for executing commands on a remote machine. It is intended to replace rlogin and rsh, and provide secure encrypted communications between two untrusted hosts over an insecure network.
How do you know what directory you are in?
Using the pwd command will print the working directory.
How do you list all the files in a directory?
The ls command prints files and subdirectories in the current folder. Expose hidden files with the -a option.
How do you edit a file in UNIX?
You can use the cat command or open the file with a text editor, such as vi or nano.
What is the cat command?
The cat command reads one or more files and prints them to standard output. The operator (one arrow pointing right) can be used to combine multiple files into one. The operator (two arrow pointing right) can be used to append to an existing file.
How would you change directories?
Using the cd command and specifying the desired location.
What is echo used for?
Echo prints a string value to the standard console output. You can pipe output from another command into echo, print a variable’s value, and more.
What is telnet?
The telnet command allows you to communicate to another host using the TELNET protocol. telnet [host [port]]
What is the difference between find and grep?
“find” is a file locator while “grep” searches for patterns within a file.
What does grep do?
The grep command is used to search text or searches the given file for lines containing a match to the given strings, words, or regular expression. By default, grep displays the matching lines.
What does chmod command do?
In Unix operating systems, chmod is the command that can change the access permissions to files and directories. The syntax is: chmod (options) (permissions) (filename). The permissions list includes permissions for user, group, and other. You can use rwx (read, write, execute) notation or 0-7 digits to represent the permissions
If you have a variable called ‘name’, how would you reference that?
You can prepend the $ character to the beginning of the variable name, in this case $name will retrieve the environment variable’s value. You can change and set variable values using key=value syntax.
What is the diff command?
“diff analyzes two files and prints the lines that are different. Essentially, it outputs a set of instructions for how to change one file in order to make it identical to the second file. It does not actually change the files; however, it can optionally generate a script (with the -e option) for the program ed (or ex which can be used to apply the changes. For example: diff file1.txt file2.txt”
How would you monitor a log file?
“SSH on to your server then type: tail -f /var/log/httpd/access_log The above command will show you the last few lines of the log file. The -f option will print to your console any new lines added to the log file in realtime. So you can get a live view of additions to the log file. “