More basic Linux commands you need to know for CompTIA’s new A+

Posted on
Share on Google+Share on LinkedInShare on FacebookShare on RedditTweet about this on TwitterEmail this to someone

Knowing basic Linux commands will help you pass the new CompTIA A+ exam.Last month, we looked at some of the changes coming in the CompTIA A+ exams as they are being updated. The new exams (to be named 220-901 and 220-902) are expected by the end of the year and one of the topics being added is that of Basic Linux commands. Due to space constraints, approximately half of the commands were covered and this month we look at the rest of the basic Linux commands CompTIA wants you to be familiar with for the upcoming A+ certification exams.

Changing Permissions and Ownership

You may need to change a file’s permission settings to protect it from others. Use the chmod command to change the permission settings of a file or a directory. To use chmod effectively, you have to specify the permission settings. A good way is to concatenate letters from the columns of the following table in the order shown (Who/Action/Permission). You use only the single character from each column — the text in parentheses is for explanation only.

Letter Codes for File Permissions

WhoActionPermission
u (user)+ (add)r (read)
g (group)- (remove)w (write)
o (others)= (assign)x (execute)
a (all)s (set user ID)

 

For example, to give everyone read access to all files in a directory, pick a (for all) from the first column, + (for add) from the second column, and r (for read) from the third column to come up with the permission setting a+r. Then use the set of options with chmod, like this:

chmod a+r *.

On the other hand, to permit everyone to execute one specific file, enter:

chmod a+x filename

Then type ls -l to verify that the change took place.

Another way to specify a permission setting with chmod is to use a three-digit sequence of numbers. In a detailed listing, the read, write, and execute permission settings for the user, group, and others appear as the sequence …

rwxrwxrwx

… and dashes will appear in place of letters for disallowed operations. Given that, you should think of “rwxrwxrwx” as three occurrences of the string “rwx.” Now assign the values r=4, w=2, and x=1.

To get the value of the sequence rwx, simply add the values of r, w, and x (4+2+1=7). With this formula, you can assign a three-digit value to any permission setting. For example, if the user can read and write the file but everyone else can only read the file, then the permission setting is rw-r–r– (that’s how it appears in the listing), and the value is 644. Thus, if you want all files in a directory to be readable by everyone but writable only by the user, use the following command:

chmod 644 *

The following table shows some common permissions and values.

Common File Permissions

PermissionNumeric Value
rwxrwxrwx777
rwxr-xr-x755
rwx-—x–x711
rw-r—r–644
rw-r—–640

 

Sometimes you have to change a file’s user or group ownership for everything to work correctly. For example, suppose you’re instructed  to create a directory named “cups” and give it the ownership of user ID lp and group ID sys. You can log in as root and create the “cups” directory with the command mkdir:

mkdir cups

If you check the file’s details with the ls -l command, you see that the user and group ownership is root root. To change the owner, use the chown command. For example, to change the ownership of the “cups” directory to user ID lp and group ID sys, type

chown lp.sys cups

Working with Files

To copy files from one directory to another, use the cp command. If you want to copy a file to the current directory, but retain the original name, use a period (.) as the second argument of the cp command. Thus, the following command copies the Xresources file from the /etc/X11 directory to the current directory (denoted by a single period):

cp /etc/X11/Xresources .

The cp command makes a new copy of a file and leaves the original intact.

If you want to copy the entire contents of a directory — including all subdirectories and their contents — to another directory, use the command cp -ar sourcedir destdir. This command copies everything in the sourcedir directory to destdir. For example, to copy all files from the “/etc/X11″ directory to the current directory, type the following command:

cp -ar /etc/X11 .

To move a file to a new location, use the mv command. The original copy is gone, and a new copy appears at the destination. You can use mv to rename a file. If you want to change the name of today.list to old.list, use the mv command, as follows:

mv today.list old.list

On the other hand, if you want to move the today.list file to a subdirectory named “saved,” use this command:

mv today.list saved

An interesting feature of mv is that you can use it to move entire directories (with all their subdirectories and files) to a new location. If you have a directory named data that contains many files and subdirectories, then you can move that entire directory structure to “old_data” by using the following command:

mv data old_data

To delete files, use the rm command. For example, to delete a file named old.list, type the following command:

rm old.list

Be careful with the rm command — especially when you log in as root. You can inadvertently delete important files with rm.

Working with Directories

To organize files in your home directory, you have to create new directories. Use the mkdir command to create a directory. For example, to create a directory named “images” in the current directory, type the following:

mkdir images

After you create the directory, you can use the cd images command to change to that directory.

You can create an entire directory tree by using the “-p” option with the mkdir command. For example, suppose your system has a “/usr/src” directory and you want to create the directory tree “/usr/src/book/java/examples/applets.” To create this directory hierarchy, type the following command:

mkdir -p /usr/src/book/java/examples/applets

When you no longer need a directory, use the rmdir command to delete it. You can delete a directory only when the directory is empty. To remove an empty directory tree, you can use the “-p” option, like this:

rmdir -p /usr/src/book/java/examples/applets

This command removes the empty parent directories of applets. The command stops when it encounters a directory that’s not empty.

Networking Utilities

Knowing basic Linux commands will help you pass the new CompTIA A+ exam.Just as you can use the ipconfig command to see the status of IP configuration with Windows, the ifconfig command can be used in Linux. You can get information about the usage of the ifconfig command by using “ifconfig -help.” The following output provides an example of the basic ifconfig command run on a Linux system:

eth0      Link encap:Ethernet  HWaddr 00:60:08:17:63:A0

inet addr:192.168.1.101  Bcast:192.168.1.255  Mask:255.255.255.0

UP BROADCAST RUNNING  MTU:1500  Metric:1

RX packets:911 errors:0 dropped:0 overruns:0 frame:0

TX packets:804 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:100

Interrupt:5 Base address:0xe400

lo        Link encap:Local Loopback

inet addr:127.0.0.1  Mask:255.0.0.0

UP LOOPBACK RUNNING  MTU:3924  Metric:1

RX packets:18 errors:0 dropped:0 overruns:0 frame:0

TX packets:18 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:0

In addition to ifconfig, Linux users can use the iwconfig command to view the state of a wireless network. Using iwconfig, you can view such important information as the link quality, AP MAC address, data rate, and encryption keys, which can be helpful in ensuring that the parameters in the network are consistent.

Next Month

Having concluded looking at the basic Linux commands CompTIA wants you to be familiar with for the upcoming A+ certification exams, we will next turn our focus to Windows 8/8.1.

Share on Google+Share on LinkedInShare on FacebookShare on RedditTweet about this on TwitterEmail this to someone
Emmett Dulaney

ABOUT THE AUTHOR

Emmett Dulaney is an associate professor and the author of numerous certification study guides, including the CompTIA A+ Complete Deluxe Study Guide, Second Edition (ISBN: 978-1-118324066).

Posted in Certification|

Comment:

Leave a comment

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>