• Shuffle
    Toggle On
    Toggle Off
  • Alphabetize
    Toggle On
    Toggle Off
  • Front First
    Toggle On
    Toggle Off
  • Both Sides
    Toggle On
    Toggle Off
  • Read
    Toggle On
    Toggle Off
Reading...
Front

Card Range To Study

through

image

Play button

image

Play button

image

Progress

1/91

Click to flip

Use LEFT and RIGHT arrow keys to navigate between flashcards;

Use UP and DOWN arrow keys to flip the card;

H to show hint;

A reads text to speech;

91 Cards in this Set

  • Front
  • Back

WHAT IS THE COMMAND LINE INTERFACE CALLED?

THE SHELL

What is the proper syntax for a Linux command?

{ProgramName} {'-'Option} {Argument}

cd

CHANGE DIRECTORY

cd ~

CHANGE DIRECTORY BACK TO HOME DIRECTORY

cd -

CHANGES DIRECTORY TO THE PREVIOUS DIRECTORY

cd ..

GO UP 1 DIRECTORY LEVEL

ls

List the contents of a directory

mkdir

MAKE DIRECTORY

pwd

PRINT


WORKING


DIRECTORY



Displays current working directory

ls

LIST CONTENTS OF DIRECTORY

rm -rf {DIRECTORY}

REMOVES THE DIRECTORY AND ALL FILES AND DIRECTORIES WITHIN (USE WITH CAUTION!)



-r = recursively


-f = force eg. never prompt & ignore any non-existent files & arguments

commonly used ls options

-a : List all files, incl. hidden ones


-color : List files with colorized output


-d : List directory names and not their contents


-l : Long format


-r : List in reverse order


-R : List files recursively


-t : sort by time, most recently modified first


-S : list files by size


-s : list files and show sizes


-n : shows file contents with line numbers


head -n(# of lines) : shows a specific # of lines

mkdir

MAKE DIRECTORY



mkdir -p = make directory with full path, which means create the directory and any sub-directories listed

Command-line is more efficient than GUI. Why?

FASTEST, MOST FLEXIBLE AND SOMETIMES THE ONLY WAY TO ACHIEVE A DESIRED OUTCOME

cp

COPY FILE

cd

CHANGE DIRECTORY

rmdir

REMOVE DIRECTORY

rm

REMOVE

".."

THE ".." CHARACTERS REFER TO THE PARENT OF THE CURRENT WORKING DIRECTORY

tail

SHOWS LAST TEN LINES (OR HOWEVER MANY LINES SPECIFIED IN SYNTAX)

mv

MOVE FILE (OR DIRECTORY?)

head

SHOWS FIRST TEN LINES (OR HOWEVER MANY LINES SPECIFIED IN SYNTAX)

What are the benefits of using a virtual machine?

1) EASY AND INEXPENSIVE OR



ICAL MACHINE

>

REDIRECTS AND OVERWRITES THE OUTPUT (FROM A COMMAND SUCH AS LS, CAT, CP OR MV)

touch

CREATE A NEW & EMPTY FILE

Control + d

EXIT ENTERING TEXT LINES IN A FILE

What is "cat" short for?

CONCATENATE meaning "to link together"

>>

REDIRECTS THE OUTPUT AND APPENDS THE FILE

"."

"." REFERS TO THE CURRENT WORKING DIRECTORY

cat (to display the contents of a file)

To display MyShoppingList.txt in the directory home/joe to the terminal window screen


$ cat MyShoppingList.txt


(Press "q" to quit)

cat (to write text to a file)

WRITE/SHOW CONTENTS OF A FILE. WITH ARGUMENTS CAN COMBINE FILE DATA


i.e.


$ touch MyShoppingList.txt


$ cat > MyShoppingList.txt


My List:


Cheese


Bread


Milk


ctrl + d to end entering text

tee

Allows for redirecting stdin to stdout i.e. ls | tee parts.txt will show the results of ls on the std output AND in parts.txt.


Use -a option to append to the file output instead of overwriting or creating a new file.

cd /

CHANGE DIRECTORY TO ROOT DIRECTORY

"~"

"~" REFERS TO THE USER'S HOME DIRECTORY

man -k {KEYWORD}

SEARCH POSSIBLE COMMANDS THAT RELATE TO THAT KEYWORD

Using "cat" with the more command

Display the contents of a large file one screen at a time i.e.users/sysadmin: $ MyShoppinglist.txt |less

clear

CLEARS THE SCREEN

man {COMMAND}

SHOWS THE MANUAL FOR A GIVEN COMMAND

which {command}

TO FIND OUT EXACTLY WHERE A COMMAND IS LOCATED

$PATH

