A Few Useful Linux Command Line Tips
Just to spare you the pain, I won't go into my usual spiel about how useful the command line is. It is, even for the non techie.
In the terminal window, there are so many commands and so little time to learn them all. And there are so many little tips and tricks that can make life (or even just a visit) to the command line a bit easier.
Let's take a look at a few of my favourite tips. If you've been using the command line for any length of time, these tips will probably be old hat to you. But if you're still learning about the Linux command line, then you might find these tips useful.
Quickly Clearing the Terminal Window
I don't know about you, but I find a cluttered terminal window to be more than a little distracting. Normally, you'd get rid of everything that's in the window using the clear command. But why use six keystrokes (five for the command, plus Enter) when you can use three?
To quickly clear a terminal window, type CTRL+l (that's a lower-case L if you're wondering).
The Dot is Your Friend
At least when moving things around ...
By the dot I mean . — a simple period. When you're copying or moving files around your computer, or when transferring files via ssh from a remote server, the dot signifies the directory that you're currently in.
If you issue a copy or move command without a destination, then you'll get a missing destination file error. That's where the dot comes in.
Let's say you're in the directory /home/scott/Writing/Completed/, and you have a directory one level above named WiP (where you keep drafts of your writing).
Use the following command to move the file CLI_Tips.odt from the directory WiP to the current directory:
cp ../WiP/CLI_Tips.odt .
Continuing an Interrupted scp Yransfer
scp is a very useful tool for securely transferring files between your computer and a remote server. But, sometimes, things can go wrong.
A couple of months back, I was transferring a large file to my computer when the connection with the remote server was lost. I'd only received about 48% of the file. Instead of starting from scratch, I used another command called rsync to pick up the transfer where it left off.
To do that, you'd use the following command:
rsync —partial —progress —rsh=ssh user@host:/pathto/remotefile .
Notice the dot at that end of the command? I told you it was useful ...
The Semicolon and Ampersand are Your Friends, Too
If you need to run multiple commands but don't run those commands often enough to justify writing a script, there are two easy ways to string them together. You can separate the commands (and any parameters they take) with a semicolon (;) or with a pair of ampersands (&&).
If you use a semicolon, make sure it comes right after the command, followed by a space. With the two ampersands, make sure there's a space before and after them.
Quickly Returning to Your /home Directory
Specifically, to the top level of the directory. How? By typing cd ~/ or just cd ~.
The tilde is simply a shortcut. Your system knows it means /home, and you can use it to return to the top level of your /home directory from any folder on your computer. That includes any sub folder in your /home directory. Like many of the tips in this post, using the tilde saves you keystrokes.