Introduction to Unix CLI: Difference between revisions

From HPC documentation portal
Line 99: Line 99:
-rw-r--r-- 1 lorand hpcadmin  1177 Oct 27 10:10 .bashrc
-rw-r--r-- 1 lorand hpcadmin  1177 Oct 27 10:10 .bashrc
-rw-r--r-- 1 lorand hpcadmin  849 Oct 27 10:10 .vimrc
-rw-r--r-- 1 lorand hpcadmin  849 Oct 27 10:10 .vimrc
</pre>
Filename expansion is also supported with the usage of special characters, so called wildcards "?" or "*". "?" replaces one character, while "*" replaces any number of characters.
<pre>
$ ls -a .*rc
.bashrc  .vimrc
</pre>
</pre>
{{expand}}
{{expand}}

Revision as of 09:46, 27 October 2015

What is Unix CLI?

Unix CLI is actually the shell, a text interface to the operating system. Shell interprets and executes your commands and their arguments by passing them to the operating system.
There are different shell variants, like bash, csh, ksh, sh, tcsh, etc., probably the most popular being bash. The name “bash” is an acronym for “Bourne Again SHell” and is an enhanced replacement for sh. In this short introductory we are going to cover bash.

Bash

Bash is an interactive and scriptable shell. Supports name expansion, wildcards and typing shortcuts.

Note: Interaction with bash is case-sensitive just like everything in Unix system.

Some useful shortcuts:

TAB, UP, DOWN, Ctrl+R, Esc+.

Popular commands

man

man is the system's manual pager. It is an interface to on-line manuals. man has it's own manual pager.

$ # Show default man page for top command
$ man sleep
$ # Show all manual pages for top command, successively
$ man -a sleep

Whenever you are uncertain what a command does, what options and argument can be passed to, man is your friend.

apropos

apropos searches the manual page names and descriptions for the specified keyword.

$ apropos shell
bash                 (1)  - GNU Bourne-Again SHell
bash [sh]            (1)  - GNU Bourne-Again SHell
capsh                (1)  - capability shell wrapper
chroot               (1)  - run command or interactive shell with special root directory
chsh                 (1)  - change your login shell
…

pwd

pwd prints the full name of the current working directory.

$ pwd
/tmp/test/course2015

cd

cd changes the current working directory to the specified directory name. If no directory is specified than cd changes current working directory to users home directory. cd supports relative and absolute paths. Additionally shortcuts like ~ (points to user's home directory).

$ pwd
/tmp/test/course2015
$ cd bin
$ pwd
/tmp/test/course2015/bin
$ cd ../../src
$ pwd
/tmp/test/src
$ cd ~/bin
$ pwd
/home/lorand/bin
$ # Change back to previous directory
$ cd -

mkdir

mkdir command creates directories if they do not exist.

$ mkdir build

To create a whole directory structure, use "-p" option.

$ mkdir -p ~/build/wrf/3.7

ls

ls command lists content of the current or the specified directory. One of the most used options for ls is "-l", which will generate a long list format.

$ ls
GConf                                   libegroupwise-1.2.so.13                     libospf.so.0.0.0
ImageMagick-6.4.3                       libegroupwise-1.2.so.13.0.1                 libossp-uuid.so.16
Mcrt1.o                                 libelf-0.152.so                             libossp-uuid.so.16.0.22
PackageKitDbusTest.py                   libelf.so.0                                 libp11.so.1
…

$ ls -l
total 806992
drwxr-xr-x  3 root root     4096 Mar 11  2012 GConf
drwxr-xr-x  4 root root     4096 Nov 18  2014 ImageMagick-6.4.3
-rw-r--r--  1 root root     1358 Oct  8 20:07 Mcrt1.o
-rw-r--r--  1 root root     3383 May 29  2013 PackageKitDbusTest.py
-rw-r--r--  1 root root     4267 Oct  8 20:07 Scrt1.o
…

"-a" will list all files and folders, even hidden ones.
NB: Files, directories starting with "." character are treated as hidden files.

$ pwd
/work/shared/course2015/intro/bash

$ ls -l
total 0

$ ls -la
total 33
drwxr-xr-x 2 lorand hpcadmin 24576 Oct 27 10:10 .
drwxr-xr-x 3 lorand hpcadmin  4096 Oct 27 10:07 ..
-rw-r--r-- 1 lorand hpcadmin  1177 Oct 27 10:10 .bashrc
-rw-r--r-- 1 lorand hpcadmin   849 Oct 27 10:10 .vimrc

Filename expansion is also supported with the usage of special characters, so called wildcards "?" or "*". "?" replaces one character, while "*" replaces any number of characters.

$ ls -a .*rc
.bashrc  .vimrc

Template:Expand