Linux and BSD commands

I had thought about making a script to do just this. For a while I had a page in HTML only that I listed some, but because it was a pain to edit I never really updated it. I finally realized I could just make a page in WordPress instead so here it is.

Remember that if you are running any mysql or mysqldump commands to not include the password when you type it in. This is because the commands you type into the command line are logged & thus if you type the password directly into the command it will be logged. If however you do not enter the password directly into the commands then it is not logged as it goes to the program. (This may vary depending on your installation, but I still feel it is a better idea to enter it after the command.)

Remember that Linux, Unix, & BSD are all case-sensitive. This is not like Windows or MD-DOS where things are case aware at best & may as well be case-insensitive as far as I care.

Use of command command example
this will delete any file or folder named delme, in the current folder & all sub folders it has access to find . -name “delme” -exec rm -fr {} \;
Set all files & folders to 755 permissions chmod -R 755 *
To kill php5 processes killall -15 php5
To count subdirectories find ./ -type d | wc -l
To count files find ./ -type f | wc -l
To count subdirectories in the public_html folder find ~/public_html/ -type d | wc -l
To count files in the public_html folder find ~/public_html/ -type f | wc -l
To just fix permissions run the following commands find ~/public_html/ -type d -exec chmod 755 {} \;
find ~/public_html/ -type f -exec chmod 644 {} \;
find ~/public_html/ -name \*.cgi -exec chmod 755 {} \;
find ~/public_html/ -name \*.pl -exec chmod 755 {} \;
find ~/public_html/ -name \*.pm -exec chmod 755 {} \;
find ~/public_html/ -name .ftpquota -exec chmod 600 {} \;
I wrote a PHP script to do this over here as I got sick of running this from SSH.
Here are the commands to clean up the _ folders created by FrontPage find ~/public_html/ -type d -exec chmod 755 {} \;
find ~/public_html/ -name “_borders” -exec rm -fr {} \;
find ~/public_html/ -name “_derived” -exec rm -fr {} \;
find ~/public_html/ -name “_fpclass” -exec rm -fr {} \;
find ~/public_html/ -name “_overlay” -exec rm -fr {} \;
find ~/public_html/ -name “_private” -exec rm -fr {} \;
find ~/public_html/ -name “_themes” -exec rm -fr {} \;
find ~/public_html/ -name “_vti*” -exec rm -fr {} \;
find ~/public_html/ -name “.htaccess” -exec mv {} {}.`date +%F` \;
find ~/public_html/ -name “postinfo.html” -exec rm -fr {} \;
to find files that might have database info (will find with the username signed in as) (.php files only) find ~/public_html/ -name \*.php -exec grep -Hl `whoami`_ {} \;
to find files that might have database info (will find with the username signed in as) (all files) find ~/public_html/ -type f -exec grep -Hl `whoami`_ {} \;
to find files that might have database info (replace username with the username of the account) (.php files only) find ~/public_html/ -name \*.php -exec grep -Hl username_ {} \;
to find files that might have database info (replace username with the username of the account) (all files) find ~/public_html/ -type f -exec grep -Hl username_ {} \;
will search for the specific string “mail(” & export to a mail-usage.txt file find ~/public_html -type f -exec grep -Hl ‘mail(‘ {} \; > ~/mail-usage.txt
find ~/public_html -type f -exec grep -Hl ‘mail (‘ {} \; >> ~/mail-usage.txt
current folder (Print Working Directory) pwd
clear screen (This is similar to DOS’s CLS command) clear
Restores a database as stored in the [database-file] (Replace “[database]” with the name of the database.) (Replace “[database-file]” with the name of the database file.) mysql -u`whoami` -p [database] < [database-file]
Dumps a MySQL database to a file mysqldump -u`whoami` -p [database] > [database-file]
Dumps a MySQL database to a file with today’s date mysqldump -u`whoami` -p [database] > [database].`date +%F`.sql
Removes “eval(base64_decode” till the “))” in them. This may cause problems if some of the files are supposed to have a base64_decode running in them. find ~/public_html/ -type f -exec sed -i ‘s/eval(base64_decode.*))\;//g’ {} \;
This will show you if cron is running (You should see at least two instances one as root & one from your grep) ps aux | grep crond
This will delete an error_log files in the public_html folder & all of its sub folders find ~/public_html -name “error_log” -exec rm -fr {} \;
to replace existing php.ini files in all sub folders with the php.ini in the folder you run the command from find ./ -name php.ini -exec cp ./php.ini {} \;
to put a php.ini into all sub folders with the php.ini in the folder you run the command from find ./ -type d -exec cp ./php.ini {} \;
You can find all of the existing php.ini files this way find ./ -name php.ini
If you just want the total number of php.ini files run this find ./ -name php.ini | wc -l
to count subdirectories find ./ -type d | wc -l
to count files find ./ -type f | wc -l
To search for files with the extension .log find ./ -name ‘*.log’ | wc -l
will search for the specific string “mail(” & export to a mail-usage.txt file find ./ -type f -exec grep -Hl ‘mail(‘ {} \; > mail-usage.txt
This will find the IPs making connections netstat -utanp | less
to get the txt entry of domain.com dig txt domain.com
This will display the disk usage for the current folder & all sub folders as one number du -sh
This will display the disk usage for all of the folders that are sub folders of the current folder & after that it will list the total of all the folders combined together du -ch
This should kill all of the users processes (sometimes it will kill the ssh connection before all the other processes are dead) pkill -9 -u `whoami`
This will kill all processes for the user that are running on the ramdisk ps aux | grep `whoami` | grep ramdisk | awk ‘{ print $2 }’ | xargs -i kill -9 {};
this looks like it would also kill the SSH connection ps aux | grep `whoami` | awk ‘{print $2}’ | xargs kill -9
This command will kill PHP processes killall -9 php php4 php5
Here is the command to put the symlink back for the www symlink ln -s ~/public_html ~/www
list the total number of files & folders on the account find ~/ -type f | wc -l
find ~/ -type d | wc -l
list the total number of files on the account ls -RA | wc -l
You can find all “.htaccess” & “htaccess.txt” files in the “~/public_html/” folder & all of its sub-folders. find ~/public_html/ -name .htaccess > ~/htaccess-files.txt
find ~/public_html/ -name htaccess.txt >> ~/htaccess-files.txt
This will tell you the version of rails being run rails -v
This can help figure out why pages are having issues strace full path to file
To get the number of files in a directory including sub directories on Linux ls -1R | wc -l
this will move all files in a sub folder to “/pathtofile” find -type f -mindepth -2 -exec mv {} /pathtofile \;
this will move all files in a sub folder to the current folder find -type f -mindepth -2 -exec mv {} `pwd` \;

Now commands for BSD

Use of command command example
install nano pkg_add -r nano
remove clamav pkg_delete clamav*
rm -rf /var/log/clamav
rm -rf /var/run/clamav
rm -rf /var/db/clamav
pw userdel clamav
list installed packages pkg_info
remove HAVP pkg_delete havp*
rm -rf /var/log/havp
rm -rf /var/run/havp
rm -rf /var/tmp/havp
pw userdel havp
This command can help you remove a package from your BSD based install pkg_delete -m