Archive for the ‘Tips and Tricks’ Category
Posted by Derek@TheDailyLinux »
Add Comment »
Aliases are great and can make your life in the terminal easy. They give you a way to shorten multi-part or long commands into a single command. For example, if you’re always navigating to a certain directory like /home/username/this/directory, then you can more quickly chance to that directory by using a single command. Here’s what the alias for that would look like:
alias mydir='cd /home/username/this/directory/'
Now, whenever you type mydir, it will take you to /home/username/this/directory.
When you no longer need or want an alias, you can remove it using unalias. Here’s how to remove the example we just made above:
unalias mydir
As always, for more information on aliases refer to the man pages: alias, unalias.
Posted by Derek@TheDailyLinux »
1 Comment »
The utility aspell (along with others such as spell and hunspell), can be used to spellcheck a file from the terminal. You can also specify a file “mode” for which to scan. Modes include plain text, HTML, sgml, LaTeX, and others.
Usage Example
To list all of the spelling mistakes of the file “testfile.txt”, use:
aspell list < textfile.txt
To list all of the spelling mistakes of the HTML document “testpage.html”, use:
aspell --mode=html list < testpage.html
As always, be sure to take a look at the man pages for more information. Keep in mind that certain distributions may not come with aspell pre-installed, so you may need to use the package manager to install it (ie. apt-get install aspell or yum install aspell).
Posted by Derek@TheDailyLinux »
Add Comment »
It’s fairly common to edit the /home/user/.bash_profile file to setup a custom environment, such as alias and startup applications, for user, but what if you wanted that profile to be the same for all users (including root). The best way is to use a custom script that resides in the /etc/profile.d/ directory. This process is described briefly in /etc/bashrc:
# /etc/bashrc
# System wide functions and aliases
# Environment stuff goes in /etc/profile
# It's NOT good idea to change this file unless you know what you
# are doing. Much better way is to create custom.sh shell script in
# /etc/profile.d/ to make custom changes to environment. This will
# prevent need for merging in future updates.
Here is a quick example for taking advantage of this hook which assigns a simple alias. First, you must setup /etc/profile.d/custom.sh:
/etc/profile.d/custom.sh
chmod +x /etc/profile.d/custom.sh
Second, you must created the contents of /etc/profile.d/custom.sh:
#!/bin/sh
alias ls='ls -lah'
Third, simply log out and then back in again. You’ll notice the changes. You can verify this particular example by using the alias command:
$ alias | tail -n1
alias ls='ls -lah'
$
Of course, you’ll want to take what you’ve learned above and run with your own script suited to your needs. I hope this has helped you achieve your goal of creating a universal profile for all users on the system.
Posted by Derek@TheDailyLinux »
2 Comments »
Let’s get right to the point. Here’s how to install .rar support in Fedora 13:
1.) Open the terminal
2.) Copy/Paste the following into terminal
su -c 'rpm -Uvh http://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-stable.noarch.rpm http://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-stable.noarch.rpm'
su -c 'yum install -y rar unrar'
3.) Refer to the following pages for usage
Create/Compress/Archive Almost Any File in Linux (tar, tar.gz, tar.bz2, gz, bz, zip, 7z, rar, etc…)
Extract/Uncompress/Unarchive Almost Any File in Linux (tar, tar.gz, tar.bz2, gz, bz, zip, 7z, rar, etc…)
P.S.
For those die-hard one-liner fans out there, you can use the following instead:
su -c 'rpm -Uvh http://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-stable.noarch.rpm http://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-stable.noarch.rpm && yum install -y rar unrar'
Posted by Derek@TheDailyLinux »
Add Comment »
When you’re working in an embedded Linux environment, liberal use of the sync command can be a headache saver. Here’s the thing: in most embedded systems, your OS will be running from something like an SD card or flash and you may be subject to unexpected power loss. When you’re editing files or making changes in the filesystem, some of these edits and/or changes are only written to buffer cache, not the flash disk (not yet anyways). sync will force the system to commit the buffer cache to the disk.
As always, be sure to check out the man page for more information.
Posted by Derek@TheDailyLinux »
Add Comment »
Simply put, perldoc is the man page of perl applications. Use it and use it often when dealing with perl utilities. For example:
perldoc open
Reveals…
System::Library::Perl:User.Contributed PeSystem::Library::Perl::5.8.8::open(3)
NAME
open − perl pragma to set default PerlIO layers for input and output
SYNOPSIS
use open IN => ":crlf", OUT => ":bytes";
use open OUT => ’:utf8’;
use open IO => ":encoding(iso−8859−7)";
use open IO => ’:locale’;
use open ’:utf8’;
use open ’:locale’;
use open ’:encoding(iso−8859−7)’;
use open ’:std’;
DESCRIPTION
Full‐fledged support for I/O layers is now implemented provided Perl is
configured to use PerlIO as its IO system (which is now the default).
...
...
Posted by Derek@TheDailyLinux »
Add Comment »
I’ve been on a kick recently about doing everything in the terminal and I became excited about the possibility of grabbing weather through the terminal. I was excited until my little research on the subject revealed that this dead horse has been beaten left and right and up and down and diagonally. There were so many different ways of doing it, I sorta lost the urge to create a post about it. Well, here I am anyways listing the ones I found to be the most interesting. Check ‘em out if you’re interested…
http://fungi.yuggoth.org/weather/
http://linuxshellaccount.blogspot.com/2008/09/bash-script-to-get-weather-forecasts.html
telnet rainmaker.wunderground.com
curl http://weather.noaa.gov/pub/data/forecasts/city/state/city.txt
Posted by Derek@TheDailyLinux »
Add Comment »
A quick and easy way to troubleshoot network connections in an embedded Linux environment is to use the ping, tcpdump, and arp commands. This will allow you to see what might be happening with the traffic on your network at the packet level. Once scenario would be that you’re not getting a successful ping between two computers on the network. All reason tells you that it should be working, but maybe there’s something wrong at the driver level? To start troubleshooting, fire up tcpdump on the box being pinged (ip: 192.168.1.100) and specify the network interface and IP address of the machine doing the pinging (ip: 192.168.1.101):
tcpdump -i eth0 host 192.168.1.101
Now, run the ping test:
ping 192.168.1.100
At this point, if you get an output from tcpdump, you’ll know that the packet has made its way to the target machine (192.168.1.100). The next step would be to see if you ever received an acknowledgment from the target machine. Run arp on the machine doing the pinging (192.168.1.101):
arp -an
If you see something like ? (192.168.1.112) at (incomplete) on en1 [ethernet], that means you never got an acknowledgment back from the target machine (192.168.1.100).
At this point in this scenario, we would start to dive into what could be wrong. In this particular situation, it was a driver issue with assigning a MAC address to the interface.
This is just one scenario to get you familiar with how to use tcpdump and arp and gather information about the networking issue. Please refer to the utility man pages for more information.
Posted by Derek@TheDailyLinux »
Add Comment »
find /path/to/directory -type d -empty -exec echo {} ;
I think it’s easy to get the idea based on the example above, but just in case you need inspiration, you could automatically remove these empty directories with the following (Careful! This uses ‘-rf’ flag which shows no warnings or mercy!):
find /path/to/directory -type d -empty -exec rm -rf {} ;
Check out some additional methods here:
http://www.cyberciti.biz/faq/linux-unix-shell-check-if-directory-empty/
Posted by Derek@TheDailyLinux »
Add Comment »
In an embedded system without a battery backed real time clock (RTC), a time-based ‘fsck’ check can be quite annoying. To disable the time-based check, use the tune2fs command on the drive containing the root partition like so:
tune2fs -i 0 /dev/<device node>
There’s more information here at this link for those of you interested:
http://serverfault.com/questions/28343/will-my-system-fsck-when-i-reboot