Lesson 03 - chad-p/wiki-linux-class GitHub Wiki

Users and Permissions

Piping

Grep

# Output the lines in the file that have the username in them
cat auth.log | grep <username>

# Match all lines that do not have the keyword (case insensitive) error.
cat syslog | grep -vi error

# Find all the processes that have firefox in them. Give me line numbers too.
ps aux | grep -in firefox

# Find out if 443 is a listening port
netstat -tlnp|grep LISTEN|grep :443

# Search in all files in the current directory that have the username
grep -i <username> *

# Find lines that start with "d".  This would return directories.  (you can do this with just ls too)
ls โ€“al | grep โ€˜^dโ€™

AWK

cat /etc/passwd
awk -F ":" '{print $1 $6}' /etc/passwd
awk -F ":" '{print $1 " - " $6}' /etc/passwd

Additional Commands

# sort
# Create file with months not in order.
echo -e "Feb\nDec\nMar\nOct\nMay\nJun\nNov\nAug\nSep\nApr\nJan\nJul" > months

# Does this sort as you expect?
cat months | sort

# This is better
cat months | sort -M

# cut
# Use cut to parse the IP
ip -c a | grep inet | grep brd | cut -d " " -f 6 | cut -d "/" -f 1

Users

Groups

# Find groups user belongs to
groups
id

# Delete students group
groupdel students

# Create new group with GUID 101
groupadd -g 101 students

# Add group students to supplementary group of user
usermod -a -G students <user>

# Find out who is members of the sudo group
sudo groupmems -lg sudo

Password Management - login.defs

Sudo

Permissions

  • chmod # Modify permissions
  • chown # Modify ownership

SUID, SGID

touch myfile
chmod 4764 myfile
ls -l
  • find . -perm -6000 # Way to find files with suid or sgid set

PATH

Hard and Soft links

# Create Hard Link
touch file
ln file hardfile
ll -i
echo "hello" >> file
cat hardfile
rm file
ll
rm hardfile

# Create Soft Link
ln -s file softfile
ll -i
rm file
ll
rm softfile
โš ๏ธ **GitHub.com Fallback** โš ๏ธ