bash Flashcards
prints lines 5-10 of the “examples” file
sed -n ‘5,10p’ example
replace all instances of “old with “new” in the file “example”
sed -i s/old/new/g example
Use the tab as a delimiter, then print the second field, a space-pipe-space string, and the first field from the file sample.
awk -F”\t” ‘{print $2 “ | “ $1} sample
uniq
The uniq utility removes consecutive duplicates. This is why you almost always sort before using it.
sort
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.
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
grep ‘,’ sample | awk -F”\t” ‘{print $2 “ : “ $1 | sort -nr | head -3
find all the files and directories that end with “.conf” in the /root directory
find /root -name “*.conf”
find all the files and directories with the permissions of exactly 777 in the /home directory
find /home -perm 777
find all directories in /home/myuser (includes hidden directories)
find /home/myuser -type d
find all the files and directories owned by root in /home/myuser
find /home/myuser -user root
combine the previous options - find in / all the files with 777 permissions, owned by root, and with a name ending with “.conf”.
find / -name “*.conf” -perm 777 -type f -user root
print all files and directories below the current working directory
find
find all files in /home with 777 permissions and change them to 644 permissions (DO NOT RUN THIS ON A CUSTOMERS SERVER!)
find /home -type f -perm 777 -exec chown 644 {} \;
find all the files in /root with 777 permissions and show them in a long list format
find /root -perm 777 | xargs ls -l
find all the messages in the queue that are from spammer@spam.com and delete them. (DO NOT RUN THIS ON A CUSTOMERS SERVER!)
exiqgrep -i -f “spammer@spam.com” | xargs exim -Mrm
for each line in the file /etc/trueuserdomains, take the second word and print it to the screen (stdout)
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
for each file in /var/cpanel/users, print the line with LEGACY_BACKUP in it, then print the username
for u in ls /var/cpanel/users
;do BU$u” “grep LEGACY_BACKUP /var/cpanel/users/$u
;each $BU;done
If the file /var/cpanel/envtype contains exactly “kvm”, then print yes. If it does not, print no.
if [ “grep kvm /var/cpanel/envtype
” = “kv” ];then echo “Yes”;else echo “No”;fi
with less, search from the current position to the end of the document for lines with term, then second in them
/term.*second