Linux command line
Linux has come a long way in the past two years. Today much of what needs to be done on a Linux machine can be done using a mouse and a little pointing and clicking. Occasionally, however, there are things that still require a little under-the-hood tinkering, where a rudimentary understanding of the command line comes in handy.
In response to regular comments from readers who ask for more detail on the commands we use in articles, Tectonic has put together our top eight list of must know command line tools. The list is not exhaustive and certainly not comprehensive, but if you know these commands you’ll convince most of the people most of the time that you’re a Linux guru.
< !-more-->
1: sudo/su
su is for switching users, usually to switch to the root user. sudo is a shorthand way of executing a command as the root user without needing to log in as root. Linux is a true multiuser system with each user having their own account and set of access privileges. The superuser or administrator account is called the ‘root’ account.
Today’s modern Linux systems usually force users to create non-root users when first installing, which is a sensible precaution. Running a system as root is potentially fatal because it is remarkably easy to break something by executing a wrong command. And as root, the system can’t protect the users from themselves. There are times, however, when it is important to be the root user - when installing software for example - and a way to switch to root temporarily is provided by sudo.
To use sudo do this:
sudo command you want to execute
You will be prompted for a password. You don’t need the root password. Just type in your password and the command will be executed as root. Once the command is done you will be returned to your own login.
su is a more permanent solution in which you are able to switch to another user for a whole session. To use type in su username you want to switch to and provide the password of the user when prompted. You will then have the privileges of the other user. To return to your own login type exit.
2: ls
One thing you’ll always need to do at the command line is list the contents of directories. ls does exactly this. ls is similar to the dir command on Windows and DOS. It lists all the files and directories in the current directory. ls /usr/share/ will list the contents of the /usr/share directory.
3: mv/cp
Something else you’re going to need to do is move and copy files from one directory to another. This is where mv and cp come in handy.
mv file1.txt /usr/share/ will move the file file1.txt to the /usr/share directory. mv *.txt /usr/share/ will move all the files with the .txt extension to the /usr/share directory.
To rename file1.txt as file2.txt mv file1.txt file2.txtcp works exactly as mv does except that is duplicates the file. So cp file1.txt /usr/share/ will copy file.txt to the /usr/share directory and keep a copy in the current directory as well.
4: cd
cd is the change directory command you’ll need to switch from one directory to another. Typing in cd /usr/share for example will switch you to the /usr/share directory. To get back to your home directory type in cd ~/. The tilde sign (~) represents your home directory.
5: man
man stands for manual. Most commands in Linux have a built-in manual entry. So next time you’re confused about how to use a command type in man command which will bring up the description of the command and its various options. Try man cp for example.
6: less/more
less and more do essentially the same thing: they display the contents of a file. less file1.txt will print out the contents of file1.txt in the terminal window a screenfull at a time. Use the spacebar or the arrow keys to navigate up or down the file.
7: locate
locate is a speedier way than find to find files on your Linux system. There is a caveat, however. Locate works so quickly because the filesystem is indexed ahead of time. Most Linux systems are set up to run updatedb at regular intervals which does the indexing.
locate filename or portion of filename will find the various files you are looking for, so long as they have been indexed. If there are pages of results use the more command to display them one screenfull at a time: locate filename | more.
The ‘|’ is called a pipe and it effectively filters the results of one command (in this case ‘locate’) through a second command (’more’ in the example’).
8: tar
Many of the files you will download for Linux will be compressed using a combination of tar and gzip. The files will most likely look something like filename.tgz or filename.tar.gz.
tar creates an archive of a number of files and gzip compresses the archive. To decompress these types of files do this: tar -zxvf filename.tgz which will decompress the file and pull the contents out of the archive file.
February 19th, 2008 at 6:11 am
Honestly, I believe I was regarding in pudgy with Damon. The carrying was fascinating.