COURSE 4 LINUX COMMANDS

Ace your homework & exams now with Quizwiz!

The option -mmin can be used instead of

-mtime if you want to base the search on minutes rather than days.

-G

Adds the user to additional groups, also called supplemental or secondary groups.

What is the purpose of the sudo command?

It temporarily grants elevated permissions to specified users.

rm

Removes, or deletes a file.

Filesystem Hierarchy Standard (FHS)

The component of the Linux OS that organizes data

=

assigns permissions for the user, group, or other.

ls

displays the names of files and directories in the current working directory.

o

indicates changes will be made to other permissions.

You can use the man heir command to

learn more about FHS and its standards directories.

sudo command comes from:

super user do

The grep command commonly takes how many arguments:

two arguments: a specific string to search for and a specific file to search through. For example, entering grep OS updates.txt. returns all lines containing OS in the updates.txt file. In this example, OS is the specific file to search through.

In Linux, file permissions are represented with a:

10-character string. For a directory with full permissions for the user group, this string would be: drwxrwxrwx

relative file path

A file path that starts from the user's current directory.

Root user (or superuser)

A user with elevated privileges to modify the system.

useradd

Adds a user to the system.

Relative file paths can use a dot (.) to represent the current directory, or two dots (..) to represent the parent of the current directory.

An example of a relative file path could be ../projects.

If you enter a command incorrectly and it fails to return to the command-line prompt, you can press ______________ to stop the process and force the shell to return to the command-line prompt.

CTRL+C

-iname

Case-insensitive search for file names.

-name

Case-sensative for file names.

chmod

Changes permissions on files and directories.

cp

Copies a file or directory into a new location.

mkdir

Creates a new directory.

touch

Creates a new file

Nano shortcuts

Ctrl + O to save a file. Ctrl + X to exit.

userdel

Deletes a user from the system.

Once you've accessed your content with the less command, you can use several keyboard controls to move through the file:

Down arrow: move forward one line.

/home

Each user in the system gets their own directory.

To use the -G option, the supplemental group must be passed into the command after -G. You can add more than one supplemental group at a time with the -G option.

Entering sudo useradd -G finance, admin fgarcia adds fgarcia as a new user and adds them to the existing finance and admin groups.

When the path leads to a subdirectories below the user's home directory, the user's home directory can be represented as the tilde (~).

For example, /home/analyst/logs can also be represented as ~/logs

less command returns the content of a file one page at a time.

For example, entering less updates. txt changes the terminal window to display the contents of updates txt one page at a time. This allows you to easily move forward and backward through the content.

cat command displays the content of a file.

For example, entering cat updates. txt returns everything in the updates. txt file.

You can use the relative path and enter cd.. to go up one level in the file structure.

For example, if the current directory us /home/analyst/projects, entering cd.. would change your working directory to /home/analyst

If you want to return the contents of a directory that's not your current working directory, you can add an argument after ls with the absolute or relative file path to the desired directory.

For example, if you're in the /home/analyst directory but want to list the contents if its projects subdirectory, you can enter ls/home/analyst/projects or just ls projects.

When you're inside the directory containing the permissions.txt file, entering echo "last updated date" >> permission.txt adds the string "last updated date" to the file contents. Entering echo "time"> permissions.txt after this command over writes the entire file contents of permissions.txt with the string "time".

Note: Both the > and >> operators will create a new file if one doesn't already exist with your specified name.

pwd (print working directory)

Prints the working directory onto the screen

There are three types of permissions in Linux that an authorized user can have:

Read: read permissions means contents on the file can be read. On a directory, this permission means you can read all the files in the directory write permissions on a file allow modifications of contents of the file. On a directory, write permissions indicate that new files can be created in that directory. Execute permissions on files mean that the file can be executed if it's an executable file. Execute permissions on directories allow users to enter into a directory and access its files. ​

rmdir

Removes, or deletes, a directory

grep

Searches a specified file and returns all lines in the file containing a specified string. Example: analyst@career-certs:~$ grep OS updates.txt Enter and bash returns all lines containing OS: analyst@career-certs:~$: grep OS updates.txt update to OS2: Started... update to OS2: Complete... and so on... analyst@career-certs:~

Problems with logging in as root:

Security risk Irreversible mistakes Accountability

| (piping)

Sends the standard output of one command as standard input to another command for further processing.

sudo

Temporarily grants elevated permissions to specific users.

Authorization

The concept of granting access to specific resources in a system.

When used with echo, the > and >> operators can be used to send the output of echo to specified file rather than the screen.

The difference between the two is that > overwrites your existing file, and >> adds your content to the end of the existing file instead of over writing it. The > operator should be used carefully, because it's not easy to recover over written files.

To move a file enter the mv command followes by two arguments.

The first argument after mv identifies the file to be moved. The second argument indicates where to move it.

absolute file path

The full file path, which starts from the root.

head command displays just the beginning if a file, by default 10 lines.

The head command can be useful when you want to know the basic contents if a file but don't need the full contents. Entering head updates.txt returns only the first 10 lines of thevupdates. txt file.

root directory

The highest-level directory in Linux. It's always represented with a forward slash /.

What does the ls command do?

The ls command displays the names of files in the current working directory.

The pwd command prints the working directory to the screen. Or in other words, it returns the directory that you're currently in.

The output gives you the absolute path to this directory. For example, if you're in your home directory and your user name is analyst, entering pwd returns /home/analyst.

Permissions

The type of access granted for a file or directory

