Archive for the ‘Tips and Tricks’ Category
Posted by Derek@TheDailyLinux »
Add Comment »
Use the following command to setup your shell to have similar key behavior to vi. If you’re already familiar with the keybindings of vi, then you may appreciate the ability to quickly search/edit your history, or navigate through your commands quickly. One example I heard about was being able to change a single character in a massive 200 character command.
set -o vi
You could include this command within your ~/.bashrc or ~/.bash_profile files as well so you have it when you login to a shell.
Posted by Derek@TheDailyLinux »
2 Comments »
It’s very simply to determine which shell you’re using while logged into a Linux terminal. Simply run the following command:
ps -p $$ | tail -n1 | cut -d" " -f26
You’ll get in return, the shell command you’re using (plus the full path to it).
user@localhost$ ps -p $$ | tail -n1 | cut -d" " -f26
/usr/bin/bash
Another way to do it would be to use awk instead of cut:
ps -p $$ | tail -n1 | awk '{print $NF}'
Posted by Derek@TheDailyLinux »
2 Comments »
This came in handy for myself the other day and I figured it might come in handy for some of you out there. This is a quick command that will recursively do a find and replace for certain keywords by using a combination of grep and sed. Basically, we search recursively using grep and then we pipe in the filenames into sed for the string replacement.
grep -Irl keyword . | xargs sed -i 's/keyword/replacement/g'
Here’s a breakdown of the options used (I’ll assume you’re familiar with xargs and piping):
grep -I will ignore binary files
grep -r is recursive
grep -l will spit out the filename only
sed -i will edit the files in place
Posted by Derek@TheDailyLinux »
Add Comment »
Here’s a quick, simple tip to speed up the time it takes to compile a kernel or other program with a well designed Makefile (i.e. BusyBox): use the --jobs or -j make option. This will allow the compiler to execute in parallel in what’s known as recipes. Here’s a quick example for compiling a kernel zImage bootable image:
make -j4 zImage
This will spawn off 4 parallel compiling processes. There is not a limit for the number of job slots that you can use, but I’ve been told that as a general rule of thumb not to exceed more than twice the number of CPU cores you have. I don’t have any references (or extensive experience) to back that up, so take it for what it’s worth.
For more information, see the following resource:
http://www.gnu.org/software/automake/manual/make/Parallel.html
Posted by Derek@TheDailyLinux »
Add Comment »
There are ANSI escape sequences which allow you to set text attributes such as bold text and the color of the foreground and background of the text. You can incorporate these escape sequences into your scripts or shell. See the following resource for more information:
http://tldp.org/LDP/abs/html/colorizing.html
Posted by Derek@TheDailyLinux »
1 Comment »
I enjoyed this little tip from linuxjournal.com on how to convert filenames to lowercase recursively. Here’s an example of the command:
for x in `ls path/to/directory`; do if [ ! -f $x ]; then continue; fi; lc=`echo $x | tr '[A-Z]' '[a-z]'`; if [ $lc != $x ]; then mv -i $x $lc; fi; done
In my case, I wanted to find all files with a particular string in them and then convert to lowercase. This is what I used:
for x in `find path/to/directory -name "*theString*"`; do if [ ! -f $x ]; then continue; fi; lc=`echo $x | tr '[A-Z]' '[a-z]'`; if [ $lc != $x ]; then mv -i $x $lc; fi; done
Posted by Derek@TheDailyLinux »
Add Comment »
This was one of those “Hey! I didn’t know that!” moments when I found out that you can actually telnet to an SMTP server. This allows you to test the server as well as do other cool things such as send and receive email. By no means is it the most conventional way of sending and receiving email, but does help you flex your geek muscles a bit more. Since this is already a topic that is covered rather well by the community, I’m just going to refer you to the following article to give it a whirl:
http://www.yuki-onna.co.uk/email/smtp.html
Also, it appears that Google will allow you to do this with your gmail account (see the last answer):
http://mail.google.com/support/bin/answer.py?hl=en&answer=78775
What do ya know? It seems that there’s a similar thing for POP3 accounts as well:
http://techhelp.santovec.us/pop3telnet.htm
Have fun!
Posted by Derek@TheDailyLinux »
Add Comment »
Here is an example of how to backup a MySQL database to a dump:
mysqldump -u username -h hostname -p password db_name > dump.sql
Here is an example of how to restore a MySQL database from a dump:
mysql -u username -h hostname -p password db_name < dump.sql
You can also pass in a blank value for the password option and it will prompt you for it when you run the command rather than typing it out in plain text for all to see. Food for thought.
As always, be sure to check out the man pages for mysql and mysqldump.
Posted by Derek@TheDailyLinux »
Add Comment »
You can prevent the Gnome Display Manager (GDM), or the login screen, from loading on system startup by using the following command (run with root privileges):
sudo update-rc.d -f gdm remove
You can reverse this step by using the following command to restore GDM to defaults:
sudo update-rc.d gdm defaults 13 01
Posted by Derek@TheDailyLinux »
Add Comment »
Use the dmidecode utility to get information about the underlying hardware of your system including motherboard, memory, processor, and much more. Here’s an example of running the command (need root privileges):
sudo dmidecode | more
As always, be sure to check out the man pages for dmidecode.