|
|
|
Learning to use the Linux Command Line InterfaceAuthor: Kylie Davies AbstractThis document describes some of the Linux commands covered during the "basic Linux commands" class. Conventions used in this document .Where demonstrating usage - it is not necessary to type anything before a command line prompt A command line prompt can be $ (regular issue Joe Bloggs user) or # (root user prompt). Usage of commands will be represented in italics. ~ represents the home directory. What it all meanskylie@thinking:~$ Where kylie is the user name, thinking is the host name, ~ means home directory and $ is the prompt. Building blocks of CLI knowledge - ManualsEver come across the term RTFM? RTFM stands for Read The Fine Manual. Some also substitute fine for an f type expletive. :) Reading manual pages is the first thing you should do if you are not familiar with a command or a program. Manual pages are very extensive and will sometimes include references so that you can find out more information (to a web page or another document). The Internet is another great place to search for help with learning the command line interface; there are many tutorials on the topic. man is the command that will invoke the manual page for any command or application that has a manual page. Usage: kylie@thinking:~$ man x where x can be any command or application. The worst that man can do is return a message: No manual entry for x To get more information about the man command try typing man man at the prompt. The man pages are also found in the GUI from the KDE Help Centre. Other ways of getting informationThe info command is different to man in that it gives an abbreviated and somewhat confusing list of information about the command or application you are requesting info for. The info command displays a big file as it includes all the info files together. To quit out of an info file, press the q key. Usage: kylie@thinking:~$ info x where x can be any command or application. Help is also another way of getting abbreviated information about a command or application. Help on a command can be accessed by typing --help after a command name in order to retrieve basic information about usage. Usage and example: kylie@thinking:~$ ls --help Read about the more and less commands in the sections below to find out how to prevent information scrolling past your eyes. Special FeaturesTab CompletionTab completion means you can use tab after initially typing the first few letters of a filename, pathname or a command to complete the command, filename or pathname without having to fully type it. For eg. I want to get to a directory that is 3 directories deep. The exact path is ~/classes/basic/commandline/ To get to this directory I can type it out completely or I can use tab to complete directory paths. If there is more than one choice given the letters supplied, tab completion will not work. If this happens you can hit tab again to get a list of options or you can type the next couple of letters of the pathname, filename or command name. Keyboard Up ArrowYou can use the up arrow on the keyboard to recall command line history Commands for working with files and directoriesls --list contents of directoryls can be used with "arguments", for eg: ls -l will list the contents of a directory using a long format. It gives information about your files, including *file permissions, *owner, *group, size, date and time stamp of last revision. Try man ls for more information about the ls command. Usage: kylie@thinking:~$ ls -l [enter] The above returns something like: total 10512
cd --change directoryUsage: kylie@thinking:~$ cd foo [enter] Returns: kylie@thinking:~/foo$ mkdir --makes a directoryUsage: kylie@thinking:~$ mkdir foo Will create a directory named foo. rm --remove The rm command will remove both directories and files dependent on the arguments used. Be very careful when using the rm command. Before using rm please read the man page. Usage: kylie@thinking:~$ rm filename where filename is the file you wish to delete. If you wish to delete a directory that has files in it the command rm will not work on its own, you will need to specify some options. Usage: kylie@thinking:~$ rm -rf directoryname where -rf are the options for the ls command and directoryname is the name of the directory you wish to remove. If a directory is empty and you wish to remove it you can just use the command: rmdir directoryname mv --move a file (this is different to copy a file) Usage: kylie@thinking:~$ mv filename directoryname where directoryname will also include a path to a directory if one is required. cp --copy a file kylie@thinking:~$ cp filename directoryname where directoryname will also include a path to a directory if one is required. If I was in kylie@thinking:~/foo$ and I wanted to a copy a file from my home directory into the directory foo I would have to specify: kylie@thinking:~/foo$ cp /home/kylie/foo.txt . where the . (a dot) means current working directory. Thus the command says copy the file 'foo.txt' into the foo directory. Using Wildcards with filenamesWildcards are represented by an asterix (*). They can be used in place of a letter, or a full word when working with files. If we wanted to delete or remove all files that were jpgs we might use; kylie@thinking:~$ rm *.jpg where the * substitutes for any filename as long as it has the .jpg extension. Or if we wanted to delete all rtf files starting with k we might use: kylie@thinking:~$ rm k*.rtf Other commandscat --concatenate a file Otherwise known as display the contents of a file to the screen. cat works best for text files, source code and config files. When you cat a word processed document or an image you will get a whole lot of gobbledygook on your screen. Try it if you like. Usage: kylie@thinking:~$ cat foo.txt will display the filename foo.txt to the screen. If your file is too big you might need to use another command in order to see the file a screen (or a page) at a time. The command is more, alternatively less does the same thing. When using the more or less command you also need to use a pipe | (the pipe character is the one above the backslash key). Usage: kylie@thinking:~$ cat foo.txt | more |
|
|
Computerbank Victoria Inc., 483 Victoria St, West Melbourne, Victoria, Australia.
© Computerbank Victoria Inc. GNU Free Documentation License - copying and distribution of Computerbank documentation is permitted in any medium, ONLY if this notice is preserved. |