From LedHed's Wiki
Jump to: navigation, search
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
'''Tips -N- Tricks'''
 
'''Tips -N- Tricks'''
 +
== Truncating a File ==
 +
If you want to empty a file quickly (like purging a log file) then run the following command:
 +
:> filename
  
 
== Search command history ==
 
== Search command history ==
Line 20: Line 23:
 
To re-enable it use this command:
 
To re-enable it use this command:
 
  swapon -a
 
  swapon -a
 +
 +
== Run a command as a different User ==
 +
su <SOME_OTHER_USER>
 +
or Run as a user that doesn't have shell access (Like the 'www' account).
 +
su -m www -c "run some command here"
 +
Note: The -c option is used to run a single command.
 +
 +
  
  

Latest revision as of 05:53, 4 June 2012

Tips -N- Tricks

Truncating a File

If you want to empty a file quickly (like purging a log file) then run the following command:

:> filename

Search command history

grep -i 'SearchStringHere' ~/.bash_history

View Log Continuously

tail -f /path/to/log/filename

or

Filter a continuous log for a specific entry

tail -f /path/to/log/filename | grep -i 'FilterStringHere'


Dump a .conf file to a new file without the comments (#)

grep -v '#' file.conf > newfile.conf

Disable/Enable Swap

To disable all swap space in Linux use this command:

swapoff -a

To re-enable it use this command:

swapon -a

Run a command as a different User

su <SOME_OTHER_USER>

or Run as a user that doesn't have shell access (Like the 'www' account).

su -m www -c "run some command here"

Note: The -c option is used to run a single command.



RPM's

RedHat based distributions use RPM's short for Redhat Package Manager. To view a list of installed RPMS:

rpm -qa

To look for a specific installed package:

rpm -qa | grep 'package_name'

To view the contents of a RPM

rpm -qpil /path/to/package.rpm

Common Sqitches: -i Install
-U Upgrade
-v verbose
-h Display Hash mark progress bar
-e erase
--force forces an erase or upgrade