Linux Midterm - Ch 1-26

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

tar

"tar" stands for tape archive, which is used by large number of Linux/Unix system administrators to deal with tape drives backup. The tar command used to rip a collection of files and directories into highly compressed archive file commonly called tarball or tar, gzip and bzip in Linux.

format of passwd file

COMMAND - The format of the passwd file is a text file. You can find out more information on this file under the passwd man page. You use the passwd command when you want to set or change your password. You can only change other users passwords if you have superuser priviledges.

pipe

COMMAND - This command pipes the output of the previous command to the next command.

sudoer file and how to edit it

COMMAND - You can edit a sudoer by use of "visudo"

cd

Command - Change directory

cp

Command - Copy files and directories

mv

Command - Move/rename files and directories

pwd

Command - Print name of current working directory

rm

Command - Remove files and directories

df

Command - Using the " df " command, it will allow you to see the current amount of free space on our disk drives.

Hard Links

DEFINITION - allow files to have multiple names 1. A hard link cannot reference a file outside its own file system. This means a link cannot reference a file that is not on the same disk partition as the link itself. 2. A hard link may not reference a directory.

File Descriptors

DEFINITION - also known as Drivers. The POSIX standard defines this per-process unique, non negative integer used to identify an open file for the pruposes of file access. It does not describe a file, it just is a number that is ephemerally associated with a particular "open" file description

inode

DEFINITION - this contains the description of the file

rwx representation

File Permission - File permissions: File attributes contain Read, Write, and Execute (r,w,and x) permission bits for each type of user access: • (1) User owner • (2) Group owner -- users who are members of the owning group • (3) Other (aka World) -- users who aren't owners or members of the owning group Examples: rwxrwxrwx 111 111 111 777 rwxrw-r-- 111 110 100 764 -wxr-xr-- 011 101 100 354 700 rwx------ 755 rwxr-xr-x 600 rw------- 622 rw--w--w- 620 rw--w----

How do you search for a process?

How do you search? - By using the "jobs" command, you can see a list of all active job processes

how does rwx work on files?

How does this work? - When dealing with files, the permissions for their directories is important. Here is what can be set to read, write, or execute a file in a directory. • R - permission to read the directory (see details about the files in the directory) assuming X is also set • W - permission to write the directory (I can create files in it, rename files, delete them, and change the attributes of the directory itself) assuming X is also set • X - permission to traverse the directory (go into the directory and access the files inside, including sub-directories) • By the way, the sticky bit for directories states that files and directories within that directory may only be deleted or renamed by their owner (or root) - BUT this varies from system to system in my experience

How many processes will be forked from process of bash when we run the following script in the bash? #!/bin/bash while true do sleep 2 date > /dev/null done A. 1 B. 2 C. 3 D. 4

How many processes will be forked? - Choice C is the correct answer. There is a total of 3 processes that will be forked: The bash script is the first fork.The sleep is the the next fork.Then date is the last one.

Hard link

Link - Hard links point to the targets file's iNode. You can create a hard link by using "" -ln "" Notes about a Hard link: • Very simple to have two filenames, in the same or different directories, that point to the same inode • This is why both of the files must be on the same filesystem if it is a hard link • By default, ln command creates hard links • Hard link is a reference to the physical data on a file system • All named files are hard links • More than one name can be associated with the same physical data • Hard links can only refer to data that exists on the same file system • You can not create hard link to a directory • Creates two filenames that both go to the same data • Must be on the same file system on the machine • More efficient than a symbolic link Example: ln file1 file1 -hard

"<"

Redirect - stdin so that input to command comes from a file (instead of keyboard)

Who created the first so-called Linux?

The history of Linux - Linus Torvalds in 1991

Linux is created based on what?

The history of Linux - The Linux kernel, based on UNIX, was developed in the early 1990s by Linus Torvalds. By 1991, Torvalds had released the first version — just 10,000 lines of code — and sparked excitement in the software development community with the humble email announcement seen above.

Hard links link file names and _____.

What does this do? - This will link file names and inodes

What is unmask?

What is? - umask : Shell built-in command used to set default permissions for files created by user • When umask is expressed with symbols, the settings represent which permissions are granted • Same as chmod • When umask expressed numerically, the bits represent which permissions are denied • The effective default permission is [777 - (Value of umask)] • Note that this is the opposite of chmod

Which is the correct regular expression for matching the word "book" in both singular and plural forms in the text? A. 'book' B. ' book ' C. ' books*' D. '[[:space:]]books{0,1}[[:space:]]'

Which is the correct regular expression (RE)? - Choice D is the correct regular expression for matching the word "book" in both singular and plural forms in the text.

Which is the correct way to source the script? A. ./bash_script B. . ./bash_script C. > ./bashscript D. ./bashscript &

Which is the correct way? - Choice B is the correct way to source the script.

Which of the following info is NOT in the inodes? A. File type B. File name C. Disk address D. File permission

Which one is not included? - Choice B is not included in the inodes.

? Key

Wildcard - Matches any single character

directory commands

command - These are some of the commands that are used with directories: cp - Copies files and directories mkdir - Makes a new directory mv - Moves/renames files and directories rm - Removes files and directories

cp file1 file2 dir1

cp example - Copy file1 and file2 into directory dir1. The directory dir1 must already exist.

cp -i file1 file2

cp example - Copy file1 to file2 and file2 exists, the user is prompted before it is overwritten.

cp file1 file2

cp example - Copy file1 to file2. If file2 exists, it is overwritten with the contents of file1. If file2 does not exist, it is created

