Powered By Blogger

Tuesday, May 3, 2011

Working with Files in Linux

c r e a t i n g    f i l e s
syntax:
cat > filename
  content
  content
  content
e.g.:
cat > todo_list
  eat
  rest
  sleep
* use ctrl + D to denote the end of the line

d i s p l a y i n g    f i l e    c o n t e n t s
syntax:
cat filename
e.g.:
cat todo_list

r e m o v i n g    f i l e s
syntax:
rm filename
e.g.:
rm todo_list

c o p y i n g    f i l e s
syntax:
cp oldfilename newfilename
e.g.:
cp old.pdf new.pdf
* copy the contents of the file to another file

r e n a m i n g    f i l e s
syntax:
mv oldfilename newfilename
e.g.:
mv oldfilename.txt newfilename.txt

f i l e n a m e    c o m p l e t i o n
press Tab key

Sunday, May 1, 2011

Managing CentOS Users and Groups



c r e a t i n g    u s e r s
syntax:
useradd [options] {username}
e.g.:
useradd --home /home/john john
useradd dhee

a d d i n g    p a s s w o r d
syntax:
passwd {password}
e.g.:
passwd dhee
*** Without pw, user account will be in lock status.

s e t    a c c o u n t    d i s a b l e    d a t e
syntax:
useradd -e {yyyy-mm-dd} {username}
e.g:
useradd -e 2011-06-28 dhee

s e t    d e f a u l t    p a s s w o r d    e x p i r y
syntax:
useradd -f {days} {username}
3.g.:
useradd -f -1 john
*** Type man useradd for options

l i s t i n g    a l l    u s e r s
e.g.:
cat /etc/passwd | grep "/home"
cat /etc/passwd | grep "/home" |cut -d: -f1
cat /etc/passwd | grep "/bin/bash" |cut -d: -f1

d e l e t i n g    a n    a c c o u n t
syntax:
userdel {username}
e.g.:
userrdel john

d e l e t i n g    u s e r ' s    h o m e    d i r e c t o r y
syntax:
userdel --remove {username}
e.g:
userdel --remove john

r e m o v i n g    a n    e m p t y    d i r e c t o r y
syntax:
rm -rf userdirectory
e.g.:
rm -rf john

a d d i n g    a    g r o u p
syntax:
groupadd {group}
e.g.:
groupadd accounts

a d d    a    u s e r    i n    a    g r o u p
syntax:
usermod -G {group} {account}
e.g.:
usermod -G accounts,sales,support john
usermod -a -G accounts,sales,support john

v i e w i n g    a l l    m e m b e r s    o f    a    g r o u p
syntax:
egrep "groupname" /etc/group
e.g.:
egrep "personal" /etc/group

d e l e t i n g    a    g r o u p
syntax:
groupdel {group}
e.g.:
groupdel accounts
***A group cannot be deleted if it is the primary group for any user.