Ubuntu Linux, Day 18: What Is This ‘sudo’ You Speak Of?
By Tony Bradley
30 Days With Ubuntu Linux: Day 18
From the beginning of the 30 Days With Ubuntu Linux series I have had readers suggest solutions for various issues that involve the command line. In general, I prefer to work with the graphical interface, but it is worthwhile to be familiar with the command line interface so today I decided to poke around on it.
Before I started using Windows, I used DOS, and I was fairly adept at navigating and manipulating DOS from the command prompt. I have used Windows since Windows 3.0–when it was still a separate graphical user interface application that ran on top of DOS. Since Windows 95, though, DOS has been integrated with Windows as a single unit, and the command prompt has been relegated to a sort of legacy role that only IT admins ever really master.
You can click on the Ubuntu logo icon and select Terminal to open a command prompt window. I am using Unity, so I opened the Applications lens and typed Terminal in the search field to get to it. However you get there, you will see the sparse black box with a little bit of text indicating the current directory path that your command line session is operating from.
If you just open Terminal, it defaults to your user folder. In DOS or Windows, this is where I might type “dir” to get a listing of the directory. In Linux, though, “dir” is replaced with “ls”. You can then use switches like “-l” for a more detailed listing including permissions and file sizes, “-a” to display all files including hidden files, and “-h” to show file sizes in KB or MB instead of just bytes.
Some other common commands you might need when working with the Ubuntu command line are “cd” for change folder (typing “cd ..” will switch to the parent folder), “cp” to copy a file or folder, “mv” to move a file or folder, and “rm” to remove or delete a file or folder.
There is a little learning curve to understanding and working with permissions from the command line. If you use the “-l” switch, the permissions displayed appear to be a random string of gibberish at first glance-for example “drwxrw-r–“.
The first letter indicates the type of data. In this case, the “d” indicates that these are permissions for a directory. If the first character were a “-” this would be a file, and if the first letter were an “l” it would be a link.
The characters after that are actually three groups of three. The first three are the permissions for the owner of the file or folder, the second are permissions for group members, and the third are permissions for all others. The three characters are for read, write, and execute. A letter indicates that group has that permission, while a dash indicates it does not. So, “rwx” means full permissions to read, write and execute, while “r–” would be read only.
Two other key commands when using the Ubuntu command line are “grep” and the seemingly ubiquitous “sudo”. Grep is a command used to search a specified file for a specific word or phrase. I have not used it extensively myself, but I have read enough tech books, and talked with enough gurus smarter than myself to know that this is a valuable, and frequently used command.
No command, however, is more valuable or frequently used than “sudo”. Sudo is a mashup of “super-user do”, which basically tells Ubuntu to execute commands with root–the Linux equivalent of “administrator”–authority. Ubuntu will require a password to authorize running commands with root powers, and once the password is supplied your bidding will be done.
Now, I am only writing a simple article. I am not trying to completely master the Ubuntu command line myself, nor do I intend to pretend that I could convey it all to you in the course of a single article. For that, you would need a book.
So, this is where I give a shameless plug for a book by a PCWorld peer of mine Keir Thomas. Keir wrote a self-published Kindle book called Linux Nitty Gritty: Working at the Ubuntu Command-Line Prompt. It is clear, concise, and informative, and easily worth more than the 99 cents it costs to purchase from the Amazon Kindle store. I know it helped me, and if you have any interest in learning to navigate and manipulate Ubuntu Linux from the command line, I highly recommend this book.