MISC 1 Flashcards
Create multiple files:
list1 - list3
touch list{1..3}
Change file permissions for user group and other in one command without using octal
chmod ug=rwx,o=1 this
change the ownership and group of this from root to a different user and group
chown
Allow files to gain the same ACL as the parent directories
setfacl -Rm u:rwx:user this
Show brief info pertaining to a command
whatis ls
if this doesn’t work you need to
mandb
what command do you use if you want to display stdout on terminal and stick it in a file
echo “Hello, world!” | tee -a this
Get the last line then the first line of a file
tail -n 1
head -n 1
Show the first third and fifth letter of each line for a file
then show this in bytes
cut -c 1,3,5 this.txt
cut -b 1,3,5 this.txt
Show every line after the 6th colon of /etc/passwd using cut
cut -d: -f 6 /etc/passwd
Delimiter is basically using : instead of space
Show only the 1st and 3rd column of ls using awk
ls -l | awk ‘{print $1,$3}’
Print the last column of ls -l
ls -l | awk ‘{print $NF}’
search for tim in /etc/passwd
only show the 3rd column
remember that each item is spaced by a colon (:) rather than a space
awk -F : ‘/tim/ {print $1}’ /etc/passwd
echo “Hello, Larry” and change larry with Nathan via awk
echo “Hello, Larry” | awk ‘{$2=”Nathan”; print=$0}’
Show only lines with 15 characters or more
awk ‘length ($0) > 15’ seinfeld-characters
If the last line of ls contains Seinfeld, print it
ls -l | awk ‘{if($NF == “seinfeld”) print $0;}’
How many number of times does Seinfeld appear in seinfeld.txt? using grep
grep -ci “seinfeld” seinfeld.txt
Show the line number and how many times Seinfeld appears in seinfeld.txt using grep
grep -ni “seinfeld” seinfeld.txt
Show everything BUT seinfeld in seinfeld.txt using grep
grep -vi “seinfeld” seinfeld.txt
Print ls -l stdout in opposite of alphabetical order on the third column and then delete duplicates
sort -k3 -r seinfeld | uniq
Order seinfeld alphabetically and then remove duplicates.
Show the amount of duplicates per item
sort seinfeld | uniq -c
Order seinfeld alphabetically and then show only the words that were duplcates
sort seinfeld | uniq -d
What are the three numbers that pop up when you use this command
wc seinfeld-characters?
-l -w -c
line
word
byte
Archive your directory, and then show what’s in it, then open it
tar cvf this.tar /home/delsin
tar tvf this.tar
tar xvf this.tar
cut a file down to 120 bytes via truncate
truncate -s 120 this.txt
Take the countries file containing 7 countries and put them into separate files name newa-d
split -n 4 countries new
Use sed to change delsin to nathan permanently
sed ‘s/Kenny/Lenny’
s - substitute
sed ‘s/Kenny/Lenny/g’
g - globally
Remove the name nathan from the file via sed
sed ‘s/nathan//g’ sed
Delete all lines containing Nathan via sed
sed ‘/nathan/d’ sed