Space Savers on the command line
AnthonyEnglish 270000RKFN Visits (4611)
System administrators are always looking for shortcuts, especially for those tasks and commands which we do all the time. Simple shortcuts really can save time when you're in a hurry. One of these is so obvious that people often overlook it: skipping the space. The other is more of a curiosity to do with the slash key. First the space saver.
"I need my space"
Actually, quite often you don't. For example, before and after the pipe key. As you know, the pipe, which looks like this:
| # That's Shift \ on most US keyboardsis used when you want to capture the output of one command as input into another command.
Two very common examples are when you want to view the output a page at a time using more or pg, or when using grep to search through the output of a command:
ls -l | more
Well, you don't need that space before or after the pipe key.
It's a keystroke saver, although not quite as readable as the spaced-out version.
Also known as alias
A lot of people are used to running the ls command with several different flags (e.g. ls -larts | more). We've already spoken about the virtue of laziness, where we touched on using aliases to shortcut very common commands. You may have an alias to do that long ls command for you. Now let's return to space.
There are a lot of common commands where you don't really need to use the space, although almost everyone does. For example this one to list all the adapters:
lsdev -Cc adapter
No need for the space after the second flag (the lower case c). So you could get used to doing this:
Or, as the man page for lsdev explains
the -C flag is not required, but is maintained for compatibility reasons.
So that command could be shortened to:
You can skip the space on the chdev command between the -l flag and the device name, and again between the attribute flag (-a) and the attribute itself.
chdev -lhdisk0 -ahc
This will work on lots of commands.
When the space suits
Sometimes it's more suitable to use the space for readability. Include the space if you're putting the command in scripts or documentation, or when someone's watching over your shoulder to learn. The rule I use is this: if someone's seeing my good work, I use the space, but when it's my own private command line, I don't use my space (or mySpace for that matter).
Slash that trailing slash
You may be in the habit of putting a trailing slash at the end of every cd command. You don't need to. So instead of this:
cd /home/users/ # trailing slash is harmless ... and uselessYou can do this:
Which is probably what you do anyway. Except that some people always add that trailing slash. Maybe they have web development in their blood. I'm speaking here of getting around the directory structure via the shell and the cd command,. As for adding trailing slashes to URLs you may like to look at To slash or not to slash?
Impress ///// your //// supergeek //// friends ////////
If you do happen to add a slash to announce where the directory ends, here's a geek party trick for you: you can use several slashes together! So this:
cd ////Does exactly the same as this:
cd /home/usersAren't you impressed? There are three occasions when that would actually be useful to know:
If you find yourself falling into category 3 above, it's probably time to seek some professional help.