tail command does the opposite if head.

This command can be used to display just the end of a file, by default 10 lines. Entering tail updates txt returns only the last 10 lines of the update txt file.

/mnt

This directory stands for "mount" and stores media, such as USB drives and hard drives.

/etc

This directory stores the system's configuration files.

The cd command navigates between directories. When you need to change directories, you should use this command

To navigate to a subdirectory of the current directory, you can add an argument after cd with the subdirectory name. For example, if you're in /home/analyst/projects, entering cd/home/analyst/logs changes your current directory to /home/analyst/logs.

Once you've accessed your content with the less command, you can use several keyboard controls to move through the file:

Up arrow: move back one line.

Permissions are granted for three different types of owners:

User: is the owner of the file. When you create a file, you become the owner of the file, but ownership can be changed. Group: Every user is a part of a certain group. A group consists of several users, and this is one way to manage a multi-user environment. Other: Other can be considered all other users on the system.

Note: when there are permissions changes to more than one owner type, commas are needed to separate changes for each owner type.

You should not add spaces after those commas.

+

adds permission to the user group, or other

Once you've accessed your content with the less command, you can use several keyboard cintrols to move through the file:

b: move back one page.

If you want to change the permissions on an approved_users.txt file, which command can you use?

chmod

chmod g+w, o-r access.txt

chmod g+w, o-r access.txt user: u group: g other: o

The following command would add all permissions to login_sessions.txt:

chmod u+rwx, g+rwx, o+rwx login_sessions.txt

Following command would take all the permissions away:

chmod u-rwx, g-rwx, o-rwx login_sessions.txt

Another way to assign these permissions is to use the equals sign (=) in the first argument. Using = with chmod sets, or assigns, the permissions exactly as specified. For example, the folliwing command would set read permissions for login_sessions.txt for user, group, and other:

chmod u=r, g=r, o=r login_sessions.txt this command over writes existing permissions. For instance, if the user previously had written permissions, these write permissions are removed after you specify only read permussion with =

When working with a directory, what do write permissions allow users to do?

create new files in that directory.

drwxrwxrwx

d: is used to indicate it is a directory. If this character contains a hyphen instead, it would be a regular file. rwx: the second , third and fourth character indicate the permissions for the user. In this example r indicates the user has read permissions, w, indicates the user has write permissions, and x indicates the user has execute permissions. If any of the permissions was missing there would be a hyphen instead of the letter. In the same way, the fifth, sixth, and seventh characters indicate permissions for the next owner type group. The eight through tenth characters indicate permissions for the last owner type: other. ​

cat

display the content of a file.

ls -a

displays hidden files.

head

displays just the beginning of a file, by default 10 lines.

ls -la

displays permissions to files and directories, including hidden files.

ls -l

displays permissions to files and directories.

Note: In order for grep to interpret a string of two or more words correctly, you must:

enclose it in quotes. e.g. (Human Resources).

The -mtime option search in base on days, so entering -mtime +1 indicates all files or directories last modified more rhan one day ago, and

entering -mtime -1 indicates all files or directories last modified less than one day ago.

To use the -g option, the primary group must be specified after -g. For example:

entering sudo useradd -g security fgarcia adds fgarcia as a new user and assigns their primary group to be security.

To learn what your user name is use the command whoami command. The whoami command returns the username if the current user.

for example, if your user name is analyst, entering whoami returns to analyst.

What command can you enter to search the log.txt file for all lines containing the string error?

grep error log.txt The grep command searches a specified file and returns all lines in the file containing a specified string. Its first argument (error) is the string you are searching for. Its second argument (log.txt) is the file you are searching through.

g

indicates changes will be made to group permissions. ​

u

indicates changes will be made to user permissions.

nano

is a command-line file editor that is available by default in many Linux distributions.

principle of least privilege

is the concept of granting only the minimal access and authorizations required to complete a task or function.

file path

is the location of a file or directory. In the file path the different levels of hierarchy are separated by a forward slash /.

Options

modify the behavior of the command.

mv

moves a file or directory to a new location.

cd

navigates between directories.

Once you've accessed your content emwith the less command, you can use several keyboard controls to move through the file:

q: quit and return to the previous terminal window.

You can use tail to:

read the most recent information in a log file.

-

removes permissions from the user, group, or other.

find command

searches for directories and files that meet specified criteria.

-g

sets the user's default group, also called their primary group.

Once you've accessed your content with the less command, you can use several keyboard controls to move through the file:

space bar move forward one page.

/bin

this directory stands for "binary" and contains binary files and other executables. Executable are files that contain a series of commands a computer needs to follow to run programs and perform other functions.

/tmp

this directory stores many temporary files. The /tmp directory is commonly used by attackers because anyone in the system can modify data in these files.

When describing the directory structure in Linux, slashes are used when tracing back:

through these brances to the root. For example /home/analyst. The first slash indicates the root directory. Then it branches out a level into the home subdirectory. Another slash indicates it is branching out again. This time to the analyst subdirectory that is located with in home.

piping allows what?

to combine commands, making your work more efficient.

cp command to copy the first argument indicates which ile to copy and the second argument provides the path:

to the directory that it will be copied into.

An asterisk (*) is used as a wildcard to represent:

zero or more unknown characters.


Related study sets

Chapter 5: Nevada Statutes and Codes Common to All Lines

View Set

Chapter 10: Artificial Intelligence

View Set

Ch.17 APBIO (The Central Dogma - From Gene to Protein)

View Set