Difference between revisions of "Training/Linux - command line"
m |
m |
||
Line 133: | Line 133: | ||
This command lists the contents of a directory: | This command lists the contents of a directory: | ||
− | + | <pre style="background-color: black; color: white; border: 2px solid black; font-family: monospace, sans-serif;"> | |
− | + | user@viper:~$ ls | |
+ | myfile1.txt myfile2.txt mydirectory1 | ||
+ | |||
+ | </pre> | ||
'''ls''' has a number of useful different options | '''ls''' has a number of useful different options | ||
− | + | <pre style="background-color: black; color: white; border: 2px solid black; font-family: monospace, sans-serif;"> | |
− | + | ||
− | + | user@viper:~$ ls –l (show a long listing with more information) | |
+ | user@viper:~$ ls –a (show all files including those that are hidden) | ||
+ | user@viper:~$ ls –la (combines both of the options above) | ||
+ | |||
+ | </pre> | ||
=== mkdir === | === mkdir === | ||
Line 147: | Line 154: | ||
This commands makes a directory from the specified directory: | This commands makes a directory from the specified directory: | ||
− | + | <pre style="background-color: black; color: white; border: 2px solid black; font-family: monospace, sans-serif;"> | |
− | + | ||
− | + | user@viper:~$ mkdir mydirectory1 | |
+ | user@viper:~$ cd mydirectory1 | ||
+ | user@viper:~$ pwd | ||
/home/user/mydirectory1 | /home/user/mydirectory1 | ||
+ | |||
+ | </pre> | ||
Revision as of 14:24, 27 February 2017
Contents
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
Although an important concept to understand the rule here is very simple. When you type a path starting with a slash (/), then the root of the file tree is assumed. If you don't start your path with a slash, then the current directory is the assumed starting point.
Here are two examples, firstly of absolute path
user@viper:~$ pwd /home/user user@viper:~$ cd /var user@viper:~$ pwd /var
And relative path
user@viper:~$ pwd /home/user user@viper:~$ cd myfiles user@viper:~$ pwd /home/user/myfiles
The command line will help you in typing a path without errors. If you type a partial command such as:
user@viper:~$ cd /home/user/my
Pressing the TAB key will fill in the rest of the directory name, if that directory exists and it is unique). So the following would appear
user@viper:~$ cd /home/user/myfiles
ls
This command lists the contents of a directory:
user@viper:~$ ls myfile1.txt myfile2.txt mydirectory1
ls has a number of useful different options
user@viper:~$ ls –l (show a long listing with more information) user@viper:~$ ls –a (show all files including those that are hidden) user@viper:~$ ls –la (combines both of the options above)
mkdir
This commands makes a directory from the specified directory:
user@viper:~$ mkdir mydirectory1 user@viper:~$ cd mydirectory1 user@viper:~$ pwd /home/user/mydirectory1