Few basic unix command to remember

——————————————-
#command to find linux model and versios
——————————————–
uname -m = i686
uname -r = 2.6.9-42.0.3.ELsmp or2.6.18-8.el5(centos)or2.6.16-xenU(fc-xen)
uname -s = Linux
uname -v = #1 SMP Fri Oct 6 06:21:39 CDT 2006
uname -a =Linux imagic.planet.com 2.6.18-8.el5 #1 SMP Thu Mar 15 19:57:35 EDT 2007 i686 i686 i386 GNU/Linux

#cat /etc/distro for linux
#cat /etc/issue for ubuntu

———————————–
#add a user to home directory
———————————–
useradd -d /home user
——————————–
#give permission to a file
——————————-
chmod 755 filename(755-wrx rx rx)

————————————–
#user with nologon permission
————————————–
vi /etc/passwd
rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin

—————————–
#ownership to file
—————————–
chown root:root file(user:group)

——————————
#delete a user
——————————
userdel user

——————————-
#adding a user to group
——————————-
usermod -g group user

————————————-
#check user present in that group
————————————-
groups user

—————————–
#delete a user from group
—————————–
usermod -a -G group user

——————————-
#add a user to wheel group
——————————-
vi /etc/group
wheel:x:10:root,user

————————————–
#permission wheel user to system
————————————–
visudo(/etc/sudoers)
## Allows people in group wheel to run all commands
%wheel ALL=(ALL) ALL

## Same thing without a password
# %wheel ALL=(ALL) NOPASSWD: ALL

##permission to user to few services

user ALL=/etc/init.d/httpd /sbin/httpd

—————————
#setuid user
—————————
chmod u+s file
it willbe like -rwsr-xr-x user group file

#setuid user
chmod g+s file

———————————————–
#command to check uid for user
———————————————–
id
uid=502(user) gid=10(wheel) groups=10(wheel)

id root
uid=0(root) gid=0(root) groups=0(root),1(bin),2(daemon),3(sys),4(adm),6(disk),10(wheel)

——————————–
#process to background
——————————–
bg

#check with jobs -l

#put it front
fg %id

——————————————————-
#command to run the process when shell is closed
——————————————————-
nohup process

———————————————
#command to check memery usage of procees
———————————————
top or htop

——————————-
#command to kill process
——————————-
kill -9 pid or process

#part of the name
pkill -9 httpd

#kill all
killall -l httpd

# Kill TERM processes owned by www
pkill -TERM -u www
# Kill every process accessing /home (to umount)
fuser -k -TERM -m /home

——————————–
#switch to other user
——————————–
su -l user

#run a program using a sudo user(edit /etcsudoers and add user
user ALL=/etc/init.d/httpd or allow wheel and add user to wheel group)
sudo /etc/init.d/httpd start
sudo restart

———————————-
#enable/disable firewall
———————————-
lokkit

#delete a oneday previous file in a dir

find /tmp -mtime +1 -type f -exec rm -f {} \;

# find all files last modififed yesterday
find . -mtime 1 -type f -print

#Delete log and use crontab
20 8 * * * echo “” > /usr/local/apache2/logs/access_log

# List the crontab
crontab -l crontab -e (edit)

#check if cron run
egrep -ir “access_log” /var/log/cron (check if run)

#check last accessed time from log
head -n10 /usr/local/apache2/logs/access_log

Advertisements

Posted on October 25, 2013, in LInux Based. Bookmark the permalink. Leave a comment.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: