Where to find things in RHEL and Ubuntu Linux

Always forgetting the paths to restart Apache or edit your log files, etc? Well, I am, so this is a post to help me keep track of those places, but perhaps it will be useful to you as well. Some paths will be the same for all flavors of Linux and some are specific to RHEL.
 

Apache Restart: /etc/init.d/httpd restart (or on Ubuntu sudo service apache2 restart)
Apache configuration: - /etc/httpd/conf/httpd.conf
PHP configuration: - /etc/php.ini (or on Ubuntu /etc/php5/apache2/php.ini)
Log files: /var/log
Web root: /var/www/html
Bash shell profile: ~/.bash_profile

mysql:mysql -u user -p -h ip.ad.dr.ess
mysqldump: mysql -u user -p -h ip.ad.dr.ess databasename > databasename.sql
apply a patch: patch -p0 filetopatch

search / find in vi: /searchterm and then use 'n' key to find next

find and replace in all subdirectories using grep and sed: grep -lre 'MySearch' ./ | xargs sed -i 's/ChangeFrom/ChangeTo/g'

Of course replacing MySearch, ChangeFrom, and ChangeTo to your patterns.
 

Delete all matching lines in files in subdirectories: find . -type f -print0 | xargs -0 sed -i /SSL\ available/d

Save a file as su when already inside of vi: You ever open vi as normal user when you mean to as root / su. Just type in vi: w !sudo tee %

svn delete all files in subversion control that were removed: svn status | grep '\!' | awk '{print $2;}' | xargs svn rm

% is to be replaced by the current filename

Grep for terms and ignore svn directories: grep -re "Content_Data_Data" ./ | grep -v .svn

Grep for terms and ignore multiple filetypes/directories: grep -nre "issue" --exclude=*.{svn,test,svn-base,tmp} .

The nice part about the second grep statement is that it keeps the syntax highlight whereas when using -v you lose highlighting

rename folders based on a pattern: rename site.drupal.org site.drupal.org.project. site.drupal.org.*
 
This will replace e.g., site.drupal.org.views and site.drupal.org.cck, with site.drupal.org.project.views and site.drupal.org.project.cck Works on the entire folder

delete svn directories in current and all subdirectories: find . -name ".svn" -type d -exec rm -rf {} \;

add all new files in a directory that is already under subversion control: svn add directoryname/ --force

pngcrush an image pngcrush -rem gAMA -rem cHRM -rem iCCP -rem sRGB image.png image2.png

port forward via ssh: ssh -f -L 8080:server.example.com:80 server.example.com

untar a tarred and gzipped folder and remove the base directory (very helpful for untarring Drupal or the like when you want to overwrite files): tar -xzvpf thefilename.tar.gz --strip-components 1 

performance monitoring commands: powertop, top, htop, vmstat, netstat, ntop, vnstat, iostat, strace, oprofile. Also useful is KCacheGrind utility and XDebug for PHP, SHOW PROCESSLIST; for MySQL, and apachetop for Apache. 

server system information: cat /proc/cpuinfo, cat /proc/meminfo, dmesg, lspci

As further explanation, the x means to extract, the z means ungzip it, the v means verbose so it will show all the folders/files being extracted, the p means to preserve permissions, and the f indicated the filename will follow. The strip components flag is what removes the base folder from the tarred file before extracting. 

!string - use this and replace string with any string that begins a previous command from your history and it will repeat that command. Yey, no more searching through history. 

Disk usage df -k

Use sed to remove matching lines sed -ie 's/front_page/d' delta.sql

Use find, sed, and awk to get part of the name of a matching directory find ./ -name "test.coderintherye.com.*" | sed "s/\./\ /g" | awk '{print $NF}'

For example on the above, if I had the directories: test.coderyintherye.com.site1, test.coderyintherye.com.site2, test.coderyintherye.com.site3, etc. and I just want to get the site# part, the above will return it

10 tips for using the Bash shell - found these quite useful

history - show your previous commands

!! - use this in the shell to rerun previous command

Edit a file on a remote host using vim - vim scp://username@host//path/to/somefile

Right alt left arrow for back one page in karmic (via Ubuntu forums):
Open "System -> Preferences -> Keyboard".
Click the Layouts tab, then click the Layout Options button.
Under "Key to choose 3rd level", check "Right Alt key never chooses 3rd level" and uncheck the others. (That worked for me; you might wanna experiment.)

Getting just the diff of particular revision in subversion: svn diff -c 123

List of modified files in a revision: svn log --verbose -r 123

Adding a new site to Apache (thanks to cdenley on ubuntuforums)

NameVirtualHost *:8080


DocumentRoot /path/to/new/site
ServerName www.example.com

-enable your new site
Command Line:
sudo a2ensite 
-restart apache to listen on your new port and load your new site
Command Line:
sudo service apache2 restart

You may also find this useful:

Also check out This great blog post and this hacker news post on nifty ssh tips.

outfit

Comments

You should use `service`

You should use `service` instead of calling the init-scripts directly - I've experienced odd inconsistencies when doing it as you have it listed.

Also, sed has an in-place flag (`-i`) that you can use instead of writing to an alternate filename and copying back over. Even better, it accepts an optional suffix for a backup file (eg `-i .bak`).

Thanks, I made the changes as

Thanks, I made the changes as you suggested.

You are amazing

Hey Kelvin, You are doing a great job!! Im very much inspired by you to start my own website.. :)

Thanks buddy...

Add new comment

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.

Comment using an existing account (Google, Twitter, etc.)