Getting help with the Linux Command Line

This is a guest post by Taylor Douglass

The command line interface (CLI) is a very powerful part of Linux. Linux beginners undoubtedly agree that at first it can seem a bit daunting and even dangerous. While it is true that there far more Linux commands available than most will ever want or need to know and that some of these commands are capable of wreaking havoc on your system if used incorrectly; it’s reassuring to know that help isn’t far away. While a new Linux user who is Internet savvy might be inclined to run straight to Google when they need help with a particular command or are searching for the command they need, this is not necessary. In fact, most of the time you don’t even need to leave your terminal. How is this possible? Simple, it’s the man command.

Getting Started With Man

Man is short for Manual, and basically means that by using the man command you are accessing the manual for a particular command. Let’s begin by exploring how man is used. Startup a terminal and type “man intro”. This brings up a basic introduction to user commands, and the CLI in general. Once you have finished reading the intro go ahead and exit the manual page by hitting the letter “q”. You should now be back at the command prompt. The next step you will want to take is to read the manual page for the man command itself. This is accomplished by typing “man man“. You may be beginning to see a pattern here. To see the manual for any command simply type “man command” at the prompt. You may also begin to notice a pattern in how the manual pages look. Most manual pages consist of several different sections. Let’s take a look at the sections available for mv command. Type “man mv” into your terminal.

Name
This section shows the command and gives a brief description of the command. In our example we see that the mv command is used to move or rename files.

Synopsis
Here you can find precise information on using the command that you are viewing. This includes all the switches and options available for the command. The first two sections (Name and Synopsis) are meant to be a quick reference for using the command that you are viewing. Further sections dive a little deeper and give you even more information.

Description
The description section breaks down all of the options available and tells you what they do. In our example with mv we can see that using the -i option prompts the user before overwriting any files that are being moved. Also note that we could also use –interactive to do the same thing.

Other sections
Other sections that you might find in the manual pages are author information, bugs, copyright, files, see also, and examples. The two that might be worth mentioning are the See Also and Example sections. See Also gives you a list of other manual pages that may be relevant to the page you are currently viewing, while the Example section gives you a real world example of using the command you are viewing.

Searching For Commands

Let’s say that you want to copy a file but you are not sure what the command for copy is. Perhaps one of the most useful features of the Linux manual pages is the ability to search them. If we look at the manual page for the command man (Again that is “man man” at the command prompt) we can see that one of the options available is -k. What this option does is allow us to search the short description for keywords and display any matches. Back to our example for finding the command to copy files, let’s get to the command prompt and type “man -k copy“. This displays all the commands that have “copy” listed in the description. If you glance through the list of commands that man -k has found you should see “cp(1) -copy files and directories“. That looks like the command we need, but to be sure let’s look at the manual page for that command to be sure. “man cp” brings up the manual page for the command cp. As you can see by looking at the name and synopsis sections, this is indeed the command we need to copy a file.

Man I’m Glad There are Manual Pages

The man command has gotten me out of a jam on more than one occasion. I recommend that if you are just beginning to explore the CLI that you do a quick check in the manual before using any command. As I mentioned before the CLI is very powerful and it’s better to be safe than sorry when using it.

Creating Custom Linux Commands

This is a guest post by Taylor Douglass

The other day I ran across a script at shell-fu that generates a random quote from their website (here). I thought it would be useful to make this a command that I could execute at any terminal at anytime. Let’s get started.

First of all you are going to need links. If you don’t have links or are not sure if you do or not, fire up a terminal and type the following:

# sudo apt-get install links

Next navigate to your /bin folder and create the file

# sudo touch shell-fu

Make the file readable and executable

# sudo chmod +rx shell-fu

Now edit the file and add the code for retrieving the shell-fu quote (I use nano for this)

# sudo nano shell-fu
# links -dump "http://www.shell-fu.org/lister.php?random" | grep -A 100 -- ----
^O (writes the file from nano)
^X (exits nano)

You now have a custom command named “shell-fu” that you can type from anywhere and retrieve a random shell-fu quote.

The chage command changes the number of days between password changes and the date of the last password change. This information is used by the system to determine when a user must change his/her password.

Example:

adam@desktop:~$ sudo chage -l adam
Last password change : Mar 02, 2008
Password expires : Apr 11, 2008
Password inactive : never
Account expires : Mar 30, 2009
Minimum number of days between password change : 20
Maximum number of days between password change : 40
Number of days of warning before password expires : 7
adam@desktop:~$

Read the man page of chage here.

Need to find out what all the file types in a certain directory are? Simple!

Execute the following on the command line:

find /path/here/ -type f -print | xargs file

I typed: find /home/adam/test/ -type f -print | xargs file

The output will look something like this:

/home/adam/test/music.wav: RIFF (little-endian) data, WAVE audio, Microsoft PCM, 16 bit, mono 44100 Hz
/home/adam/test/package.deb: Debian binary package (format 2.0)
/home/adam/test/file.tar.gz: gzip compressed data, from Unix, last modified: Tue Jun 20 12:51:11 2006
/home/adam/test/widget.xml: ASCII text, with CRLF line terminators
/home/adam/test/logfile.txt: empty

Cheers!

Command Line Progress Bar

Have you ever had to copy a fairly large file on the command line and wondered what the progress was? The command line progress bar seems to do a decent job at showing the percentage and estimated time of a copy.

Description from the site:

Bar is a simple tool to copy a stream of data and print a display for the user on stderr showing (a) the amount of data passed, (b) the throughput of the data transfer, and (c) the transfer time, or, if the total size of the data stream is known, the estimated time remaining, what percentage of the data transfer has been completed, and a progress bar.

Bar was originally written for the purpose of estimating the amount of time needed to transfer large amounts (many, many gigabytes) of data across a network. (Usually in an SSH/tar pipe.)

Go check it out!

Quickzi: How to Jail VSFTPD Users

If you’re worried about FTP users exploring outside of their home directory, you want to set up what is called a chroot jail.

To do this, open the /etc/vsftpd.conf file:

vim /etc/vsftpd.conf

and make the following modifications (line should be uncommented):

chroot_local_user=YES

After you save the file, restart vsftpd:

/etc/init.d/vsftpd restart

Now all users will be jailed to their own home directory when using FTP.
Now, lets say you only want to jail certain users, and allow other users to browse other directories. To do this, you’ll want to again edit the configuration file.

vim /etc/vsftpd.conf

uncomment the following lines:

chroot_list_enable=YES
chroot_list_file=/etc/vsftpd.chroot_list

After you save the file, restart vsftpd:

/etc/init.d/vsftpd restart

Now you will need to create the /etc/vsftpd.chroot_list file and add in users you do NOT want to jail. By default, all users will be jailed. In the /etc/vsftpd.chroot_list file you can specify what users to allow to browse all directories.

ColorMake: A colorful make output

ColorMake is a neat wrapper script written in Perl that generates a colorful make output when compiling an application on the Linux command line. Once installed, basically all you need to do is type “cmake” or “clmake” whenever you would ordinarily type “make”. This is useful for those of us who like to compile from source and want to be able to distinguish between output lines. Go check it out.

5 Linux Text Editors You Should Know About

As some of us already know, one of the greatest things about Linux is that there can be a variety of different ways to do one particular thing, resulting in the same outcome no matter how it is done. Read the rest of this entry

Kent Johnson over at SquareBits has enlightened us on three useful commands to find out which files and directories are the largest on your Linux system. These commands are helpful to have when your hard drive becomes full and your wondering if there are files that are taking up space that actually shouldn’t be. Read the rest of this entry