Linux Quiz 1 - Chapter 1-4 / Lecture 1-4

¡Supera tus tareas y exámenes ahora con Quizwiz!

What does the Bash acronym mean?

Acronym - Bourne Again Shell

CNTRL D

COMMAND - STOP PROCESS

alias

COMMAND - a shortcut to simplify a long winded command

sort

COMMAND - arranges lines of text in order of concatenation of files

which

COMMAND - finds the binary executable of the program (if it is in your PATH) RETURNS THE PATH OF THE EXECUTABLE

whereis

COMMAND - finds the binary, the source, and the man page files for a program

info

COMMAND - gives info on a file

man

COMMAND - manual

uniq

COMMAND - operates on consecutie, duplicate lines of text

head and tail

COMMAND - output first / last part of a file

tee

COMMAND - puts a "T" in your pipeline and adds a branch

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

cd

Command - Change directory

" cp

Command - Copy files and directories

mkdir

Command - Create directories

ln

Command - Create hard and symbolic links

" file

Command - Determine file type

CNTRL h

Command - Display help screen

ls

Command - List directory contents

1G or g

Command - Move to the beginning of the text file

G

Command - Move to the end of the text file

mv

Command - Move/rename files and directories

pwd

Command - Print name of current working directory

CNTRL Q

Command - Quit less

rm

Command - Remove files and directories

" Page Up or b

Command - Scroll back one page

Down arrow

Command - Scroll down one line

Page Down or space

Command - Scroll forward one page

Up arrow

Command - Scroll up one line

CNTRL n

Command - Search for the next occurrence of the previous search

/characters

Command - Search forward to the next occurrence of characters

" "less

Command - This allows us to scroll forward and backward through a text file. For example, to examine the file that defines all the system's user accounts, enter the following command: [me@linuxbox ~]$ less /etc/passwd Once this program starts, we can view the contents of the file. If the file is longer than one page, we can scroll up and down. To exit this command, press the q key.

exit

Command - This will end a terminal session by either closing the terminal emulator window. Ctrl-d shortcut.

less

Command - View file contents

free

Command - display the amount of free memory

cal

Command - displays a calendar of the current month.

df

Command - displays the current amount of free space on our disk drives

date

Command - displays the current time and date.

"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

"File System Tree

Definition - A Unix-like operating system such as Linux organizes its files in what is called a hierarchical directory structure. This means they are organized in a pattern of directories (sometimes called folders in other systems), which may contain files and other directories.

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 orignial Unix shell program written by Steve Bourne.

" "Absolute Pathnames

Definition - This begins with the root directory and follows the tree branch by branch until the path to the desired directory or file is completed. For example, there is a directory on our system in which most of our system's programs are installed. The directory's pathname is /usr/bin. This means from the root directory (represented by the leading slash in the pathname) there is a directory called ""usr"" which contains a directory called ""bin"". [me@linuxbox ~]$ cd /usr/bin [me@linuxbox bin]$ pwd /usr/bin [me@linuxbox bin]$ ls = ...Listing of many, many files ... Now we can see that we have changed the current working directory to /usr/bin and that it is full of files. Notice how the shell prompt has changed? As a convenience, it is usually set up to automatically display the name of the working directory.

Terminal Emulators

Definition - This gives us access to the shell when using a GUI (Graphical User Interface) which interacts with the shell. KDE uses knosole and GNOME uses gnome-terminal. There is many kinds, but they all do the same thing which is it gives us access to the shell.

" Root Directory

Definition - This is the 1st directory in the File System Tree. This contains files and subdirectories, which contain more files and subdirectories and so on.

" "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

" command history

Definition - Using the up and down arrows, we will see that the prvious commands will re-appear after the prompt. Most Linux distribution software remember the last 1000 commands by default.

Shell

Definition - program that takes keyboard commands and passes them to the operating system to carry out

"pathname

Definition - the route we take along the branches of the tree to get to the directory we want. We can specify pathnames in one of two different ways; as absolute pathnames or as relative pathnames.

