bash Flashcards

1
Q

prints lines 5-10 of the “examples” file

A

sed -n ‘5,10p’ example

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

replace all instances of “old with “new” in the file “example”

A

sed -i s/old/new/g example

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Use the tab as a delimiter, then print the second field, a space-pipe-space string, and the first field from the file sample.

A

awk -F”\t” ‘{print $2 “ | “ $1} sample

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

uniq

A

The uniq utility removes consecutive duplicates. This is why you almost always sort before using it.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

sort

A

The sort utility sorts output alphabetically. Use the -n option to sort numbers, so that you get 1, 2, 10, 20 instead of 1, 20, 2, 10.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

take all the lines from sample that contain a command, split them on the tab, print the second field, a space-colon-space, and then the first field. Then sort the lines in reverse numerical order and show me the first 3

A

grep ‘,’ sample | awk -F”\t” ‘{print $2 “ : “ $1 | sort -nr | head -3

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

find all the files and directories that end with “.conf” in the /root directory

A

find /root -name “*.conf”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

find all the files and directories with the permissions of exactly 777 in the /home directory

A

find /home -perm 777

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

find all directories in /home/myuser (includes hidden directories)

A

find /home/myuser -type d

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

find all the files and directories owned by root in /home/myuser

A

find /home/myuser -user root

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

combine the previous options - find in / all the files with 777 permissions, owned by root, and with a name ending with “.conf”.

A

find / -name “*.conf” -perm 777 -type f -user root

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

print all files and directories below the current working directory

A

find

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

find all files in /home with 777 permissions and change them to 644 permissions (DO NOT RUN THIS ON A CUSTOMERS SERVER!)

A

find /home -type f -perm 777 -exec chown 644 {} \;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

find all the files in /root with 777 permissions and show them in a long list format

A

find /root -perm 777 | xargs ls -l

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

find all the messages in the queue that are from spammer@spam.com and delete them. (DO NOT RUN THIS ON A CUSTOMERS SERVER!)

A

exiqgrep -i -f “spammer@spam.com” | xargs exim -Mrm

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

for each line in the file /etc/trueuserdomains, take the second word and print it to the screen (stdout)

A

for I in cat /etc/trueuserdomains | cut -d" " -f 2;do each $1 ;done

for i in $( cut -d “ “ -f 2 what ); do echo $i; done

17
Q

for each file in /var/cpanel/users, print the line with LEGACY_BACKUP in it, then print the username

A

for u in ls /var/cpanel/users;do BU$u” “grep LEGACY_BACKUP /var/cpanel/users/$u;each $BU;done

18
Q

If the file /var/cpanel/envtype contains exactly “kvm”, then print yes. If it does not, print no.

A

if [ “grep kvm /var/cpanel/envtype” = “kv” ];then echo “Yes”;else echo “No”;fi

19
Q

with less, search from the current position to the end of the document for lines with term, then second in them

A

/term.*second