1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Welcome to iHelpForum - the place to get help from knowledgeable techs in all areas of Tech, Home and Auto help. Consider checking out our Guides or Registering an account to post on our forums today.

    Dismiss Notice

A beginners guide to the Linux Command Line.

A beginners guide to the basic Commands used in Linux..

  1. apemax
    Operating System:
    Linux
    When it comes to using Linux one of the most useful things you can know is how to use the Command Line. In this guide I will be showing you how to use the Command Line and showing you some of the basic commands.

    First you're going to need to start a Terminal, just as you would use a Command Prompt or Dos Prompt in a Windows OS. This can be done by starting the program called "Terminal" or "Terminal Emulator", It most commonly has a icon with ">_" in it. Once you have started it you should then have a window that looks similar to this:

    iHF-LCLG-IMG-1.png

    The actual usage of the Command Line is fairly basic, You type in the command you want to execute and hit enter. Knowing all of the commands you can use and how to use them is the slightly more complex part.

    In the above image you can see a empty Terminal window with a command prompt. (Where you type in you commands.) "apemax" is the name of the user your currently logged into and "apes-pc" is the name of your computer. Obviously those will be different on your PC.. The tilde "~" represents your home directory, The directory you always start in when you open a Terminal.

    It is possible to access a history of all previously executed commands, To do this press the Up arrow key, You can then cycle through all of the previously executed commands. When you find the command you want to execute again simply hit the enter key.

    Now that you have your terminal window open one of the first things you should know is how to navigate the file system. One of the first commands you should know about is ls. Executing the ls command will list all files and directories in the current directory your in. To run the ls command simply type:

    Code:
    ls
    And hit enter. It should then output a list of all files and directories in you current directory. Now you're going to need to know how to move around the filesystem, This is where the cd command comes in. With the cd command you can change your current directory to any other directory on your system. So if you have a directory called "stuff" in your home directory you would type in:

    Code:
    cd stuff
    And hit enter. That would then become your current active directory. If you run ls now you will see it will output all files and directories in the "stuff" directory. If you want to change to a directory with a space in the name like:

    Code:
    ~/directory space
    Then put a * where the spaces are so it would look something like this:

    Code:
    cd ~/directory*space
    Hit enter and you'll change to that directory.

    If you want to go back one directory (Aka, in this example, go back to your home directory) you can type in this:

    Code:
    cd ..
    And hit enter. A quick way of getting back to your home directory is by typing:

    Code:
    cd ~
    And hitting enter. Because the ~ symbol represents your home directory you can "cd" to it and it will take you to your home directory. If you want to know where you are in the file system you can use the pwd command, Simply type it in:

    Code:
    pwd
    And hit enter. It will output the full path to the directory you're in.

    Now that you know how navigate your file system you'll probably want to know how to change things, create/delete files and directories for example. To create a directory we will use the mkdir command. Usage is fairly simple, Just type in:

    Code:
    mkdir stuff2
    And hit enter. This will create a directory called "stuff2" in your current directory. To create a empty plain text file you can use the touch command. Simply type:

    Code:
    touch text1.txt
    into the terminal and hit enter. You will then have a empty text file called "text1.txt". To edit text files you can use the nano command. nano is a text editor you can use in the command line to create and edit text files without having to open the file within a GUI text editor. To start it simply type in:

    Code:
    nano
    And hit enter. You should then see something like this:

    iHF-LCLG-IMG-2.png

    Note: If you want to open an already existing file type the command nano followed by the name of the file you want to open. So to open the file "file.txt" in nano you would type the following and hit enter:

    Code:
    nano file.txt
    It works fairly similar to any other text editor although there are a few differences. Typing in it is mostly the same, Simply type in what you want to put into the text file as you would in a normal text editor.

    To save the text file press and hold down the Ctrl key and then press the O key. You will then be asked to type in a name for the text file. Type in what you want to call the text file and then hit the Enter key.

    Finally to close nano simply hold down the Ctrl key and press the X key.

    To delete files and directories you can use the rm command. To delete a directory type in:

    Code:
    rm stuff2
    And hit enter, that will delete the directory called "stuff2". Same goes for if you want to delete a file, In this case the file "text1.txt". Type in:

    Code:
    rm text1.txt
    And hit enter. Remember: Always be careful when using the rm command, Make sure you have typed in the name of the file or directory you want to delete correctly. To copy files we can use the cp command, So to copy a file called "text2.txt" into the directory "stuff3" that is located in your home directory you would type in:

    Code:
    cp text3.txt ~/stuff3
    And hit enter. You will then find a copy of the file "text2.txt" in the directory "stuff3". To copy a directory and it's contents you will need to add the -r command line argument. So for example to copy the directory "stuff1" and it's contents into the directory "stuff2" that is located in your home directory you would type in:

    Code:
    cp -r stuff1 ~/stuff2
    And hit enter, you will then find a copy of "stuff1" in the "stuff2" directory.

    You should now know the basics of how to use the command line on Linux.
    Lord Chance likes this.

Recent Reviews

  1. Lord Chance
    Lord Chance
    5/5,
    For someone new to Linux, the information presented in this Guide is well written and informative. Hopefully we will see more from the Author.