Topic 3: The Power of the Command Line

0.0(0)
studied byStudied by 0 people
0.0(0)
full-widthCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/66

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

67 Terms

1
New cards

compression

lessen the memory a set of data consumes

2
New cards

archiving

bundling files and/or directories into a single file

3
New cards

tar

a tool that archives files. Does not compress them by itself. (Name is short for "tape archive." Files created with tar are called "tar balls"

4
New cards

zip

an archive file format that supports lossless data compression; may contain one or more files or directories

Comes with windows operating systems, needs to be installed for Linux

5
New cards

unzip

the command that decompresses and expands a zipped file

6
New cards

bzip2

A lossless file compression command. Uses the .bz2 file extension.

7
New cards

gzip

a lossless file compression command. Uses the .gz file extension

8
New cards

xz

a lossless file compression command. Uses the .xz file extention

9
New cards

bunzip2

uncompresses .bz2 files

10
New cards

gunzip

uncompresses .gz files

11
New cards

unxz

uncompresses .xz file

12
New cards

compression levels

entered as options, usually as numbers from 1 (least compression) to 9 (most compression). 9 is default

13
New cards

gzip reading tools

Versions of common commands (cat, less, grep, etc) which work on gzip .gz files. These can be accessed by prefixing a z. For example: zcat, zless, etc

14
New cards

bzip2 reading tools

bzcat, bzless, etc

15
New cards

xz reading tools

xzcat, xzless, etc

16
New cards

tar options

c create

x extract

f file name

t view contents

u add or replace files (must be uncompressed)

v lists files processed

A concatenates archive files

z compresses using gzip

j compresses using bzip2

J compresses using xz

W used to verify an archive file

r update file or directories in .tar file

17
New cards

tar -tf name.tar

displays the contents of name.tar

18
New cards

tar -options filename(to edit) files/directories(if relevant)

format of a tar command. First the options, then the tarball to edit or work in, then finally all other arguments the chosen options require

19
New cards

tar cf newtarball.tar targetdirectory

makes a new tarball from the target directory

20
New cards

tar -tf tarball.tar

shows the contents of the named file

21
New cards

tar xf tarball.tar

extracts the entire tarball

22
New cards

tar xvf tarball.tar target_file

extracts target_file from the tarball and prints all the files tar interacted with

23
New cards

tar cjf file.tar.bz2 bigfile bigfile2 bigfile3

creates a compressed tarball using bzip2

24
New cards

stdin

-standard input: information inputted into terminal through keyboard or input device. AKA channel 0

25
New cards

stdout

standard output: is the information outputted to the screen after a process is run. AKA channel 1

26
New cards

stderr

a stream that contains error output, known as channel 2. Goes to the screen by default

27
New cards

>

redirects standard output (stdout) to a file. If it doesn't exist, it creates a new one. If it does, it is overwritten

28
New cards

>>

redirects standard output, appending it to a file

29
New cards

2>

redirects just error messages

30
New cards

2>>

appends error messages to a file

31
New cards

/dev/null

null device. sending data to it will do nothing

32
New cards

<

used to redirect standard input (stdin)

$ cat < file.txt

Hello!

Most commonly used with commands that don't accept file arguments

33
New cards

<<

a redirection operator that acts as a 'here document'

34
New cards

&>

writes both channel 1 and 2 to a file

35
New cards

&>>

appends both channel 1 and 2 to a file

36
New cards

|

also known as redirection or command line pipes

Output of first command used as input of second command, etc

$ cat /etc/passwd | less

uses less on the text result of cat

37
New cards

wc

counts the lines, words, and bytes

-w counts only words

-l counts only lines

-c counts only bytes

38
New cards

tail -f

view last 10 lines of a file and follow output

39
New cards

grep

abbreviation of "global regular expression print"

finds lines with specified pattern

-i case insensitive

-r recursive (also in subdirectories)

-c outputs number of matches instead of matches

-v outputs lines that DON'T match

-E advanced RegEx (for ?, |, etc)

and more

40
New cards

sun | moon

Find either of the listed strings

41
New cards

^ RegEx

start of a line

42
New cards

$ RegEx

end of a line

43
New cards

+ RegEx

matches when the character preceding + matches 1 or more times, and makes it mandatory

44
New cards

? RegEx

matches zero or one of the preceding pattern

45
New cards

. RegEx

represents any single character

46
New cards

script

a file containing commands that can run on the command line one after another

47
New cards

./

prefix that runs a file as a script

48
New cards

shebang

#!/bin/bash for bash. It specifies which interpreter

49
New cards

.sh

or .bash

The conventional ending of bash scripts

50
New cards

vi

text editor installed by default. vim is a clone which is slightly improved. Has a number of different navigational modes

51
New cards

nano

a simple text editor

52
New cards

#This is a Bash comment

Comments are defined by #

53
New cards

arguments

delimited inside the script as $1, $2 etc. (After 9, it gets odd).

54
New cards

$#

variable containing the number of arguments/paramters

55
New cards

format of conditional logic in Bash

if [ condition ]

then

action

else

action2

fi

56
New cards

-eq

checks for equality

57
New cards

-ne

not equal to

58
New cards

-gt

greater than

59
New cards

-ge

greater than or equal to

60
New cards

-lt

less than

61
New cards

-le

less than or equal to

62
New cards

$ built-in variable

this contains the exit code of the last command to run

63
New cards

exit 0

exits the script with an exit code of 0

64
New cards

$@ or $*

a built-in variable for all arguments

65
New cards

for loop syntax

FILES="/usr file2 file3"

for file in $FILES

do

action

done

66
New cards

Bash array syntax

Separated by spaces

item1 item2 item3

67
New cards

shift

removes the first element of our array