Everyday Linux Commands

Some Linux commands I use over and over again (and still might forget)

screen — run this to use restartable ssh session
screen -r — reconnect to a screen
exit — exit screen to log off
who — list users
who -u — list users with pid
kill <pid> — kill a session/process
passwd — change password
sudo su -l userName — switch to that user

— get sendmail path —
postconf -d sendmail_path
result on cohen = /usr/sbin/sendmail

— get disk space —
df -h

— view available disks —
lshw -C disk

— how many processors? —

grep -c ^processor /proc/cpuinfo     

— view logs —
tail /var/logs/logfile.log (shows end of log)

— remove directories —
rm -rf {file or directory name(s)}

— decompress a file —
tar xzvf file.name.tar.gz

— CRON —
sudo cron -l (lists cron jobs)
sudo cron -e (edit cron jobs)
sudo crontab -l
sudo crontab -e

– FIND –
find by name examples:
find -name my.file.name
find -name my.file.name ! -name not.my.similar.file.name

CHMOD (from http://www.washington.edu/computing/unix/permissions.html)

chmod u=rx file (Give the owner rx permissions, not w) chmod go-rwx file (Deny rwx permission for group, others) chmod g+w file (Give write permission to the group) chmod a+x file1 file2 (Give execute permission to everybody) chmod g+rx,o+x file (OK to combine like this with a comma)

 (Less common, but still forget-able)

?
1
2
3
sudo iptables -I INPUT -p tcp --dport 9090 -m state --state NEW,ESTABLISHED -j ACCEPT
sudo iptables -I OUTPUT -p tcp --sport 9090 -m state --state ESTABLISHED -j ACCEPT
sudo service iptables save

info is written to /etc/sysconfig/iptables

edit and mark executable script in /etc/init.d

?
1
2
3
chmod 755 tomcat_ect_qa
sudo chkconfig --add tomcat_ect_qa
sudo chkconfig --level 234 tomcat_ect_qa on

(Ubuntu)

– reconfigure postfix –
sudo dpkg-reconfigure postfix

— firewall rules with ufw —

# ufw default deny
# ufw allow http/tcp
# ufw allow 22/tcp
# ufw enable
# ufw status verbose

Advertisements

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 )

Google photo

You are commenting using your Google 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 )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.