PixiePro: Introduction to Linux

From WikiPixie
Jump to: navigation, search

Understandig the shell

When we talk about the command line on Linux, we're usually talking about the shell. The UNIX shell program interprets user commands, which are either directly entered by the user or read from a script file, There are many shells available for Linux, but the most popular is Bash (Bourne-Again shell) which was written by the GNU Project.

Archlinux ARM for PixiePro uses Bash shell as the main shell program, however if necessary, you can install other shell programs from the Archlinux Official Repositories.

Basic Commands

Once you logged in to the linux console, you are in the home directory of the logged in user. You will see the name of the logged in user followed by the hostname. $ means you are logged in as a regular user, whereas # means you are logged in as root.

File & Directory Commands

List all files and directories of the current directory

You can list all directories and files inside the current directory by using the ls command.

[pixiepro@PixiePro ~]$ ls
Desktop Documents Downloads Music Pictures Public Templates Videos

Moving around directories

To change to any directory, use the cd command

For example: If I want to change directory from /home/pixiepro to 'Downloads' which is inside PixiePro home folder, we run cd and then give the path.

[pixiepro@PixiePro ~]$ cd /home/pixiepro/Downloads/
[pixiepro@PixiePro Downloads]$

Note that in the last line, the 'Downloads' directory has moved inside the square brackets, which denotes that we are inside this directory.

You don't have to give the complete path if you want to move inside the sub-directory of the current directory. Let's say we want to move inside the 'Test' directory within the current 'Downloads' directory. Just type cd and the directory name, in this case it's 'Test', without any slash.

[pixiepro@PixiePro Downloads]$ cd Test

Checking size of files and directories

In order to see the size of directories and files you can use -lh option with the ls command. It will also tell the permissions of the files and directories, their owners and the time/date of modification:

[pixiepro@PixiePro ~]$ ls -lh /home/pixiepro/Downloads/
total 4.0K
drwxr-xr-x 2 pixiepro users 4.0K Mar 26 11:55 Test

Creating files and directories

In order to create new directories, you can use the mkdir command. By default the directory will be created in the current directory. So give the complete path of the location where you want the directory to be created:

mkdir /path-of-the-parent-directory/name-of-the-new-directory

So if I want to create a directory 'Tests' inside the 'Downloads' directory, run the following command:

[pixiepro@PixiePro~]$ mkdir /home/pixiepro/Downloads/Tests

Removing files and directories

If you want to delete any file or directory, use the rm command.

If I want to remove the Test directory, the command would be:

rm -r /home/pixiepro/Downloads/Test

However, if you want to delete all the content of a directory without deleting the directory itself use the '*' wildcard with a slash. For exmaple, if you want to delete all the content of Test directory:

rm /home/pixiepro/Downloads/Test/*

If there are sub-directories inside, you will needto use the '-r' option to also delete the sub-directories:

rm -r /home/pixiepro/Downloads/Test/*

System information Commands

uname -a: The uname command with the -a option prints all system information, including machine name, kernel name & version, and a few other details. Most useful for checking which kernel you're using.

ip addr reports on your system's network interfaces.

top: The top ('table of processes') command displays information on your Linux system, running processes and system resources, including CPU, RAM & swap usage and total number of tasks being run. To exit top, press "q".

free: The free command displays the amount of free and used memory in the system

Checking for man files

Every command and application in Linux will have a man (manual) file, so finding them is as simple as typing "man "command"" to bring up a manual entry for the specified command. For example, "man mv" will bring up the mv (move) manual.

Move up and down the man file with the arrow keys, and quit back to the command prompt with "q".

Editing files with GNU Nano

Nano is a text editor suited to working in UNIX.

  • To edit a file called filename, type in the following command:
    $ nano filename
  • Navigating with nano:
    The usual mouse-based point-and-click method is not supported by nano. Use the arrow keys to move around the page in nano.
    Most nano commands are invoked by holding down the Ctrl key (that is, the control key), and pressing one of the other keys. In this text, the control key is referred to using ^
  • Navigation commands:

^A move to beginning of line
^E move to end of line
^Y move down a page
^V move up a page
^_ move to a specific line (^_^V moves to the top of the file, ^_^Y to the bottom)
^C find out what line the cursor is currently on
^W search for some text.

Additional Information

For more detailed tutorials on the Linux command line, please see:

  1. grep HowTo - grep is a powerful command line search tool
  1. find HowTo - locate files on the command line
  1. creating users HowTo- Create users in Archlinux
  1. http://linuxtutorial.todolistme.net - A beginners guide to effective use of the command line.
  1. http://www.ss64.com/bash/ - A good list a commands.