DETERMINES THE VALUE OF PATH (ie. WHAT DIRECTORIES CONTAIN EXECUTABLE COMMANDS AND IN WHAT ORDER THEY ARE SEARCHED)

Using "cat" with the less command

Display the contents of a large file all at once so you can scroll up and down a file



i.e.users/sysadmin: $ MyShoppinglist.txt |more


(Press "q" to quit)

echo

DISPLAYS A VALUE ON YOUR OUTPUT (SUCH AS YOUR SCREEN OR A DOCUMENT)

tree -c

colorize the output

wc

WORD COUNT

tree

LIST THE CONTENTS OF A DIRECTORY IN TREE FORMAT

wc -l {filename}

Counts the lines of code in a file

tree -d

list directories only

sudo

RUN AS SUPERUSER/ADMINISTRATOR/ROOT


Stands for 'super user do'

eog {filename}

Eye


Of


Gnome



VIEW IMAGE FILE FROM WITHIN TERMINAL

grep

SEARCH FOR DATA WITHIN GIVEN FILES


Syntax: grep -i or -il (search term) (file name or *)

grep -i

SEARCH FILES WITHOUT CASE SENSITIVITY

grep -il

SEARCH FILES WITHOUT CASE SENSITIVITY AND SHOW ONLY FILE NAMES

grep -ri

SEARCH FILES RECURSIVELY (THROUGH SUBDIRECTORIES)

find

FIND FILES AND DIRECTORIES, DEPENDING ON WHAT PARAMETER YOU PLACE NEXT TO THE FIND COMMAND


ie find -f : finds files


find -d : finds directories

Linux file system structure

/ = root


/home = home dir contains user private files


/etc = config files


/bin, /sbin = binaries; contains applications


/ var = contains files that change over time


/tmp = contains temp files

ll

= ls -l : shows the permissions of a given file or folder

ls -l (file/folder)

Shows permissions of a given file or folder

ps aux

Shows a snapshot of all commands running at time of snapshot

PS aux | grep -I "(process)"

Snapshot of all processes grep'd into a search of specific process

top u + username you wish to check

Shows processes running under that username

kill

Used to kill processes