/boot

Directory -

" "/usr/bin

Directory - /usr/bin contains the executable programs installed by the Linux distribution. It is not uncommon for this directory to hold thousands of programs.

"/usr/share

Directory - /usr/share contains all the shared data used by programs in /usr/bin. This includes things such as default configuration files, icons, screen backgrounds, sound files, etc.

" "/var/log

Directory - /var/log contains log files, records of various system activity. These are important and should be monitored from time to time. The most useful ones are /var/log/messages and /var/log/syslog. Note that for security reasons on some systems only the superuser may view log files.

/bin

Directory - Contains binaries (programs) that must be present for the system to boot and run.

" /usr/sbin

Directory - Contains more system administration programs.

" "/lib

Directory - Contains shared library files used by the core system programs. These are similar to dynamic link libraries (DLLs) in Windows.

"/

Directory - Contains the Linux kernel, initial RAM disk image (for drivers needed at boot time), and the boot loader. Interesting files: ● /boot/grub/grub.conf or menu.lst, which are used to configure the boot loader. ● /boot/vmlinuz (or something similar), the Linux kernel.

" "/lost+found

Directory - Each formatted partition or device using a Linux file system, such as ext4, will have this directory. It is used in the case of a partial recovery from a file system corruption event. Unless something really bad has happened to our system, this directory will remain empty.

" "/home

Directory - In normal configurations, each user is given a directory in /home. Ordinary users can only write files in their home directories. This limitation protects the system from errant user activity.

" "/usr/share/doc

Directory - Most packages installed on the system will include some kind of documentation. In /usr/share/doc, we will find documentation files organized by package.

" "/media

Directory - On modern Linux systems the /media directory will contain the mount points for removable media such as USB drives, CD-ROMs, etc. that are mounted automatically at insertion.

" "/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.

" "/opt

Directory - The /opt directory is used to install "optional" software. This is mainly used to hold commercial software products that might be installed on the system.

" "/proc

Directory - The /proc directory is special. It's not a real file system in the sense of files stored on the hard drive. Rather, it is a virtual file system maintained by the Linux kernel. The "files" it contains are peepholes into the kernel itself. The files are readable and will give us a picture of how the kernel sees the computer.

" "/tmp

Directory - The /tmp directory is intended for the storage of temporary, transient files created by various programs. Some configurations cause this directory to be emptied each time the system is rebooted.

" "/usr

Directory - The /usr directory tree is likely the largest one on a Linux system. It contains all the programs and support files used by regular users.

"/usr/local

Directory - The /usr/local tree is where programs that are not included with the distribution but are intended for systemwide use are installed. Programs compiled from source code are normally installed in /usr/local/bin. On a newly installed Linux system, this tree exists, but it will be empty until the system administrator puts something in it.

/

Directory - The root directory. Where everything begins.

" /usr/lib

Directory - The shared libraries for the programs in /usr/bin.

"/sbin

Directory - This directory contains "system" binaries. These are programs that perform vital system tasks that are generally reserved for the superuser.

" "/dev

Directory - This is a special directory that contains device nodes. "Everything is a file" also applies to devices. Here is where the kernel maintains a list of all the devices it understands.

" /root

Directory - This is the home directory for the root account.

" "/var

Directory - With the exception of /tmp and /home, the directories we have looked at so far remain relatively static, that is, their contents don't change. The /var directory tree is where data that is likely to change is stored. Various databases, spool files, user mail, etc. are located here.

"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

" "4 Facts about Linux Filenames

Facts - 1. Filenames that begin with a period character are hidden. This only means that ls will not list them unless you say ls -a. When your account was created, several hidden files were placed in your home directory to configure things for your account. In Chapter 11 we will take a closer look at some of these files to see how you can customize your environment. In addition, some applications place their configuration and settings files in your home directory as hidden files. 2. Filenames and commands in Linux, like Unix, are case sensitive. The filenames "File1" and "file1" refer to different files. 3. Linux has no concept of a "file extension" like some other operating systems. You may name files any way you like. The contents and/or purpose of a file is determined by other means. Although Unix-like operating systems don't use file extensions to determine the contents/purpose of files, many application programs do. 4. Though Linux supports long filenames that may contain embedded spaces and punctuation characters, limit the punctuation characters in the names of files you create to period, dash, and underscore. Most importantly, do not embed spaces in filenames. If you want to represent spaces between words in a filename, use underscore characters. You will thank yourself later.

