Linux Command Line 101By Veronica Henry
Most of us are familiar with using what is called a Graphical User Interface (GUI), be it GNOME or KDE based, to navigate our computers. What beginners don’t realize, is that underneath that interface, lives the Linux command line.
Those coming from the Windows world may easily confuse the DOS window with the Linux command line, but the two are worlds apart in terms of structure and power.
Using the command line, you can issue commands directly to the computer to perform tasks that you’d normally complete with a mouse. Starting a program, file management, system monitoring and more can all be performed without a single mouse click.
Some swear by the command line, while others are happy never to have to encounter that intimidating black screen. If you’re the curious type and want to explore the full power of your Linux system that your GUI conveniently hides, then read on.
The shell is the piece of the puzzle that actually does the work. It takes the commands you type in and hands them off to the operating system for action.
Bash (which stands for Bourne Again Shell), is the default shell program for most Linux distributions. There are many others though, kshh, tcsh and zsh to name a few.
Under Ubuntu, you can launch the terminal through the Applications menu, under Accessories or by hitting Alt+F2 and typing “terminal”. Other distributions may have the launcher located elsewhere. It could be called terminal, konsole or Xterm, but the icon is usually a black computer screen.
When you launch a terminal window, you’ll see your name, followed by your computer name and either a $ (logged in as user) or # (logged in as root). For example:
To leave the terminal and return to the GUI, type “exit”.
Navigating the File System
Coming from the Windows world, the most difficult concept for me to grasp was the different directories and structure. Filenames are case sensitive and extensions aren’t mandatory. Root is represented by a forward slash (/) and contains system files.
Linux Command Line 101: Commands
A full list of commands is available at the Linux MAN pages. Here is a subset of commands that you’ll find yourself using most:
- pwd – prints your working (or current) directory
- cd – change directory
- ls – list the files in the working directory
- cp – copy files and directories
- mv – move or rename files and directories
- rm – remove files and directories
- mkdir – create a directory
• Viewing Text Files with cat and less
Many files in Linux can be viewed as plain text. There are several ways to edit these files, but if you’d just like to view them, here are the 2 most simple: cat and less.
To use cat, simply type cat and the file name:
janedoe@janespc:~$ cat my_file
Use less when you have a longer file that doesn’t fit onto one screen. Navigate using the up and down arrow keys.
janedoe@janespc:~$ less my_file
Another way that Linux differs from Windows is in its ability to have multiple users working on the same pc at once. In order to manage this tricky process seamlessly, you can use permissions.
Here are some basic permission commands:
- chmod – modify file access rights
- su – temporarily become the superuser
- chown – change file ownership
- chgrp – change a file’s group ownership
• System Information
When troubleshooting your Linux box, system information is often the first piece of information you’ll need to know. The kernel version, partitions and other hardware information can easily be obtained from the command line.
This is just a sample of commands for viewing system information:
- uname – show kernel version and system architecture. (several options available including -s – kernel, -o for operating system. -a prints all options)
- cat /proc/partitions – show all partitions registered on the system
- grep MemTotal /proc/meminfo – show RAM total seen by the system
- lspci -tv show PCI info
- lsusb -tv – show USB info
- Disk Space
- df -h – Show free space on mounted filesystems
- fdisk -l – Show disks partitions sizes and types (run as root)
Linux Command Line Resources
In terms of Linux command line functionality, we’ve barely skimmed the surface here. If you’d like to delve a little deeper, be sure to check out IBM’s introductory course on the Linux command line. Tuxfiles also has a good tutorial. Finally, the Linux Pocket Guide is a free download and an invaluable resource for beginners, one that I still reference often.
Why Learn The Linux Command Line?
For most users, the GUI will provide all the functionality and interface with the OS that they need. However, there are times where it is possible that your GUI can become inoperable. Knowing how to navigate the command line will ensure you can troubleshoot, access and possibly backup your system.
Additionally, for those inclined to truly understand the inner workings of their Linux OS, mastering the the command line is a hard-earned right of Linux passage.
About the Author
Veronica Henry is a writer, web developer and tech guru. Her 20 year IT career came to an end when her inner writer and entrepreneur inexplicably besieged her to give it all up. She is a self-proclaimed girl-geek and linux convert, who has held MCSE, GSEC and PMP certifications. In her dreams, she is a international best-selling sci-fi and fantasy author, but in the meantime, she now spends her days writing, managing her websites and wrecking havoc on her Ubuntu laptop.
Author's Website: http://www.veronicawrites.com
- How To Defrag from the Windows 7 Command Line
- Take Command of Server 2008 with Windows PowerShell – Part 1
- The sound of no command
- How to Create a Separate Home Partition in Ubuntu Linux
- Top 9 Linux Productivity Tips and Tools
- Take Command of Server 2008 with Windows PowerShell – Part 3
- Take Command of Server 2008 with Windows PowerShell – Part 2
- CompTIA Linux+ Certification Overview
- How to Install Google Chrome and Chromium in Ubuntu Linux 9.10
- Top 7 Linux Open Source Development Tools