Archive for October, 2003
LCOD – 10.23.03 – turn off annoying console beeps
Posted by Jon Zobrist in Linux, Linux Command of the Day on October 23, 2003
xset -b
This will disable console beeps, finally, peace.
LCOD – 10.20.03 – X hotkeys
Posted by Jon Zobrist in Linux, Linux Command of the Day on October 20, 2003
It’s likely you’re using X windows if you’re using Linux on the desktop.
Here’s a couple quick things that could come in handy in X.
CTRL-ALT-BACKSPACE will forcefully kill an X server. Use this if your X server is messed up and needs to be killed. It’s handy if you’ve got a broken process that’s spiraling out of control, or you just want X dead fast. Usually you’ll be kicked back to the login screen, but sometimes X won’t recover well and you’ll need to reboot or restart xdm.
CTRL-ALT-+/- … That is control alt and the plus or minus keys. CTRL-ALT-+ will increase your resolution to the next one in your config file, and CTRL-ALT– will decrease your resolution. Useful for some games I’ve had that when you’re done they leave you in 640×480.
xkill … xkill is a program that can be used to forcibly kill misbehaving programs under X. If you’ve got a window that won’t respond and isn’t dying easy, you COULD find out it’s process id or name and do some kill -9′s on it, OR you could run xkill and click on it. This will remove the windows resources and very rapidly kill it. Hasn’t failed me yet.
LCOD – 10.16.03 – Finding files on your hard drive
Posted by Jon Zobrist in Linux, Linux Command of the Day on October 16, 2003
There are 2 main commands I use daily to find files on your hard drive. The first is locate, and the second is find. man locate, and man find will tell you more about these commands.
Locate relies on a database of all the files on your hard drive. This database is normally created and maintained by cron scripts, if you run locate and it says something about your database isn’t updated run updatedb and wait for a long time. I often run updatedb & so it runs in the background so i can keep looking for the files i want manually. The basic way to use locate is locate word. This will search the locate database for “word”. A few quick notes, like most things on Linux the search term is case sensitive. So Word and word will match different patterns. Also, this will match words that contain your search pattern, so avoid short searches. If you’re looking for a bunch of files try piping your output to more or less.
locate word | less
Find all .mp3 files on your hard drive
locate .mp3 | less
Find your log files
locate .log | less
Locate is more useful if you don’t know which tree/directory the files you’re looking for are in. Also, locate -i will ignore the case of the searched term, so if you want to find all .mp3 or .MP3 or .Mp3 files
locate -i .mp3 | less
Now, find searches a given path, for differnet types of information.
It’s useful if you need to find changed files in a specific tree of your hard drive. It’s syntax is a little more confusing, and in my opinion non-intuitive. from man find we get it’s usage as
find [path...] [expression]
The most common way I use this is
find . -name “*word*”
where word is part of the filename I’m looking for
This finds all files in the current directory and below with word in their names.
But, you can do more than just simple word pattern matches
try these
Find all files in the current directory and below accessed within the last 60 minutes
find . -amin -60
Find all empty files in and below /home/me
find /home/me -empty
With these 2 find commands you should be able to find most things on your filesystems. Checkout the man pages, (man locate and man find) for more examples and full usage.
One last thing, if you’re always finding you need to updatedb then you’re linux box isn’t running updatedb from any cron script. Write one! Add it to your crontab.
I recommend making sure you don’t have an existing crontab as root.
crontab -l > /root/cron
edit /root/cron and add a line like this
0 0 * * * /usr/bin/updatedb >> /root/update.log 2>&1
make sure it’s all on one line
then run
crontab /root/cron
run crontab -l to check that you’ve installed roots new crontab file correctly
and now your update database should be rebuilt nightly
LCOD – 10.15.03 – BASH working with your command history
Posted by Jon Zobrist in Linux, Linux Command of the Day on October 15, 2003
Command history searching in bash:
If you’re at the command line, and in Linux you’ll find yourself there often, and you want to find a command you had previously typed (so you don’t have to type it again, say), hit CTRL-R and start tying some letters from that command. Hit CTRL-R to get the next match. It will show them to you on the command line, and in order from most recent to least recent.
So, say you had recently scp’d a file and you want to do the same thing again, hit CTRL-R then type scp, if you’d recently done multiple scp’s or there are other commands with the letters scp in them, hit CTRL-R again and again till you find the one you want.
Last command substitution in bash:
You’re at the command line and you just typed a very long command, but when you hit enter it gave you an error, pressing the up arrow shows you the command, and you see a typo. You could use the left/right arrows to get to the typo and fix it, OR, you could use a simple character substitution. To redo your previous command with a simple substitution, use the carat key ^, that’s shift-6. The first carat will denote what you’re deleting, and the second carat will denote what you’re replacing it with.
So, you typed
scp fillename.tar.gz root@10.1.1.1:/usr/portage/distfiles/
^ll^l
will redo the command with 1 less ‘l’
You can also leave off the second carat if you’re just deleting letters
so
^l
would do the same thing.
A couple caveats for carat use, first is that it’s a simple match, no regular expressions going on, and second is that it will match exactly and only once. So if there was a single l before the first one in fillename.tar.gz it would be deleted by the second command.
If you’ve got CTRL-R down and the ^^ substitutions, you’re well on your way to speedy command input. But what if it’s a new command, and you’re too lazy to type the full path, or you don’t know where something is and don’t want to have to retype your whole command again. Use the TAB key when typing a command. One tab will try to finish the current path or command, two tabs will list any possible commands or paths. From your bash prompt, type sc and hit TAB. You’ll either get scp or a beep indicating there are more than one possible commands. Hit TAB again and you’ll get a list of the possible commands.
Hope these help!