Difference between revisions of "Training/Linux - command line"

From HPC
Jump to: navigation , search
m
m
Line 21: Line 21:
  
 
'''user@viper:~$ man –k syslog'''  (an apropos which shows a list of available man pages with this string contained within it)
 
'''user@viper:~$ man –k syslog'''  (an apropos which shows a list of available man pages with this string contained within it)
 +
 +
== Working with directories ==
 +
 +
As with other operating systems such as Microsoft Windows the filesystem is based around files and directories. Linux is no exception to this and uses a number of commands for the user to navigate around its own filesystem.
 +
 +
This module is a brief overview of the most common commands to work with directories: '''pwd, cd, ls, mkdir''' and '''rmdir'''. These commands are available on any Linux system.
 +
 +
This section will also discuss absolute and relative paths and path completion in the bash shell.
 +
 +
=== pwd ===
 +
 +
On the command line pwd (or print working directory) basically displays the current directory you are in. This would appear as:
 +
 +
'''dbird@viper:~$ pwd'''
 +
 +
/home/dbird
 +
 +
=== cd ===
 +
 +
On the command line cd (or change directory) changes your current directory to the one specified:
 +
 +
'''user@viper:~$ cd /var'''
 +
 +
'''user@viper:~$ pwd'''
 +
 +
/var
 +
'''user@viper:~$ cd /home/user'''
 +
 +
'''user@viper:~$ pwd'''
 +
 +
/home/user
 +
 +
There is also a shortcut back to your home directory by typing the character ~ (tilda) which has the same effect as typing (for example) /home/user.
 +
 +
'''user@viper:~$ cd ~'''
 +
 +
'''user@viper:~$ pwd'''
 +
 +
/home/user
 +
 +
To go to the directory above (or parent directory), we use the characters ..
 +
 +
'''user@viper:~$ pwd'''
 +
 +
/home/user
 +
 +
'''user@viper:~$ cd ..'''
 +
 +
'''user@viper:~$ pwd'''
 +
 +
/home
 +
 +
There is also the character . which means the current directory. This is not useful for the cd command but is very useful for copying files to your current directory.
 +
 +
=== Absolute and relative paths ===
 +
  
  

Revision as of 14:03, 27 February 2017

Introduction

This represents a series of teaching pages to allow you to learn more about Viper's Linux command line interface

Command Line

Like other operating systems Linux does have a window’s type environment too called X and hopefully in the future its successor Wayland. (Linux refers to X and Wayland with the term Display Server). However, with VIPER the vast majority of work will be carried out on the command line.

The command line in Linux is referred to as a shell. The shell is a program that allows the user to interact with Linux at the command line. In true Linux style there are a few different ones to choose from, however the one used predominantly is BASH. The name BASH is an acronym for “Bourne Again SHell”, a reference to BASH is an enhanced replacement for sh, the original Unix shell program written by Steve Bourne.

Man pages

This will explain the use of man pages (also called manual pages) on Linux. Most Linux files and commands have pretty good man pages to explain their use. Type man followed by a command (for which you want help) and start reading. Press q to quit the man page. See below:

user@viper:~$ man whois (shows manual page for the command whois)

user@viper:~$ man syslog.config (shows the manual page for a configuration file)

user@viper:~$ man syslogd (show the manual for a daemon (background program))

user@viper:~$ man –k syslog (an apropos which shows a list of available man pages with this string contained within it)

Working with directories

As with other operating systems such as Microsoft Windows the filesystem is based around files and directories. Linux is no exception to this and uses a number of commands for the user to navigate around its own filesystem.

This module is a brief overview of the most common commands to work with directories: pwd, cd, ls, mkdir and rmdir. These commands are available on any Linux system.

This section will also discuss absolute and relative paths and path completion in the bash shell.

pwd

On the command line pwd (or print working directory) basically displays the current directory you are in. This would appear as:

dbird@viper:~$ pwd

/home/dbird

cd

On the command line cd (or change directory) changes your current directory to the one specified:

user@viper:~$ cd /var

user@viper:~$ pwd

/var user@viper:~$ cd /home/user

user@viper:~$ pwd

/home/user

There is also a shortcut back to your home directory by typing the character ~ (tilda) which has the same effect as typing (for example) /home/user.

user@viper:~$ cd ~

user@viper:~$ pwd

/home/user

To go to the directory above (or parent directory), we use the characters ..

user@viper:~$ pwd

/home/user

user@viper:~$ cd ..

user@viper:~$ pwd

/home

There is also the character . which means the current directory. This is not useful for the cd command but is very useful for copying files to your current directory.

Absolute and relative paths

Further Information