Posted January 21st, 2010 |
Published in linux
The curse of the Linux shell history command strikes everyone, me included.
I’ve seen people fall into historical hell many a time…
You’re working in a shell and you need to run a command that you know you’ve run before, you know it. goddamit it, you’ve definitely run this one before. The command you want is at least 20 chars long and it’s just too much to type, so you either:
- Don’t find the command as you keep up-arrowing through your history. By the time you’re bored with the up-arrow, you’ve pressed it at least 40 times and you could have re-typed the command you were looking for in full by now, twice.
- Use CTRL+R and start to re-type your command so that the shell will find it in your history. And it doesn’t. So you type more. Still doesn’t find it. And then, as you fill out the command to find it, you’ve re-typed the whole thing anyway.
Posted March 26th, 2009 |
Published in linux
I’ve never fully understood what each directory was for on my Linux machine. Do apps get installed into /usr/bin or /usr/local/bin? Should mount points be in /mnt or /media? Those and many other questions were never answered.
Until now….
http://www.pathname.com/fhs/pub/fhs-2.3.html
Posted February 28th, 2009 |
Published in linux
du -hs -b <dir>
For example:

The “-h” parameter specifies human reaable output and the “-s” flag specifies that a summary should be printed. If you don’t specify the -s then the size of each sub-directoy is printed individually.
The “-b” parameter specifed that the output is show in bytes, if you remove it the output defailts to MB.
Posted November 14th, 2008 |
Published in linux,
ubuntu
Redhat, and possibly other, distros have the ll shell shortcut defined – it’s a shortcut to save you typing ls -l all the time. Once you start using it you really miss is badly when it’s not available. Ubuntu doesn’t have it setup as default.
But that’s easy to fix by editing your .bashrc file. The .bashrc file is in your home directory, open it in an editor, uncomment the following line and save:
#alias ll=’ls -l’
Note that files beginning with a dot are hidden files and you won’t be able to see them using Nautilus or any other GUI file browser by default. In Nautilus, navigate to your home folder and right-click in it and select show hidden files.
Say, for example, you have an application called DoStuff. For sake of argument lets say that this app scans a directory and searches for files called “steve.txt”. Because you have a large directory structure, this can take a number of minutes to complete.
You can run this from a console by simply typing its name:
steve@steve-desktop:~$ DoStuff
By doing this you will have to wait until the application has finished before you have control of this console again.
If you want to run this application in the background then you can simply add a “&” to the end of the command:
steve@steve-desktop:~$ DoStuff &
DoStuff now runs in a background process and you have not blocked your console. Of course, you could always open multiple console windows but that quickly clutters the screen up if you have too many.
You will notice that once your background process has finished running DoStuff it will print a status message to the console it was run from. Something along the lines of:
[1]+ Exit 1 DoStuff
This is a notification that the process has finished – you will see an error message if DoStuff terminated with an error
To recursively grep through directories you can use the find command to select a filenames in a directory tree and then grep to find a string within each file.
Here’s the command to find the string facebook in all javascript (*.js) files in the current directory and any sub-directories:
find . -name ‘*.js’ -exec grep ‘facebook’ -Hn ‘{}’ \;
Breaking that command down:
The first find parameter is the . that instructs it to start in the current directory. The -name parameter is followed by a filename wildcard to match, *.js in this case. Next parameter is the -exec, this is an instruction that find will execute for each file it finds – we are using grep. The grep ‘facebook’ -Hn is the grep command and its parameters – it tells grep to look for the string facebook and -Hn tells it to output the filename and line number of all matched files. Finally, the ‘{}’ \; are find parameters that instruct it to call grep for each file.
We can recursively grep for all files by omitting the -name parameter:
find . -exec grep ‘facebook’ -Hn ‘{}’ \;
We can look in another directory by changing the . for a directory name:
find /home/steve -exec grep ‘facebook’ -Hn ‘{}’ \;
Because this is a bit of a pain in the ass to remember I usually create a bash script called rgrep.sh or something like that and just call it from that.
Posted July 26th, 2008 |
Published in linux
The Linux shell’s history command is very useful. Typing ‘history’ will list you the last X commands you entered in that shell. Typing CTRL+R will pop up a prompt and allow you to search for a command by typing a section of it.
For example: Hit CTRL+R and then type ’svn’ will list the last svn command you entered. If you have more than one svn command in your history you can cycle through them by typing CTRL+R again until you get to the one you want.
The history and the CTRL+R selector are great; really useful when you need to re-run long-winded command lines. But, I think a GUI version would me way better. The CTRL+R doesn’t always work properly and sometime you can’t find a string in the history even though you know it’s there. It’s possible to accidentally run the wrong command because CTRL+R will always leave you with something from your history at your command prompt and it won’t always be what you wanted. Hastily hitting return on a command you didn’t want could be disastrous.
If you had a small GUI for history you could control your list much easier using the mouse. It’d still let you search for command using a regex input but there’d be no danger of accidentally running it at the command prompt; you’d have to paste it in first. The GUI version could also let you store your favourites so you can quickly re-run command commands. Favourites is probably not the right word to use, you’d have to be a serious geek to have a favourite command line, maybe something like Starred or Saved would be less romantic and geeky.
Maybe this GUI version already exists – searching for “linux history GUI” just throws up a load of links to pages talking about Linux’s progress etc.
General Shortcut Keys
| Alt + F1 |
Opens the Applicantions Menu . |
Window Shortcut Keys
| Alt + Tab |
Switches between windows. When you use these shortcut keys, a list of windows that you can select is displayed. Release the keys to select a window. |
Panel Shortcut Keys
| Ctrl + Alt + Tab |
Switches the focus between the panels and the desktop. When you use these shortcut keys, a list of items that you can select is displayed. Release the keys to select an item. |
Application Shortcut Keys
| Shortcut Keys |
Command |
| Ctrl + Z |
Undo |
| Ctrl + S |
Save |
| Ctrl + Q |
Quit |
It’s a pain in the nuts if you forget your mySQL root password. Here’s an easy way to reset it:
1) Stop any running mySQL deamons
2) Open a text editor and create a new file with the follownig line in it:
SET PASSWORD FOR ‘root’@'localhost’ = PASSWORD(‘<your new password>’);
3) Run the mySQL deamon and use the –init-file flag to force mySQL to process the change password command:
mysqld_safe –init-file=<the file from step 2> &
You might need to sudo that mysqld_safe command.
Posted January 10th, 2008 |
Published in linux
linuxHaxor.net have compiled a list of free eBooks about, or relating to, Linux.
Free linux ebooks.