Linux
Most useful commands for Linux
* Continuously check Apache error log file: $ tail -f /var/log/httpd/error_log * View first 15 lines from MySQL log: $ head -15 /var/log/mysqld.log * vi keyboard shortcuts => jump to end of line $ => start of line 0 => Delete rest of line D => Repeat the last command given: . (dot) => add [...]
How to remove unwanted .DS_STORE files
It is simple. Just use the following command and it will find all files under the folder you are. find . -name .DS_Store -print -delete
Backup MySQL Database to a file
Backing up your database is a very important system administration task, and should generally be run from a cron job at scheduled intervals. We will use the mysqldump utility included with mysql to dump the contents of the database to a text file that can be easily re-imported. Syntax: mysqldump -h localhost -u root -pmypassword [...]
A “live” view of a logfile on Linux
This approach works for any linux operating system, including Ubuntu, and is probably most often used in conjunction with web development work. tail -f /path/thefile.log This will give you a scrolling view of the logfile. As new lines are added to the end, they will show up in your console screen. For Ruby on Rails, [...]
Backup your bootsector
Messing with bootloaders, dual-booting and various other scary processes can leave you with a messed up bootsector. Why not create a backup of it while you can: dd if=/dev/hda of=bootsector.img bs=512 count=1 Obviously you should change the device to reflect your boot drive (it may be sda for SCSI). Also, be very careful not to [...]
Transferring files without ftp or scp
Need to transfer a directory to another server but do not have FTP or SCP access? Well this little trick will help out using the netcat utility. On the destination server run: nc -l -p 1234 | uncompress -c | tar xvfp – And on the sending server run: tar cfp – /some/dir | compress [...]
Faster Hard drives
You may know that the hdparm tool can be used to speed test your disk and change a few settings. It can also be used to optimise drive performance, and turn on some features that may not be enabled by default. Before we start though, be warned that changing drive options can cause data corruption, [...]
Save battery power
You are probably familiar with using hdparm for tuning a hard drive, but it can also save battery life on your laptop, or make life quieter for you by spinning down drives. hdparm -y /dev/hdb hdparm -Y /dev/hdb hdparm -S 36 /dev/hdb In order, these commands will: cause the drive to switch to Standby mode, [...]
Finding the biggest files
A common problem with computers is when you have a number of large files (such as audio/video clips) that you may want to get rid of. You can find the biggest files in the current directory with: ls -lSrh The “r” causes the large files to be listed at the end and the “h” gives [...]
Replacing same text in multiple files
If you have text you want to replace in multiple locations, there are several ways to do this. To replace the text Windows with Linux in all files in current directory called test[something] you can run this: perl -i -pe ‘s/Windows/Linux/;’ test* To replace the text Windows with Linux in all text files in current [...]
