Outcome 2 Revision Flashcards
(39 cards)
What are the contents of the /bin directory?
The programs ‘pwd’, ‘rmdir’ and ‘ls’ and the following ‘uname’ program all live in the filesystem
What does Uname command do?
It shows system information and is useful for finding information such as the Linux kernel, CPU, and hardware platform.
uname –n - shows (print the network node (server) hostname)
uname -a - (print all information)
What does the pipe symbol do | ?
The pipe command takes the output of the first command and uses it as the input for the second command. Pipe is denoted by the pipe symbol ‘|’
What is happening in this command?:
Cy2a30@RIV-0M-MUOS-01ls /dev | grep sda
The command gets the listing of the current directory and then pipes it to (sends it to) the second command which is a grep command.
The grep command selects those lines from the directory listing (which it received from the ls command) having the regular expression ‘sda’ in them.
So basically as a result of this command you would get a list of files or directories that have the pattern ‘sda’ in their names.
What does ‘pwd’ command do?
It prints the full path of the current working directory
The pwd command should always be used should you get lost or confused in the file system. It lets you see the absolute path and lets you determine where you are in the context of the filesystem. If you have any problems as to your present location simply type cd as this will take you directly to your own home directory
The root / directory
The / (forward slash) is known as root and is denoted by a forward slash. This is known as the root directory. It is used to denote the starting point of the Linux filesystem and you cannot go any further back than this. Think of it as the equivalent of the ‘C’ drive in Windows.
What is the /var directory?
This directory contains ‘miscellaneous’ files used for the day to day running of the system.
What are the default permissions for a file and directory in Linux?
- 644 for a file
- 755 for a directory
How to recall previous commands?
- The ‘up arrow’ key
- ctrl+p
Introduction to the vi editor
Command Mode
This mode accepts commands, which are usually entered as single letters.
For instance, pressing the ‘i’ key or the ‘a’ key both get you into insert mode as does pressing the insert key itself, although in somewhat different ways, as described shortly, pressing the ‘o’ key opens a file in a line below the current one.
Ex Mode
To manipulate files (including saving your current file and running outside programs), you use ex mode. You enter ex mode from command mode by typing a colon (:), typically directly followed by the name of the ex-mode command you want to use. After you run the ex-mode command, Vi returns automatically to command mode.
Insert Mode
You enter text in insert mode. Most keystrokes result in text appearing on the screen. One important exception is the Esc key, which exits insert mode and returns to command mode.
What is the boot process in Linux?
cpu initiates bios
bios loads and runs boot loader
boot loader runs and runs secondary boot loaders and linux kernel
linux kernel loads and runs init
init start rest of services via Sys V and other startup scripts
What is the echo command?
The echo command when used on the command line or in a script will take a text string and write it to standard output – your screen.
What does this command do? :
echo Hello my name is caleb > names.odt
This command will create a new file with a .odt extension. Using this command simply sends (redirects) the text away from the screen by using a single > symbol typed after the text - to a new file called names.odt ‘. If the names.odt file previously did not exist; it will be created.
If names.odt does already exist – the redirection operator (>) will overwrite its existing contents.
What does Append symbol»_space; do?
It adds data to a file without overwritting the exisiting contents.
What is the Tee command?
The tee command when used in conjunction with pipe, is used to store and view (both at the same time) the output of any other command. The tee command writes to the stdout (monitor) and to a file at the same time as shown in the examples below.
By default, the tee command overwrites the previous content of a file. You can instruct the tee command to append (add to the end) of the file using the –a option.
What does this command do? :
find –maxdepth 2 –name *.txt
This command will search the current level (1) and one level down and give me the name of these files with a .txt extension and the directory they are in.
The find command shown above when used with the correct options will search for all .txt files but will restrict the search to the current directory level (1) and the all subdirectories located one level down.
Find & grep are NOT the same program – grep matches a pattern
What does the head command do?
It echoes (by default) the first 10 lines of one or more files to standard output.
Another definition: It prints the first lines of one or more files (or piped data) to standard output. By default, it shows the first 10 lines.
What does the Tail command do?
The tail command works just like head, except that (by default) tail displays the last 10 lines of a file. (You can use the –n lines options to change the amount of data displayed, just as with head.) This command is useful for examining recent activity in log files or other files to which data may be appended.
Tail -f
The -f or –follow option tells tail to keep the file open and to display new lines of input as they’re added. This feature is helpful for tracking log files because it enables you to see changes as they’re made to the file and who or which device made those changes.
What do these commands do? :
- vmstat 2 20 > vmstat.log
- tail –f vmstat.log
The first command will display the virtual memory statistics for the Linux server. The statistics will update every 2 seconds and display 20 lines of output. After the 20th line you’ll be returned to the prompt.
The second command - tail –f vmstat.log allows you to watch the vmstat.log file being continuously updated with the virtual memory statistics in real time.
When the vmstat command on your first screen terminates after the 20th entry, the vmstat.log file just stops. To exit the vmstat.log file just press ctrl+z
Remember! – tail –f vmstat.log however will keep the vmstat.log file open and display new lines as they are continuously updated.
Note: tail vmstat.log will only show the last 10 lines (by default).
What is a process in Linux?
A process is identified on the system by a process ID. That process ID is unique for the current system. In other words, no other process can use that number as its process ID while that first process is still running. However, once a process is ended, another process can reuse that number.
Along with a process ID number, there are other attributes associated with a process. Each process, when it is run, is associated with a particular user account and group account. That account information helps determine what system resources the process can access (similar to access to our college system). For example, processes run as the root user have much more access to system files and resources than a process running as a regular user
Which command shows the top 35 processes running on the system?
ps –e | head -36
The command to see all processes is - ps -e
Note: Use the ps –e command and pipe it with wc –l to see how many processes there are. (Possibly over 350 are running)
To see only the processes owned by you, use the ps u command.
What does “ vi file2& “ command do?
It will place the process called file2 into the background as a running process. Note the process ID. Your process IDs will be different from the examples shown.
Alternatively you could use these 3 commands:
1. vi file2
2. ctrl+z
3. bg
What does ‘fg’ command do?
If there is only one job then the fg (foreground) will bring this job to the foreground. If there are more than one job then the ‘%’ would be used symbol refers to the most recent command placed into the background.
What are the Kill commands?
kill -9 and kill -15