LowEndBox - Cheap VPS, Hosting and Dedicated Server Deals

Finding your way on your first ever VPS - Part II

A couple of weeks ago, I posted the ‘Finding your way on your first ever VPS – Part I‘ tutorial. This is part 2 of that series in which I will introduce you to another couple of commands!

I am going to assume a Debian-based distribution in my examples. I’m using Ubuntu 14.04 more specifically. Most commands should work on any Linux distribution; the only distribution-specific commands are those for the package manager.

Ready? Set? Let’s go!

man

Last time I have already shown you what to do if you need help (type ‘–help’ behind a command). This help can sometimes be cumbersome, even cryptic. There are cases where you need more than just a single line of text.

‘man’ is the man for that job. If you type ‘man’ followed by another command (the name of the command/application you need help with) you get to see the manual for that command. So, for example, if you need more help with the command ‘cd’, type:

man cd

This will open a manual viewer where you can move around with the arrow keys, HOME, END, PAGE UP, and PAGE DOWN. If you want to quit the manual, press ‘q’ and you will return to your terminal shell.

Almost every application has a manual, though I do have to add that a small portion of them are quite bad. I doubt you will run into one of those any time soon, though.

cp

The ‘cp’ command enables you to copy a file or a directory. If requires two paths and a parameter in case you would like to copy a directory. The first path is the source path, so the file or directory you want to copy. The second path is the destination path, the file or directory you want to copy it to. This does not have to exist. If the target file exists, cp will overwrite that file. If the target directory exists, cp will throw an error.

For example, to copy the file ‘README.txt’ to ‘README-NEW.txt’, type:

cp README.txt README-NEW.txt

The above assumes the README.txt file is in the directory you are currently in. cp also works will full paths, though:

cp /home/johnsmith/README.txt /home/johnsmith/README-NEW.txt

And you can even copy things to another directory:

cp /home/johnsmith/README.txt /home/johnsmith/Documents/README-NEW.txt

Finally, copying a directory requires the ‘-r’ parameter:

cp -r /home/johnsmith/directory1 /home/johnsmith/directory2

mv

‘mv’ work very similarly to ‘cp’. It enables you to move a file or a directory, which can also be used to rename things. If requires two paths. The first path is the source path, so the file or directory you want to move. The second path is the destination path, the file or directory you want to move it to.

For example, to move the file ‘README.txt’ to ‘README-NEW.txt’, type:

mv README.txt README-NEW.txt

The above assumes the README.txt file is in the directory you are currently in. mv also works will full paths, though:

mv /home/johnsmith/README.txt /home/johnsmith/README-NEW.txt

And you can even move things to another directory:

mv /home/johnsmith/README.txt /home/johnsmith/Documents/README-NEW.txt

But, you can also move directories:

mv /home/johnsmith/directory1 /home/johnsmith/directory2

rm

‘rm’ is both a helpful and a dangerous command. It allows you to remove files and directories.

WARNING – Please be very careful with this command as it will often irrevocably remove files from your system without a way to get them back. Additionally, if may damage your system in such away that it may need to be reinstalled! – WARNING

rm takes one or more arguments of files to be removed. For example, if you want to remove the README.txt file, you type:

rm README.txt

Again, this also works with a full path:

rm /home/johnsmith/README.txt

To remove a directory that is empty, just use that directory path:

rm /home/johnsmith/emptydirectory

To remove a directory and all files in it, you can use the ‘-r’ parameter to remove files and directories recursively. You need to be very careful with this, because if you take it  level too high, you could use more files than you intended.

rm -r /home/johnsmith/nonemptydirectory

I can’t emphasize this enough: please be careful with rm!

less

To view text-based files, you can use the tool ‘less’. Less can basically work with any text-based file, but does not have syntax highlighting. It is especially useful for viewing log files or configuration files.

For example, to view the system’s log file (more about this later), type:

less /var/log/syslog

As you can see, less takes a path as an argument and that path needs to point to a file. Within less, you can use the arrow keys, HOME, END, PAGE UP, and PAGE DOWN to move around. Type ‘q’ to exit.

If you want to search for something inside less, type ‘/’ followed by the word/term you are looking for and press ENTER. This will give you the first highlighted result, if any. If there is more than one result, keep pressing ENTER until you get the desired result.

Final notes

That’s it again for this part of the tutorial. You’ve now learned some more commands to find your way about, but also to actually do some things. Feel free to experiment further with these commands or browse through their manual pages to find out what else they can do. I’ve only shown a very small portion of the available options.

See you next time, in Part III!

mpkossen

1 Comment

  1. Nice post for people new to Linux commands.

    September 28, 2014 @ 1:19 am | Reply

Leave a Reply

Some notes on commenting on LowEndBox:

  • Do not use LowEndBox for support issues. Go to your hosting provider and issue a ticket there. Coming here saying "my VPS is down, what do I do?!" will only have your comments removed.
  • Akismet is used for spam detection. Some comments may be held temporarily for manual approval.
  • Use <pre>...</pre> to quote the output from your terminal/console, or consider using a pastebin service.

Your email address will not be published. Required fields are marked *