"<"

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

">"

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

">>"

Redirect - stdout so that output is appended to a file

Switching between virtual consoles

Shortcut - Alt-F1 thru Alt-F6

Returning to the graphical desktop

Shortcut - Alt-F7

"cd ~user_name

Shortcut - Changes the working directory to the home directory of user_name. For example, cd ~bob will change the directory to the home directory of user "bob."

cd -

Shortcut - Changes the working directory to the previous working directory.

" cd

Shortcut - Changes the working directory to your home directory.

How to access Virtual Terminal behind the scenes

Shortcut - Ctrl-Alt-F1 to Ctrl-Alt-F6

Copy Paste Trick

Trick - By double clicking on a filename, it will and copy the info, then by doing a middle click, it will paste that info.

BACKUP.[0-9][0-9][0-9]

Wildcard - Any file beginning with "BACKUP." followed by exactly three numerals

Datta???

Wildcard - Any file beginning with "Data" followed by exactly three characters

b*.txt

Wildcard - Any file beginning with "b" followed by any characters and ending with ".txt"

g*

Wildcard - Any file beginning with "g"

[[0-9]]*

Wildcard - Any file beginning with an uppercase letter

[abc]*

Wildcard - Any file beginning with either an "a", a "b", or a "c"

*[[:lower:]123]

Wildcard - Any file ending with a lowercase letter or the numerals "1", "2", or "3"

[![:digit:]]*

Wildcard - Any file not beginning with a numeral

[:alpha:]

Wildcard - Matches any alphabetic character

[:alnum:]

Wildcard - Matches any alphanumeric character

[characters]

Wildcard - Matches any character that is a member of the set characters

[[:class:]]

Wildcard - Matches any character that is a member of the specified class

[!characthers]

Wildcard - Matches any character that is not a member of the set characters

* Key

Wildcard - Matches any characters / or All files

{:lower:]

Wildcard - Matches any lowercase letter

{:digit:]

Wildcard - Matches any numeral

? Key

Wildcard - Matches any single character

[:upper:]

Wildcard - Matches any uppercase letter

cp itme...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

mkdir dir1

Wildcard Example - create a single directory named dir1

mkdir dir1 dir2 dir3

Wildcard Example - create three directories named dir1, dir2, and dir3

apropos

command - finds all the the files that contain the keyword or a command that has to do with the key word

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 -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 dir1/* dir2

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

"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 -a

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

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.

"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.

"shel prompt

example - [me@linuxbox ~]$ This is called a shell prompt and it will appear whenever the shell is ready to accept input. While it may vary in appearance somewhat depending on the distribution, it will typically include your username@machinename, followed by the current working directory and a dollar sign. Note: If the last character of the prompt is a pound sign ("") rather than a dollar sign, the terminal session has superuser privileges. This means either we are logged in as the root user or we selected a terminal emulator that provides superuser (administrative) privileges.

cd

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

" ls

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 - [me@linuxbox ~]$ pwd /home/me

" Symbolic Link

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

"|"

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 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 -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.

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 -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-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.

" "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 -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 -rf file1 dir1

rm example - Same as the previous command, except that if either file1 or dir1 do not exist, rm will continue 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


Conjuntos de estudio relacionados

Key Concepts in Communication & Culture

View Set

1800's and Industrial Revolution - Conway

View Set

Psychology 1301 - DBU BEALE Test 2

View Set

FBLA International/Global Business

View Set

4337 Programming Languages (quiz 1-4) Exam 1

View Set

Writing Workshop: Evaluating Sources That Support a Claim

View Set