kill -9 (process #)

Kill a process

sudo killall (app/process ie. Firefox)

Kill all processes associated with a specific application

tar

STANDS FOR "TAPE ARCHIVE"


The way to create backups or archives of specific files or folders.


Syntax example:


sudo tar cvvWf 20200829_backup.tar


/var/log


Will create a full backup of the /var/log directory.


sudo tar cvvWf 20200829_backup.tar /var/log [> or >>] /var/log/backups_log_file.txt


Will create a full backup of the /var/log directory and redirect the output to a log file called backups_log_file.txt



Syntax breakdown:


sudo tar cvvWf [archive_name] [objects_to_archive


sudo ]



sudo = because /var/log contains system files therefore u need 'root' privileges to access them.



tar = the command



cvvWf = short form options:


c = create


vv = very verbose. It will display


the file name & path & the


permissions, owner, group,


size, creation date, and time


of each file as it is added to


the archive


W = verify


f = use this archive file, followed


by the name of the archive


20200829_backup.tar is the archive name.


/var/log = the objects (files or directories) to archive

Using tar to create incremental backups

Syntax: sudo tar cvvWf (archive_name).tar --listed-incremental=(snapshot_name).snar --level=0 /var/log



will create a full backup of the /var/log folder


and


sudo tar cvvWf (archive:_name).tar --listed-incremental=(snapshot_name).snar /var/log



will create an incremental backup of the /var/log directory

Creating full backups using tar command

Syntax: tar cvvWf (archive name).tar (directory_name)



ie. tar cvvWf tape_backup_20200827.tar ~/Documents/Downloads/



will create a full backup of the ~/Documents/Downloads directory.

Checking the contents of a tar file (same goes for compressed files)

SYNTAX: tar tvvf (tar_file).tar | less


Syntax breakdown:


tar = the command


tvvf = options


t = list the contents of an archive


vv = very verbose. Lists all relevant file information


f = stands for this file


[tar_file.tar] = archive name


| less = pipes the output to less so that we can scroll thru the data


tar best practices

•Make sure that archives are not writable by an untrusted user


• Sanitize data, such as passwords, before writing to an archive


• Monitor all backups, as tar is vulnerable to DoS attacks


• Pay attention to the diagnostic and exit status of tar

Extracting block of data from an archived file using tar command into a specified directory

1st step : mkdir restored_emails


Syntax :


tar xvvf 20190510_backup.tar -R -C restored_emails --wildcards "*.csv"


Syntax breakdown:


tar = command


xvvf = options


x = extract data


vv = very verbose


f = this archive file


20190510_backup.tar = the archive file


-R = print error msgs for any error with the block number in the archive file when extracting files


-C = what directory you want to save the untarred files


restored_emails = the directory where you want to save the extracted/untarred files


--wildcards "*.csv"= extract a group of files whose pattern begins with .csv



Extracting files into current directory using tar

Syntax:


tar xvvf -R file_backup.tar



Syntax breakdown :


tar = the command


xvvf = options


x = extract


vv = very verbose


f = this archive file


file_backup.tar = the archive file

Create a tar archive with compression using gzip and bz2

Syntax 1:


tar cvvzf 20200829_backup.tgz /home/Images



Syntax breakdown :


tar = the command


cvvzWf = options


c = create


vv = very verbose


z = compress archive using gzip


f = this archive file


20200829_backup.tgz = the archive file


/home/Images = the directory to be archived



Syntax 2:


tar cvvjf 20200829_backup.bz2 (or .tbz or .tb2) /home/Images



Syntax breakdown :


tar = the command


cvvjf = options


c = create


vv = very verbose


j = compress archive using bz2 (higher compression but slower compression rate)


f = this archive file20200829_backup.bz2 = the archive file


/home/Images = the directory to be archived

Untar /unzip compressed archive file

Syntax 1:


tar -xvvf 20200829_backup.tgz Syntax breakdown :


tar = the command


cvvzf = options x = extract vv = very verbose z = compress using gzip f = this archive file20200829_backup.tgz = the archive file



Syntax 2:tar -xvvf 20200829_backup.bz2


Syntax breakdown :tar = the commandcvvzWf = options x = extract vv = very verbose f = this archive file20200829_backup.bz2 = the archive



Untar a single file from a tar archive

Syntax:


tar -xvvf 20200829_backup.tar image_1.jpg


Untar multiple files, sequential, from a tar archive (same goes for compressed tar archives)

Syntax:


tar -xvvf 20200829_backup.tar "image_{1-25}.jpg

Untar multiple files, non-sequential, from a tar archive (same goes for compressed tar archives)

Syntax:tar -xvvf 20200829_backup.tar "image_1.jpg" "image_24.jpg"



tar -zxvvf 20200829_backup.tgz "image_1.jpg" "image_24.jpg"



tar -jxvvf 20200829_backup.bz2 "image_1.jpg" "image_24.jpg"


Add files or directories to a tar archive file (cannot do this with compressed archives)

Syntax:


For a file:


tar -rvvf 20200829_backup.tar image_1.jpg



For a directory:


tar -rvvf 20200829_backup.tar php


From where did cron get its name?

Kronos, Greek God of Time

cron tasks are scheduled in....

A file called crontab (short for CRON TABle)

What is the command to create or edit a cron file?

crontab -e

How can you tell if a service is running?

systemctl status [service_name]

How to tell if the cron service is up and running?

systemctl status cron

Command to list the contents of a crontab?

crontab -l

What is the basic syntax for a command within a crontab?

min hr date month weekday command



min = 0-59


hr = 0-23


date = 1-31


month = 1-12


weekday = 0-7 (0 & 7 = Sunday)



* = every ie. * in any value means every one of that value



Example:


If you want to delete everything in your Downloads folder every Saturday at 11 pm:


0 23 * * 6 rm ~/Downloads/*

how to use conditional statements in awk

awk '{if ($# >= 1000) print $0}'


What does < echo $? > do?

It is a special variable that will display the exit status of the previous command. An exit code of 0 indicates that the previous command ran successfully. Anything greater indicates an error.

What does 2>&1 mean vs 2>/dev/null?

2 = stderr


1 = stdout


/dev/null = a UNIX device file that discards all data written to it and yeilds no output


>& = redirect file descriptor



Therefore 2>&1 means if an error occurs, redirect the stderr to the stdout. 2>/dev/null means if an error occurs, redirect the stderr to /dev/null which will write the error and show no output. (You can echo $? to see if an error occurred)

Logrotate: What is the command syntax tk restart logrotate using the new/edited config file?

sudo logrotate -vf /etc/logrotate.conf

What does TTP stand for?

Tactics


Techniques


&


Procedures

For Loop

Syntax:



Numerical looping -



for ((i=0; i < 1000; i++))


do


echo $i


done




Iterating over a list -



for VAL in 20 3 dog 7


do


echo $VAL


done

If statements, command conditional

if cmd


then


some cmds


else


other cmds


fi

If statements, file & numerical conditionals

if [[ -e $FILENAME ]]


then


echo $FILENAME exists


fi




File Test =


-d = directory exists


-e = file exists


-r = file is readable


-w = file is writable


-x = file is executable