cp dir1/* dir2

cp example - Using a wildcard, copy all the files in dir1 into dir2. The directory dir2 must already exist.

cp -a

cp option - "--archive - Copy the files and directories and all of their attributes, including ownerships and permissions.

cd example

example - [me@linuxbox ~]$ cd /usr/bin

"|"

key - piping - also known as a double redirection

(') Single quotes

key - these allow you to use spaces in your code

ln file link

ln command - creates a hard link

ln -s item link

ln command - creates a symbolic link

mv -i

mv option - "--interactive - Before overwriting an existing file, prompt the user for confirmation. If this option is not specified, mv will silently overwrite files.

ls -r --reverse

option - This option is used with the ls command - it means Display the results in reverse order. Normally, ls displays its results in ascending alphabetical order.

ls -h --human-readable

option - This option is used with the ls command - it means In long format listings, display file sizes in human readable format rather than in bytes.

ls -F --classify

option - This option is used with the ls command - it means This option will append an indicator character to the end of each listed name. For example, a forward slash (/) if the name is a directory.

ls -l

option - This option is used with the ls command - it means to Display results in long format.

rm -r

rm example - ""--recursive - Recursively delete directories. This means that if a directory being deleted has subdirectories, delete them too. To delete a directory, this option must be specified.

rm -f

rm example - "--force - Ignore nonexistent files and do not prompt. This overrides the --interactive option.

rm -i

rm example - "--interactive - Before deleting an existing file, prompt the user Before deleting an existing file, prompt the user for confirmation. If this option is not specified, this will silently delete files.

rm -rf file1 dir1

rm example - Same as the previous command, except that if either file1 or dir1 do not exist, rm will continue silently.

sudoer file and its format

COMMAND - This stands for ""Super User Do"" which allows you to run programs as another user, by default the root user. If you spend a lot of time on the command line, sudo is one of the commands that you will use quite frequently. Using sudo instead of login in as root is more secure because you can grant limited administrative privileges to individual users without them knowing the root password.

sudoer file and how to edit its permission

COMMAND - You can list the set of privileges that are granted by sudo by using the "" -l "" option to list them. Ex. [me@linuxbox ~]$ sudo -l => User me may run the following commands on this host: (ALL) ALL To change permissions using sudo, you can use the chmod command to change the setuid or setgid permissions. Ex. [bill@linuxbox ~]$ sudo chmod g+s /usr/local/share/Music [bill@linuxbox ~]$ ls -ld /usr/local/share/Music drwxrwsr-x 2 root music 4096 2018-03-24 20:03 /usr/local/share/Music

alias

COMMAND - a shortcut to simplify a long winded command

uniq

COMMAND - operates on consecutie, duplicate lines of text

grep

COMMAND - search for lines matching an expression

cat

COMMAND - this catenates files and prints out all the contents on the screen

cut

COMMAND - this grabs a file so you can paste it

echo

COMMAND - used to display a string on the screen

/mnt

Directory - On older Linux systems, the /mnt directory contains mount points for removable devices that have been mounted manually.

/etc

Directory - The /etc directory contains all of the system-wide configuration files. It also contains a collection of shell scripts that start each of the system services at boot time. Everything in this directory should be readable text. Interesting files: While everything in /etc is interesting, here are some all-time favorites: ● /etc/crontab, a file that defines when automated jobs will run. ● /etc/fstab, a table of storage devices and their associated mount points. ● /etc/passwd, a list of the user accounts.

Environment variable

Environment - The shell stores two basic types of data in the environment; though, with bash, the types are largely indistinguishable. They are environment variables and shell variables. Shell variables are bits of data placed there by bash, and environment variables are everything else. To see what is stored in the environment, we can use either the set builtin in bash or the printenv program. The set command will show both the shell and environment variables, while """" printenv """" will only display the latter. Since the list of environment contents will be fairly long, it is best to pipe the output of either command into less. [me@linuxbox ~]$ printenv | less *Environmental points from slides: • A shell variable defined in one instance of the shell not accessible to subprocesses of the shell unless it is defined as an environment variable $VAR=CYBR3350 $ # now launch a script that uses $VAR • A variable is defined as environment variables by defining its name and value (assignment/set), then exporting it with the export command • export <name>=<value> • Lots of built-in shell variables • export -p $echo $HOSTNAME => vm1 $echo ${HOSTNAME} => vm1 $hostname => vm1 $echo $(hostname) => vm1 • env / printenv • env | grep HOME = echo $HOME • export • alias Environment Variables • HOME - your home directory • PATH - we know this - search path for commands • DISPLAY - what display you are on (X-windows) • EDITOR - your default editing program • PAGER - usually /usr/bin/less, used for commands like "man" • SHELL - what shell program to use for scripts and things • TERM - generally "xterm" but describes terminal translation and special character handling

sticky bit

File Permission - This is a holdover from ancientUnix, where it was possible to mark an executable file as "not swappable." On files, Linux ignores the sticky bit, but if applied to a directory, it prevents users from deleting or renaming files unless the user is either the owner of the directory, the owner of the file, or the superuser. This is often used to control access to a shared directory, such as /tmp For Linux, has no effect when applied to a file • For Linux, when applied to directory (usually) • Only the user owner (and root) can rename or delete a file • Even if (non-root) user has write access to directory, don't permit them to delete files they don't own • Recall: This is not the default behavior... without the sticky bit, deleting a file is just a change to the directory... so user can delete a file they don't have any access to if they have write access to the directory

octal number presentation

File Permission - With octal notation, we use octal numbers to set the pattern of desired permissions. Since each digit in an octal number represents three binary digits, this maps nicely to the scheme used to store the file mode • Octal digit: base-8 number system • 0, 1, 2, 3, 4, 5, 6, 7, 10, 11, 12, 13, 14, 15, 16, 17, 20,... • Binary: base-2 number system, 0/1 • Translation between them • 0 000 --- • 1 001 --x • 2 010 -w- • 3 011 -wx • 4 100 r-- • 5 101 r-x • 6 110 rw- • 7 111 rwx *A full permssion set would look like this: 000 000 010 010 (which is the same as) --- rw- r-- r-- Ex. [me@linuxbox ~]$ > foo.txt [me@linuxbox ~]$ ls -l foo.txt -rw-rw-r-- 1 me me 0 2016-03-06 14:52 foo.txt [me@linuxbox ~]$ chmod 600 foo.txt [me@linuxbox ~]$ ls -l foo.txt -rw------- 1 me me 0 2016-03-06 14:52 foo.txt By passing the argument "600", we were able to set the permissions of the owner to read and write while removing all permissions from the group owner and world. Though remembering the octal to binary mapping may seem inconvenient, we will usually have only to use a few common ones: 7 (rwx), 6 (rw-), 5 (r-x), 4 (r--), and 0 (---).

mount

File System Command - The mount command allows you to mount a file system onto a storage container. The first step in managing a storage device is attaching the device to the file system tree. This process, called mounting, allows the device to interact with the operating system. Slide notes: • OK we partitioned /dev/sdb to get /dev/sdb1 • We did a mkfs on /dev/sdb1 • We could just for fun do a check on it • fsck /dev/sdb1 • Now the only thing left to do is mount it • Create a directory where you want it mounted • mount /dev/sdb1 /wherever • If you want to edit /etc/fstab you can set it up to be mounted every time you boot

mkfs

File System Command - You use mkfs to create a new file system on our flash drive. To do this, we will use mkfs (short for "make file system"), which can create file systems in a variety of formats. To create an ext4 file system on the device, we use the -t option to specify the ext4"system type, followed by the name of the device containing the partition we want to format. Example: [me@linuxbox ~]$ sudo mkfs -t ext4 /dev/sdb1 The program will display a lot of information when ext4 is the chosen file system type. To reformat the device to its original FAT32 file system, specify vfat as the file system type. [me@linuxbox ~]$ sudo mkfs -t vfat /dev/sdb1 This process of partitioning and formatting can be used anytime additional storage devices are added to the system. While we worked with a tiny flash drive, the same process can be applied to internal hard disks and other removable storage devices like USB hard drives.

Please translate the permission of "753" into rwx representation.

Translate the permission. - rwxr-x-wx

What are the steps to making a 2nd or new hard drive that is usable to Ubantu?

What are the steps? - Assuming that a new hard drive is connected to the physical or virtual machine, you will need to use fdisk, mkfs, and mount with certain options to do this.

To create an alias, named "foo", for the commands of "cd /usr; ls; cd ~", what command we should use?

What command should be used? - The correct coding to use is: alias foo='cd /usr; ls; cd ~'

To create a symbolic link, in the path of "./shortcut", for file "/home/steal/passwd", what command should we use?

What command should be used? - The correct coding to use is: ln -s /home/steal/passwd ./shortcut

What does a single quote do in an environment?

What does this do? - If we need to suppress all expansions, we use single quotes. Here is a comparison of unquoted, double quotes, and single quotes: [me@linuxbox ~]$ echo text ~/*.txt {a,b} $(echo foo) $((2+2)) $USER text /home/me/ls-output.txt a b foo 4 me [me@linuxbox ~]$ echo ""text ~/*.txt {a,b} $(echo foo) $((2+2)) $USER"" text ~/*.txt {a,b} foo 4 me [me@linuxbox ~]$ echo 'text ~/*.txt {a,b} $(echo foo) $((2+2)) $USER' text ~/*.txt {a,b} $(echo foo) $((2+2)) $USER As we can see, with each succeeding level of quoting, more and more of the expansions are suppressed.

What does a double quote do in an environment?

What does this do? - The first type of quoting we will look at is double quotes. If we place text inside double quotes, all the special characters used by the shell lose their special meaning and are treated as ordinary characters. The exceptions are $, \ (backslash), and ` (back-quote). This means that word-splitting, pathname expansion, tilde expansion, and brace expansion are suppressed, but parameter expansion, arithmetic expansion, and command substitution are still carried out. Using double quotes, we can cope with filenames containing embedded spaces. Say we were the unfortunate victim of a file called two words.txt. If we tried to use this on the command line, word-splitting would cause this to be treated as two separate arguments rather than the desired single argument. [me@linuxbox ~]$ ls -l two words.txt ls: cannot access two: No such file or directory ls: cannot access words.txt: No such file or directory By using double quotes, we stop the word-splitting and get the desired result; further, we can even repair the damage. [me@linuxbox ~]$ ls -l ""two words.txt"" -rw-rw-r-- 1 me me 18 2016-02-20 13:03 two words.txt [me@linuxbox ~]$ mv ""two words.txt"" two_words.txt There! Now we don't have to keep typing those pesky double quotes. Remember, parameter expansion, arithmetic expansion, and command substitution still take place within double quotes. [me@linuxbox ~]$ echo ""$USER $((2+2)) $(cal)"" me 4 February 2019 Su Mo Tu We Th Fr Sa 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 We should take a moment to look at the effect of double quotes on command substitution. First let's look a little deeper at how word splitting works. In our earlier example, we saw how word-splitting appears to remove extra spaces in our text. [me@linuxbox ~]$ echo this is a test this is a test By default, word-splitting looks for the presence of spaces, tabs, and newlines (linefeed characters) and treats them as delimiters between words. This means unquoted spaces, tabs, and newlines are not considered to be part of the text. They serve only as separators. Since they separate the words into different arguments, our example command line contains a command followed by four distinct arguments. If we add double quotes: [me@linuxbox ~]$ echo ""this is a test"" this is a test word-splitting is suppressed and the embedded spaces are not treated as delimiters; rather they become part of the argument. Once the double quotes are added, our command line contains a command followed by a single argument. The fact that newlines are considered delimiters by the word-splitting mechanism causes an interesting, albeit subtle, effect on command substitution. Consider the following: [me@linuxbox ~]$ echo $(cal) February 2019 Su Mo Tu We Th Fr Sa 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 [me@linuxbox ~]$ echo ""$(cal)"" February 2019 Su Mo Tu We Th Fr Sa 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 In the first instance, the unquoted command substitution resulted in a command line containing 38 arguments. In the second, it resulted in a command line with one argument that includes the embedded spaces and newlines

PWD mean when used with echo (Ex. Echo$(PWD))

What does this mean? - This usage of $PWD prints the current working directory Examples of PWD to disquish correct use vs. incorrect use (note the difference) $echo PWD => PWD (incorrect) $echo $PWD => /home/ruizhao (correct)

What does $pwd mean when used with echo (Ex. Echo$(pwd))

What does this mean? - This usage of $pwd prints nothing. This is because the Value of unassigned shell variable is empty string. This is an incorrect attempt to use the $PWD (print working directory. Use $echo $PWD instead) Examples of pwd: $echo pwd => pwd Shell variable names are case-sensitive $echo $pwd => <nothing> Value of unassigned shell variable is empty string Note that the variables are case-sensitive

Whats the difference between locate and find?

What is the difference? - Locate uses a prebuilt database, which should be regularly updated, while find iterates over a filesystem to locate files. Thus, locate is much faster than find , but can be inaccurate if the database -can be seen as a cache- is not updated.

format of passwd

What is the format? - The passwd format is a text file. Without proper permissions, it cant be accessed.

format of shadow file

What is the format? - The shodow format is a text file. Without proper permissions, it cant be accessed.

In my current directory, there is no file or subdirectory named "my_item", what is the result of executing command "ls my_item | wc -l"? A. ls: cannot access my_item: No such file or directory 0 B. 1 C. 2 D. 3

What is the result? - Choice A is is the result. In this coding, since there is no subdirectory named "my_item", it will tell us that the ls command cannot access that file because no such directory exists. They word count (wc) will show zero words.

The file descriptor for standard input is _____. The file descriptor for standard output is _____. The file descriptor for standard error is _____.

What is the standard input? - The file descriptor for standard input is 0. The file descriptor for standard output is 1. The file descriptor for standard error is 2.

What is extended regular expression

What is this command for? - The Extended Regular Expressions or ERE flavor standardizes a flavor similar to the one used by the UNIX egrep command. "Extended" is relative to the original UNIX grep, which only had bracket expressions, dot, caret, dollar and star. An ERE support these just like a BRE.

What is a file archive command?

What is this command for? - The Linux 'tar' stands for tape archive, is used to create Archive and extract the Archive files. tar command in Linux is one of the important command which provides archiving functionality in Linux. We can use Linux tar command to create compressed or uncompressed Archive files and also maintain and modify them.

What is a compression command?

What is this command for? - compress command is used to reduce the file size. After compression, the file will be available with an added . Z extension. File permissions will still remain the same as before using compress command.

What is bashrc?

What is? - This is an important Startup file for Non-Login shell sessions. This file is a users personal startup file. It can be used to extend or override setting in the global configuration script. This being on the more important startup files because it is read by default by most strartup files. • When you run a shell script, "bash" will try to run • /etc/bash.bashrc - global for all users • ~/.bashrc - your own personal script

What is a setgid bit and what does it mean?

What is? - This is very similar to setuid • GID instead of UID • When applied to directory • Newly created files in the directory have the same group owner as the directory's group owner Known as Octal 2000. Like the setuid bit, it changes the effective group ID from the real group ID of the real user to that of the file owner. If the setgid bit is set on a directory, newly created files in the directory will be given the group ownership of the directory rather the group ownership of the file's creator. This is useful in a shared directory when members of a common group need access to all the files in the directory, regardless of the file owner's primary group.

The PID of the current bash is 12496. We have an executable scripted called "pid.sh", which has the following content:#!/bin/bashecho $$ What will be printed out when we "source ./pid.sh"? A. 29656 B. 1 C. 12496 D. Who knows!

What will be printed? - Choice C will be printed out when we use "source ./pid.sh".

Which of the following vi commands can be used to save the content on screen and then exit the vi? A. :q B. :q! C. :x D. :w

Which can be used? - Choice C can be used to save the content on screen and then exit the vi.

Which command can be used for print out all environment variables? A. ls B. cut C. env D. Export

Which command can be used? - Choice C command can be used for print out all environment variables.

Which command cannot be used for compressing files? A. gzip B. gunzip C. tar D. bzip2

Which command can't be used? - Choice B can not be used for compressing files.

Which command is used to modify the file/directory permission? A. ln B. ps C. chmod D. cut

Which command is used to modify? - Choice C command is used to modify the file/directory permission.

Which command is used to install a package called "java" on Ubuntu? A. sudo apt-get update java B. sudo apt-get upgrade java C. sudo apt-get install java D. sudo apt-get remove java

Which command is used? - Choice C command can be used to install a package called "java" on Ubuntu.

Which of the following commands can NOT print out the hostname? A. echo $HOSTNAME B. echo ${HOSTNAME} C. echo hostname D. echo $(hostname)

Which does not print? - Choice C is will not print out the hostname. You must use the $ symbol to have it work properly.

Which is the correct regular expression for matching any single digit number? A. [0123456789] B. {0123456789} C. {0-9} D. [!0-9]

Which is the correct regular expression (RE)? - Choice A is the correct regular expression for matching any single digit number. Note: This one is NOT USING THE SQUIGGLY BRACKETS. So make sure to pick the squared brackets [ ] for this expression.

Which is the correct way to add our own directories to the PATH environment variable? A. PATH=/home/steal/bin:${PATH} B. PATH=$(PATH):/home/steal/bin C. PATH=/home/steal/bin:$(PATH) D. PATH=${PATH}:/home/steal/bin

Which is the correct way to add our own directories? - Choice D is the correct way to add our own directories to the PATH environment variable.

Which is the right symbol that can put the execution of a command to the background? A. ! B. ^ C. * D. &

Which is the right symbol? - Choice D is the right symbol that can put the execution of a command to the background.

Which of the following statements is wrong? A. Hard links can be created across file systems. B. Symbolic links can be created across file systems. C. Hard links can be created for files only. D. Symbolic links can be created among file/directory names only.

Which one is wrong? - Choice A is incorrect. Hard links can not be created across file systems.

Which of the following statements is wrong? A. ln "command1; command2", if the execution of "command1" is unsuccessful, the "command2" will be executed. B. ln "command1 && command2", if the execution of "command1" is unsuccessful, the "command2" will be executed. C. ln "command1 | command2", if the execution of "command1" is unsuccessful, the "command2" will be executed. D. ln "command1 && command2", if the execution of "command1" is successful, the "command2" will be executed.

Which one is wrong? - Choice B is incorrect. In this coding, using the &&, both commands must execute to make this work properly.

Which of the following statements is wrong? A. "> tmp" will redirect standard output to a file "tmp" and overwrite the file content. B. ">> tmp" will redirect standard output to a file "tmp" in an append mode. C. "> tmp 2>&1" will redirect standard output and standard error to a file "tmp" and overwrite the file content. D. "2>&1 > tmp" will redirect standard output and standard error to a file "tmp" and overwrite the file content.

Which one is wrong? - Choice D is incorrect. In this coding, putting the ""tmp"" in the incorrect location will not work. It must go in the beginning, not after.

Which of the following commands can print out the full pathname of the current working directory? A. echo PWD B. echo ${PWD} C. echo pwd D. echo $pwd

Which prints out this? - Choice B is correct. Using echo in this way will print out the full pathname of the current directory.

The regular expression used in the command grep -E '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' file is not able to produce _____ on matching IP addresses in the text? A. True positive B. False positive C. True negative D. False negative

Which regular expression (RE) is not able to produce? - Choice D is not possible to produce from the text. The other 3 is possible to produce from the text.

Which of the following statement is correct for searching out files which have "setuid" bit on? A. find / -type f \( -perm -2000 \) B. find / -type f \( -perm -4000 \) C. find / -type f \( -perm 2000 \) D. find / -type f \( -perm 4000 \)

Which statement is correct? - Choice B statement is correct for searching out files which have the ""setuid"" bit on. NOTE: THERE IS A DASH BEFORE THE PERMISSION NUMBER

Which of the following statements regarding the hard drive is correct? A. SSD has a longer lifetime than disk drive. B. The hard drive cables have the limited length because we want to ensure the signal quality while the signal transmitted on the cable will attenuate quickly. C. OS can be installed on an extended partition. D. On a hard drive we can create five prime partitions.

Which statement is correct? - Choice B statement is correct regarding the hard drive.

File "f.txt" belongs to a user named "steal" and a group named "steal", it has the permission bits of "rwxr-xr--", which of the following statements is wrong? A. "f.txt" can be written by user "steal" B. "f.txt" can be written by users in group "steal" C. "f.txt" can be read by all the users D. "f.txt" can be executed by user "steal" and users in group "steal"

Which statement is wrong? - Choice B statement is incorrect. Using f.txt can not be written by the users in this group because the permissions are not set properly for the user group. These permissions in this question do not give the group the permission to write, it only allows the group to read and execute.

Which of the following structure can represent all the processes and their relations in the Linux? A. linkedlist B. array C. tree D. map

Which structure can represent all the processes and relations? - Choice C structure can represent all the processes and their relations in Linux.

Which symbol can express the pattern position in regular expression? A. * B. . C. ? D. $

Which symbol is used? - Choice D is the correct symbol that can be used to express the pattern position in regular expression.

Which text will not be matched by the regular expression 'A.*E'? A. AE B. AIRPLANE C. AIRPLANEDELTA D. A LONG WAY FROM HERE

Which text will not match? - Choice C text will not be matched by the regular expression 'A.*E'.

Which of the following statements about the wildcard is wrong? A. "*" is used to match any string in arbitrary length. B. "?" is used to match any single character. C. "[]" is used to match any single character from a set of characters. D. "[!]" is used to match any arbitrary length string composed from a set of characters.

Which wild card is wrong? - Choice D is an incorrect way to use a wildcard. In this coding, using the explaination point in the square brackets will not work properly.

User "A" own an executable file called "steal.sh". The setuid bit is turned on for this file. This user also grants user "B" the execution permission on his file. When "B" run this file from his bash, there will be a process forked from "B"'s bash process. Now who is the owner of the process corresponding to this file? A. User "A" B. User "B" C. Both user "A" and user "B" D. Who knows!

Who is the owner? - Choice A is the owner of the process corresponding to this file.

* Key

Wildcard - Matches any characters / or All files

cp item...directory

Wildcard Example - copies multiple items (either files or directories) into a directory

cp item 1 item2

Wildcard Example - copies the single file or directory item1 to the file or directory item

Write a complete command to define a variable called "foo" with a value of "echo ls > ./foo.txt".

Write a command. - foo='echo ls > ./foo.txt'

Write a complete command to kill (I really mean to kill) the process whose pid is 3390.

Write a command. - kill -9 3390

Write a wildcard to match all the file names that start with neither character "a" nor character "c" and end with any single character then ".d".

Write code. - [!ac]*?.d

cp -r dir1 dir2

cp example - Copy the contents of directory dir1 to directory dir2. If directory dir2 does not exist, it is created and, after the copy, will contain the same contents as directory dir1. If directory dir2 does exist, then directory dir1 (and its contents) will be copied into dir2.

cp -u

cp option - ""--update - When copying files from one directory to another, only copy files that either don't exist or are newer than the existing corresponding files, in the destination directory. This is useful when copying large numbers of files as it skips files that don't need to be copied.

cp -I

cp option - "--interactive - Before overwriting an existing file, prompt the user for confirmation.

cp -r

cp option - "--recursive - Recursively Copy directories and their contents.

cp -v

cp option - "--verbose - Display informative messages as the Copy is performed.

mv dir1 dir2

mv example - If directory dir2 does not exist, create directory dir2 and move the contents of directory dir1 into dir2 and delete directory dir1. If directory dir2 does exist, move directory dir1 (and its contents) into directory dir2.

mv file1 file2 dir1

mv example - Move file1 and file2 into directory dir1. The directory dir1 must already exist.

mv file1 file2

mv example - Move file1 to file2. If file2 exists, it is overwritten with the contents of file1. If file2 does not exist, it is created. In either case, file1 ceases to exist.

mv -i file1 file2

mv example - Same as the previous command, except that if file2 exists, the user is prompted before it is overwritten.

mv -u

mv option - "--update - When moving files from one directory to another, only move files that either don't exist, or are newer than the existing corresponding files in the destination directory.

mv -v

mv option - "--verbose - Display informative messages as the move is performed.

mv item... directory

mv option - move one or more items from one directory to another

mv item1 item2

mv option - move or rename the file or directory item1 to item2

ls-a --almost-all

option - This option is used with the ls command - it means Like the -a option above except it does not list . (current directory) and .. (parent directory).

ls -a --all

option - This option is used with the ls command - it means List all files, even those with names that begin with a period, which are normally not listed (that is, hidden).

ls -d --directory

option - This option is used with the ls command - it means Ordinarily, if a directory is specified, ls will list the contents of the directory, not the directory itself. Use this option in conjunction with the -l option to see details about the directory rather than its contents.

ls -t

option - This option is used with the ls command - it means Sort by modification time.

ls -S

option - This option is used with the ls command - it means Sort results by file size.

rm -v

rm example - "--verbose - Display informative messages as the deletion is performed.

rm -r file1 dir1

rm example - Delete file1 and dir1 and its contents.

rm file1

rm example - Delete file1 silently.

rm -i file1

rm example - Same as the previous command, except that the user is prompted for confirmation before the deletion is performed.

rm *.html

rm example - delete just the HTML files in a directory

rm item...

rm option - used to remove (delete) files and directories

">"

Redirect - stdout so that output from command goes to a file (instead of console)

">>"

Redirect - stdout so that output is appended to a file

What does the Bash acronym mean?

Acronym - Bourne Again Shell

ls with wildcard *

COMMAND - The ls command is used to list a directories contents. The wildcards (also known as globbing) which allows us to select filenames based on patterns of characters. The wildcard "" * "" used with the ls command matches any string of characters [including null string]

ls with wildcard ?

COMMAND - The ls command is used to list a directories contents. The wildcards (also known as globbing) which allows us to select filenames based on patterns of characters. The wildcard "" ? "" used with the ls command matches any single character (but not null)

Can a Symbolic link work across a file system? Why?

Can this work? - Yes, a symbolic link can link across file systems and directories or even across machines. Symbolic links were created to overcome the limitations of hard links. They are a special type of file that contains a text pointer to the target file or directory. Symbolic links work by creating a special type of file that contains a text pointer to the referenced file or directory. In this regard, they operate in much the same way as a Windows shortcut, though of course they predate the Windows feature by many years. A file pointed to by a symbolic link, and the symbolic link itself are largely indistinguishable from one another. For example, if we write something to the symbolic link, the referenced file is written to. However when we delete a symbolic link, only the link is deleted, not the file itself. If the file is deleted before the symbolic link, the link will continue to exist but will point to nothing. In this case, the link is said to be broken. In many implementations, the ls command will display broken links in a distinguishing color, such as red, to reveal their presence.

mkdir

Command - Create directories

ln

Command - Create hard and symbolic links

CNTRL h

Command - Display help screen

adduser

Command - In Ubantu, you can create a new user account named username using the adduser command you would run:

ls

Command - List directory contents

fdisk

Command - The fdisk is used to create one or more partitions to a disk drive. Danger Will Robinson! • We will use fdisk to create partitions on the drives • It is destructive (to the whole drive, pretty much) • So as usual, BE CAREFUL!!! • Let's pretend we have a new disk and that the device name is /dev/sdb • How do you know the device name? • You kind of have to poke around in /dev and know the way the disks are numbered. Let's worry about it later. • You run sudo fdisk /dev/sdb • May have to specify /sbin/fdisk depending on your path • It is a very simple menu • p - print the table • n - add a new partition • l - list the partition types • Etc. It's kind of hard to describe without doing it • Eventually you get it the way you want it • All editing is done in memory right up the point where you ... • w - write out the partition table • This exits the program • q - quits without saving • A common thing to do is to allocate the whole disk to the partition

Fstab

Command - The file named /etc/fstab (short for "file system table") lists the devices (typically hard disk partitions) that are to be mounted at boot time. Here is an example /etc/ fstab file from an early Fedora system: LABEL=/12 / ext4 defaults 1 1 LABEL=/home /home ext4 defaults 1 2 LABEL=/boot /boot ext4 defaults 1 2 tmpfs /dev/shm tmpfs defaults 0 0 devpts /dev/pts devpts gid=5,mode=620 0 0 sysfs /sys sysfs defaults 0 0 proc /proc proc defaults 0 0 LABEL=SWAP-sda3 swap swap defaults 0 0 Most of the file systems listed in this example file are virtual and not applicable to our discussion. For our purposes, the interesting ones are the first three: LABEL=/12 / ext4 defaults 1 1 LABEL=/home /home ext4 defaults 1 2 LABEL=/boot /boot ext4 defaults 1 2 These are the hard disk partitions. Each line of the file consists of six fields. /etc/fstab Fields Field Contents Description 1 Device Traditionally, this field contains the actual name of a device file associated with the physical device, such as /dev/sda1 (the first partition of the first detected hard disk). But with today's computers, which have many devices that are hot pluggable (like USB drives), many modern Linux distributions associate a device with a text label instead. This label (which is added to the storage media when it is formatted) can be either a simple text label or a randomly generated UUID (Universally Unique Identifier). This label is read by the operating system when the device is attached to the system. That way, no matter which device file is assigned to the actual physical device, it can still be correctly identified. 2 Mount point The directory where the device is attached to the file system tree. 3 File system type Linux allows many file system types to be mounted. Most native Linux file systems are Fourth Extended File System (ext4), but many others are supported, such as FAT16 (msdos), FAT32 (vfat), NTFS (ntfs), CD-ROM (iso9660), etc. 4 Options File systems can be mounted with various options. It is possible, for example, to mount file systems as readonly or to prevent any programs from being executed from them (a useful security feature for removable media). 5 Frequency A single number that specifies if and when a file system is to be backed up with the dump command. 6 Order A single number that specifies in what order file systems should be checked with the fsck command.

find

Command - The find command is used to "depth-first" search in a file system. Slide notes: General usage: find <options> <directories> <expression> <action> • <directories> : one or more directories (and subdirectories) to search • <expression> : matching criteria such as • filename, file permissions, file owner, file modification time, file type, etc. • <action> : what to do for matches, such as print, or execute a specified command • Default: Print name of matching filesfind • Why "find"? Since we have "ls" etc. with wildcard • Heavier tool • Much more powerful • Based on file name pattern • Wildcard: * ? • Find: formal REGULAR EXPRESSION using ^ $ * etc. • Try to find all files with more than two consecutive "a" like "aa.txt" and "abaaa.txt" • By default RECURSIVELY! • Based on almost all file properties! • Examples • find / -name '*.sh' | head -2 => • /lib/init/vars.sh • /lib/init/usplash-fsck-functions.sh • find / -name '*.sh' | tail -2 => • /var/lib/update-rc.d/devpts.sh • /var/lib/update-rc.d/hwclock.sh • find / -name '*.sh' | wc -l => 160find • -type • f - file • d - directory • c or b - character or block device • l - symbolic link • -size • +1m larger than one meg • -128k smaller than 128K • -newer • Compare timestamps to a file and tell me which are newer (let me tell you more)

locate

Command - The locate command searches database for any files, anywhere, that match the search • Uses a prebuilt (or builds it) file database • Expect a lot of matches • Usage: locate <options> <pattern> • In past semesters, the version of Linux we were using linked locate to slocate, described as a security enhanced version of locate • ls -l /usr/bin/locate => /usr/bin/locate -> slocate • So, a request to run locate really ran slocate instead But we dont use it anymore.

ps

Command - The ps command is used to report a snapshot of the current process. The most commonly used command to view processes (there are several) is ps. The ps program has a lot of options, but in its simplest form it is used like this: [me@linuxbox ~]$ ps PID TTY TIME CMD 5198 pts/1 00:00:00 bash 10129 pts/1 00:00:00 ps The result in this example lists two processes, process 5198 and process 10129, which are bash and ps respectively. As we can see, by default, ps doesn't show us very much, just the processes associated with the current terminal session. To see more, we need to add some options, but before we do that, let's look at the other fields produced by ps. TTY is short for "teletype," and refers to the controlling terminal for the process. Unix is showing its age here. The TIME field is the amount of CPU time consumed by the process. As we can see, neither process makes the computer work very hard. If we add an option, we can get a bigger picture of what the system is doing. [me@linuxbox ~]$ ps x PID TTY STAT TIME COMMAND 2799 ? Ssl 0:00 /usr/libexec/bonobo-activation-server -ac 2820 ? Sl 0:01 /usr/libexec/evolution-data-server-1.10 -- 15647 ? Ss 0:00 /bin/sh /usr/bin/startkde 15751 ? Ss 0:00 /usr/bin/ssh-agent /usr/bin/dbus-launch -- 15754 ? S 0:00 /usr/bin/dbus-launch --exit-with-session 15755 ? Ss 0:01 /bin/dbus-daemon --fork --print-pid 4 -pr 15774 ? Ss 0:02 /usr/bin/gpg-agent -s -daemon 15793 ? S 0:00 start_kdeinit --new-startup +kcminit_start 15794 ? Ss 0:00 kdeinit Running... 15797 ? S 0:00 dcopserver -nosid and many more... Adding the "x" option (note that there is no leading dash) tells ps to show all of our pro- cesses regardless of what terminal (if any) they are controlled by. The presence of a "?" in the TTY column indicates no controlling terminal. Using this option, we see a list of every process that we own. Since the system is running a lot of processes, ps produces a long list. It is often helpful to pipe the output from ps into less for easier viewing. Some option combinations also produce long lines of output, so maximizing the terminal emulator window may be a good idea, too.

unmount

Command - The unmount command allows you to unmount or ""detach"" filesystems from your device, making the files on the device. Example: mount /dev/sdc1 /home/userX @mounts the device sdc1 unmount / dev/sdc1 @unmounts the device sdc1

file commands

Command - These are some of the commands that are used with files: ls - List directory contents (use ls -l wildcard or others to filter your findings) file - Determine file type (determines a files contents) less - View file contents per single page. cp - Copies files and directories mv - Moves/renames files and directories rm - Removes files and directories ln - Creates hard and symbolic links

remove

Command - Using the remove command, you can remove the specified package from the machine. Example: apt-get remove vim Vim is the package that will be removed from the machine.

install

Command - Using the update command, you can install the latest for everything available.

update

Command - Using the update command, you can update the packages in Debian. Example: apt-get update This will update my list of available packages

upgrade

Command - Using the upgrade command, you can upgrade all your extisting packages to the latest versions in Debian. Example: apt-get upgrade This will update my list of available packages

The Current Working Directory

Definition - A file manager which represnts the file system tree. When your in a file, you can access other files in the directory above (also called the parent directory) and any subdirectories below. The directory your currently in is this thing. To display this by using the pwd (print working directory)command.

Bash

Definition - The shell program that all Linux distributions supply from the GNU Project. This is a reference to the fact that this is an enhanced replacement for sh, which was the original Unix shell program written by Steve Bourne. But don't get that confused with the man who created Linux which was Linus Torvalds in 1991.

Relative Pathnames

Definition - This starts from the working directory. To do this, it uses a couple of special notations to represent relative positions in the file system tree. These special notations are "." (dot) and ".." (dot dot). The "." notation refers to the working directory and the ".." notation refers to the working directory's parent directory. Here is how it works. Let's change the working directory to /usr/bin again. [me@linuxbox ~]$ cd /usr/bin [me@linuxbox bin]$ pwd /usr/bin Now let's say that we wanted to change the working directory to the parent of /usr/ bin which is /usr. We could do that two different ways, either using an absolute pathname. [me@linuxbox bin]$ cd /usr [me@linuxbox usr]$ pwd /usr or, using a relative pathname. [me@linuxbox bin]$ cd .. [me@linuxbox usr]$ pwd /usr

Variable

Environmental variable - A variable is a storage location (identified by a memory address) paired with an associated symbolic name (an identifier), which contains some known or unknown quantity of information referred to as a value. • The variable name is the usual way to reference the stored value, in addition to referring to the variable itself, depending on the context. Why need it? • Scope • Naming conventions • Named variable with assigned value (of course) • Set: <name>=<value> • No spaces either side of ""="" • <value> interpreted as a string • Names are case-sensitive • Get: $<name> • Unset: unset <name> ...or <name>= • any shell variable not assigned has default value of """" (empty string) $classid=CYBR3350 Instantiates a shell variable Name: classid Value: CYBR3350 (string) $echo classid => classid Value of the argument was classid $echo $classid => CYBR3350 Value of the argument was iasc3350 the $ prefix changed how the shell variable was evaluated $echo '$classid' => $classid Single quote inhibits the evaluation $echo "$classid" => CYBR3350 Double quotes permit the evaluation ... Double quotes work differently than single quotes $echo Value of \$classid is $classid => Value of $classid is CYBR3350 The "\" prefix changed how the shell variable was evaluated... just as the "\" prefix escaped the aliased definition for \ls, the "\" prefix in this example escapes the "$" operator $echo PWD => PWD $echo $PWD => /home/ruizhao $echo pwd => pwd Shell variable names are case-sensitive $echo $pwd => <nothing> Value of unassigned shell variable is empty string Note that the variables are case-sensitive $pwd => /home/ruizhao This is the result of running the command pwd, not the result of evaluating any shell variable $echo $(pwd) => /home/ruizhao This is also the result of running the command pwd... the command inside $(<cmd>) is executed and its value passed as an argument to echo This is called command substitution... spawns a subshell This is why we need $(( for expressions and not just $( $echo 'pwd' => /home/ruizhao Archaic back-quote syntax for command substitution (still used, in particular by your instructor who is old enough to remember it) $echo ${PWD} => /home/ruizhao $<name> is actually simple syntax form of ${<name>}

$PATH

Environmental variable - PATH is an environmental variable in Linux and other Unix-like operating systems that tells the shell which directories to search for executable files (i.e., ready-to-run programs) in response to commands issued by a user.

export

Environmental variable - The export command is used when defining an environmental variable. You first have to define the environmental variables name and value (assignment/set), then exporting it with the export command *export - Export environment to subsequently executed programs • export <name>=<value> • export -p You can also say that the export command tells the shell to make the contents of PATH available to child processes of this shell.

Examples of using ls Command

Example - [me@linuxbox ~]$ ls Desktop Documents Music Pictures Public Templates Videos Besides the current working directory, we can specify the directory to list, like so: me@linuxbox ~]$ ls /usr bin games include lib local sbin share src We can even specify multiple directories. In the following example, we list both the user's home directory (symbolized by the "~" character) and the /usr directory. [me@linuxbox ~]$ ls ~ /usr /home/me: Desktop Documents Music Pictures Public Templates Videos /usr: bin games include lib local sbin share src

Can a Hard link work across a file system? Why?

File and directory commands - No, a hard link can not work across a file system. Hard links have two important limitations: 1. A hard link cannot reference a file outside its own file system. This means a link cannot reference a file that is not on the same disk partition as the link itself. 2. A hard link may not reference a directory. A hard link is indistinguishable from the file itself. Unlike a symbolic link, when we list a directory containing a hard link we will see no special indication of the link. When a hard link is deleted, the link is removed but the contents of the file itself continue to exist (that is, its space is not deallocated) until all links to the file are deleted.

The "find" command implements the _____ algorithm regarding searching tree data structures. A. breadth-first search B. depth-first search C. greedy best first search D. Who knows!

Fill in the blank. - Choice B algorithm is implemented by the "find" command regarding searching tree data structure.

How do you use ps with grep?

How do you use? - You can use the external command " ps " and " grep " to run a report of job processes by PID, not by jobs. Example: • ps -ef • ps -ef | grep apache (This code will show the following) top - 16:21:20 up 1:06, 40 users, load average: 4.54, 4.66, 4.73 Tasks: 377 total, 1 running, 372 sleeping, 4 stopped, 0 zombie Cpu(s): 4.9%us, 1.0%sy, 0.0%ni, 79.5%id, 14.5%wa, 0.0%hi, 0.0%si, 0.0%st Mem: 32945680k total, 3838940k used, 29106740k free, 520808k buffers Swap: 61921276k total, 0k used, 61921276k free, 1994120k cached PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 28672 tdandrew 20 0 9787m 18m 8896 S 3 0.1 0:00.09 java 595 root 20 0 0 0 0 S 2 0.0 0:20.86 md0_raid10 629 root 20 0 0 0 0 S 1 0.0 0:28.77 jbd2/dm-0-8 6530 gitit 20 0 303m 37m 29m S 1 0.1 0:23.56 gitit 6758 postfix 20 0 23260 2252 1692 D 1 0.0 0:20.80 qmgr 28622 wmahoney 20 0 10252 1496 956 R 1 0.0 0:00.06 top 26 root 20 0 0 0 0 S 0 0.0 0:00.82 kworker/5:0 2619 mysql 20 0 603m 82m 7528 S 0 0.3 0:02.62 mysqld 6418 ntp 20 0 37772 2244 1616 S 0 0.0 0:00.13 ntpd 6458 postgres 20 0 96160 1584 364 S 0 0.0 0:00.07 postgres 10285 tdandrew 20 0 17224 5676 1596 S 0 0.0 0:00.21 bash

How do you kill a process?

How do you? - The kill command will send the signals to the desired process • Can send them by abbreviated name • -HUP • -USR1 • -INT • Can send them by number • -1 • -9 • -15 • The most nasty killer • kill -9 pid • Signal 9 is SIGKILL • Eliminates the process and the program can not ignore or handle it • Root can kill just about anyone • You can only kill processes that you started • But killing is by PID not by login • So I can kill processes started on a different terminal session

How do you put a process run on background (2 ways)?

How do you? - To launch a program so that it is immediately placed in the background, we follow the command with an ampersand (&) character. [me@linuxbox ~]$ xlogo & [1] 28236 [me@linuxbox ~]$ After entering the command, the xlogo window appeared and the shell prompt returned, but some funny numbers were printed too. This message is part of a shell feature called job control. With this message, the shell is telling us that we have started job number 1 ([1]) and that it has PID 28236. If we run ps, we can see our process. [me@linuxbox ~]$ ps PID TTY TIME CMD 10603 pts/1 00:00:00 bash 28236 pts/1 00:00:00 xlogo 28239 pts/1 00:00:00 ps If a job is suspended by using the ^Z, you can restart the job in the background by using "" bg "" command.

How do you show all the processes on the machine (2 ways)?

How do you? - Using the ps search command with the "" x "" option shows all of our processes regardless of what terminal (if any) they are controlled by. Example: [me@linuxbox ~]$ ps x PID TTY STAT TIME COMMAND 2799 ? Ssl 0:00 /usr/libexec/bonobo-activation-server -ac 2820 ? Sl 0:01 /usr/libexec/evolution-data-server-1.10 -- 15647 ? Ss 0:00 /bin/sh /usr/bin/startkde 15751 ? Ss 0:00 /usr/bin/ssh-agent /usr/bin/dbus-launch -- 15754 ? S 0:00 /usr/bin/dbus-launch --exit-with-session 15755 ? Ss 0:01 /bin/dbus-daemon --fork --print-pid 4 -pr 15774 ? Ss 0:02 /usr/bin/gpg-agent -s -daemon 15793 ? S 0:00 start_kdeinit --new-startup +kcminit_start 15794 ? Ss 0:00 kdeinit Running... 15797 ? S 0:00 dcopserver -nosid and many more... Note: The presence of a "?" in the TTY column indicates no controlling terminal. Using this option, we see a list of every process that we own. Since the system is running a lot of processes, ps produces a long list. It is often helpful to pipe the output from ps into less for easier viewing. Some option combinations also produce long lines of output, so maximizing the terminal emulator window may be a good idea, too

how does rwx on directories?

How does this look? - When dealing with directories, the permissions for these directories is important. Here is what can be set to use, view, or create a directory. Same principles as a file permission. • R - permission to read the directory (see details about the files in the directory) assuming X is also set • W - permission to write the directory (I can create files in it, rename files, delete them, and change the attributes of the directory itself) assuming X is also set • X - permission to traverse the directory (go into the directory and access the files inside, including sub-directories) • By the way, the sticky bit for directories states that files and directories within that directory may only be deleted or renamed by their owner (or root) - BUT this varies from system to system in my experience

Symbolic Link

Link - Symbolic links point to the file itself. You can create a symbolic link by using "" ln -s "" Notes about a Symbolic links: • One filename points to another filename • Works across filesystems • To create softlinks use ln -s • A Symbolic Link is an indirect pointer to a file • You can create a symbolic link to a directory • A symbolic link can point to a file on a different file system • A symbolic link can point to a nonexistent file (referred to as a "broken link") • -s (creates a symbolic link) • Can link directories this way; can't do that with a hard link • Can link across file systems or even across machines Lets show what one looks like using ls -l: $ ls -l mydir => lrwxrwxrwx 1 steal steal 7 Oct 29 15:41 my-soft-link -> myfile.txt Example: $ ln -s file2 file2-soft

What is a process?

What is? - A process is sometime referred as task. • A process has its own address space. A Job or Command may consist of several processes working together to perform a single task • Process: Single executable running in own address space • A process may consist of several threads • System processes • Started at boot type (typically) • SFTP servers, login processes, ... • Worry about these later in the semester • Interactive Processes • Controlled by a terminal session • Includes Foreground processes • Attached to terminal • Can only be one foreground process per terminal • Includes Background processes • Detached • Multiple background processes permitted

What is ppid?

What is? - In addition to a unique process ID, each process is assigned a parent process ID (PPID) that tells which process started it. The PPID is the PID of the process's parent. For example, if process1 with a PID of 101 starts a process named process2, then process2 will be given a unique PID, such as 3240, but it will be given the PPID of 101. It's a parent-child relationship. A single parent process may spawn several child processes, each with a unique PID but all sharing the same PPID. Why is the PPID Important? Occasionally, processes go bad. You might try to quit a program only to find that it has other intentions. The process might continue to run or use up resources even though its interface closed. Sometimes, this leads to what is called a zombie process, a process that is still running, but dead. One effective way to kill a zombie process is to kill its parent process. This involves using the ps command to discover the PPID of the zombie process and then sending a kill signal to the parent. Of course, any other children of the parent process will be killed as well.

What is a pid?

What is? - PID stands for process ID. It is a numeric id assigned to each process that is given to track each process. The external PS commands track the processes by JOB_SPEC. When killing a process, you refer to this number so specify what to kill. Example: (We use "" ps "" to view the PID's here) [me@linuxbox ~]$ ps PID TTY TIME CMD 5198 pts/1 00:00:00 bash 10129 pts/1 00:00:00 ps

What is a processes parent processes?

What is? - The boot process starts a single process which is the parent process. Then from the parrent, other processes can be spawned (called forking) creating new parent processes or children processes. Each time a new process is created, each process gets its own PID number (Process ID's).

What is unmasks conversion to octal number permission for files and directories?

What is? - The umask command controls the default permissions given to a file when it is created. It uses octal notation to express a mask of bits to be removed from a file's mode attributes. Ex. [me@linuxbox ~]$ rm -f foo.txt [me@linuxbox ~]$ umask 0002 [me@linuxbox ~]$ > foo.txt [me@linuxbox ~]$ ls -l foo.txt -rw-rw-r-- 1 me me 0 2018-03-06 14:53 foo.txt We first removed any old copy of foo.txt to make sure we were starting fresh. Next, we ran the umask command without an argument to see the current value. It responded with the value 0002 (the value 0022 is another common default value), which is the octal representation of our mask. We next create a new instance of the file foo.txt and observe its permissions. We can see that both the owner and group get read and write permission, while everyone else only gets read permission. The reason that world does not have write permission is because of the value of the mask. Let's repeat our example, this time setting the mask ourselves. [me@linuxbox ~]$ rm foo.txt [me@linuxbox ~]$ umask 0000 [me@linuxbox ~]$ > foo.txt [me@linuxbox ~]$ ls -l foo.txt -rw-rw-rw- 1 me me 0 2018-03-06 14:58 foo.txt When we set the mask to 0000 (effectively turning it off), we see that the file is now world writable. To understand how this works, we have to look at octal numbers again. If we take the mask, expand it into binary, and then compare it to the attributes we can see what happens. Original file mode --- rw- rw- rw Mask 000 000 000 010 Result --- rw- rw- r-- Ignore for the moment the leading zeros (we'll get to those in a minute) and observe that where the 1 appears in our mask, an attribute was removed — in this case, the world write permission. That's what the mask does. Everywhere a 1 appears in the binary value of the mask, an attribute is unset. If we look at a mask value of 0022, we can see what it does. Original file mode --- rw- rw- rw Mask 000 000 010 010 Result --- rw- r-- r-- Again, where a 1 appears in the binary value, the corresponding attribute is unset. Play with some values (try some sevens) to get used to how this works. When you're done, remember to clean up. [me@linuxbox ~]$ rm foo.txt; umask 0002 Most of the time we won't have to change the mask; the default provided by the distribution will be fine. In some high-security situations, however, we will want to control it.

What is bash_profile?

What is? - This bash_profile file is where you can add directories to your PATH or define additional environmental variables. Everything else is done in bashrc. Additional lecture slides: During the login scripts, The "bash" shell will look for login scripts • /etc/profile - automatically "sourced" by the shell • ~/.bash_profile - if present, done next • ~/.bash_login - if the profile was not found, try this one • ~/.profile - last resort, fall back to UNIX circa 1980 # .bash_profile # Get the aliases and functions if [ -f ~/.bashrc ]; then # -f: if file exist . ~/.bashrc # .: alias for calling it with the source command fi # User specific environment and startup programs PATH=$PATH:$HOME/bin export PATH unset USERNAME # idea.ist.unomaha.edu wants to have this set in order to do colorization. TERM=xterm-color ; export TERM # Newer GCC can't seem to find the libraries. LD_LIBRARY_PATH=/usr/local/lib:${LD_LIBRARY_PATH} ; export LD_LIBRARY_PATH alias ls="ls --color=auto" To Make It Work • Edit the appropriate file (~/.bash_profile, say) • "Source the script" • . .bash_profile (old, quick way, note the dot) • source .bash_profile (newer, requires typing) • Otherwise you have to log off then log back on for it to work • In general, the "dot space" will source in whatever script you want, even from another script • Note that "running" the script does not work since it runs in a separate shell! • Note that "running" the script does not work since it runs in a separate shell! • The shell looks at the command • Finds the script (explicitly or via PATH) • Starts a shell process to run the script • That shell does whatever is in the script • That shell exits • My shell gives me another prompt • Which has not changed my login shell at all, unless the script exported some variables, for example • Thus, "sourcing" the script!

What is a setuid bit and what does it mean?

What is? - This is always applied to executable files • Processes that execute this kind of file: are given an effective UID whose value is the UID of the file owner • Granting access to resources based on the user owner of the file rather than the owner of the process • "Passwd" • A very dangerous option, especially when the setuid file is owned by root user (0) This is a less used permission setting known as Octal 4000. When applied to an executable file, it sets the effective user ID from that of the real user (the user actually running the program) to that of the program's owner. Most often this is given to a few programs owned by the superuser. When an ordinary user runs a program that is "setuid root" , the program runs with the effective privileges of the superuser. This allows the program to access files and directories that an ordinary user would normally be prohibited from accessing. Clearly, because this raises security concerns, the number of setuid programs must be held to an absolute minimum.

ls Long Listing Fields Examples

example - Using ls Long Listing fields Example -rw-r--r-- 1 root root 3576296 2017-04-03 11:05 Experience ubuntu.ogg -rw-r--r-- 1 root root 1186219 2017-04-03 11:05 kubuntu-leaflet.png -rw-r--r-- 1 root root 47584 2017-04-03 11:05 logo-Edubuntu.png -rw-r--r-- 1 root root 44355 2017-04-03 11:05 logo-Kubuntu.png -rw-r--r-- 1 root root 34391 2017-04-03 11:05 logo-Ubuntu.png -rw-r--r-- 1 root root 32059 2017-04-03 11:05 oo-cd-cover.odf -rw-r--r-- 1 root root 159744 2017-04-03 11:05 oo-derivatives.doc -rw-r--r-- 1 root root 27837 2017-04-03 11:05 oo-maxwell.odt -rw-r--r-- 1 root root 98816 2017-04-03 11:05 oo-trig.xls -rw-r--r-- 1 root root 453764 2017-04-03 11:05 oo-welcome.odt -rw-r--r-- 1 root root 358374 2017-04-03 11:05 ubuntu Sax.ogg -rw-r--r-- Access rights to the file. The first character indicates the type of file. Among the different types, a leading dash means a regular file, while a "d" indicates a directory. The next three characters are the access rights for the file's owner, the next three are for members of the file's group, and the final three are for everyone else. Chapter 9 ""Permissions"" discusses the full meaning of this in more detail. 1 File's number of hard links. See the sections ""Symbolic Links"" and ""Hard Links"" later in this chapter. root The username of the file's owner. root The name of the group that owns the file. 32059 Size of the file in bytes. 2007-04-03 11:05 Date and time of the file's last modification. oo-cd-cover.odf Name of the file.

ls example

example - [me@linuxbox ~]$ ls

Examples of using ls -l Command

example - [me@linuxbox ~]$ ls -l total 56 drwxrwxr-x 2 me me 4096 2017-10-26 17:20 Desktop drwxrwxr-x 2 me me 4096 2017-10-26 17:20 Documents drwxrwxr-x 2 me me 4096 2017-10-26 17:20 Music drwxrwxr-x 2 me me 4096 2017-10-26 17:20 Pictures drwxrwxr-x 2 me me 4096 2017-10-26 17:20 Public drwxrwxr-x 2 me me 4096 2017-10-26 17:20 Templates drwxrwxr-x 2 me me 4096 2017-10-26 17:20 Videos By adding "-l" to the command, we changed the output to the long format.

Examples of using ls -lt Command

example - [me@linuxbox ~]$ ls -lt This command is given two options, which are the l option to produce long format output, and the t option to sort the result by the file's modification time.

Examples of using ls -lt --reverse Command

example - [me@linuxbox ~]$ ls -lt --reverse This command is given two options, which are the l option to produce long format output, and the t option to sort the result by the file's modification time then adding the last option will reverse the entire output.

pwd example

example - [me@linuxbox ~]$ pwd /home/me

Symbolic Link example

example - lrwxrwxrwx 1 root root 11 2007-08-11 07:34 libc.so.6 -> libc-2.6.so


संबंधित स्टडी सेट्स

Using Technology to Change the World

View Set

Real Estate, Chapter 2, Section 3 (Leasehold Estates), Pop Quiz Questions 3.1

View Set