Shell

From HPC Wiki
Revision as of 15:24, 26 February 2018 by Ds019135 (talk | contribs)
Jump to navigation Jump to search

General

The Shell or commandline is program to interact with a given computer (or supercomputer). Contrary to the graphical user interface most desktop machines use, the shell is very basic and requires the user to have a certain knowledge on what commands there are and how to use them. However, even with a few basic commands, the shell can be a very powerful tool. Combining this power with the fact that the shell itself uses almost uses no resources, is the reason, why it is still in use on (nearly) every (super)computer.

A common shell is the bash (Bourne Again SHell), which comes with nearly every unix-based operating system. Others unix shells include the sh, csh, tcsh, zsh, ksh. All these have very similar commands/syntax, which will be described below.

Windows has the cmd or the PowerShell (ps), which is different syntaxwise and will not be covered here, since most supercomputers run unix systems.


Usage

Enter a command, hit return and read/wait for the answer :-P

Navigating the Unix File System

The following commands tell you, where you are, take you somewhere else and show you what is there:

Linux Command DOS Command Description
pwd cd “Print Working Directory”. Shows the current location in the directory tree.
cd cd, chdir “Change Directory”. When typed all by itself, it returns you to your home directory.
cd directory cd directory Change into the specified directory name. Example: cd /usr/src/linux
cd ~ “~” is an alias for your home directory. It can be used as a shortcut to your “home”, or other directories relative to your home.
cd .. cd.. Move up one directory. For example, if you are in /home/vic and you type “cd ..”, you will end up in /home.
ls dir /w List all files in the current directory, in column format.
ls -l dir List files in “long” format, one file per line. This also shows you additional info about the file, such as ownership, permissions, date, and size.
ls -a dir /a List all files, including “hidden” files. Hidden files are those files that begin with a “.”, e.g. The .bash_history file in your home directory.

Doing Stuff with Files and Directories

The following commands lets you manipulate and interact with files:

Linux Command DOS Command Description
file Find out what kind of file it is. For example, “file /bin/ls” tells us that it is a Linux executable file.
cat type Display the contents of a text file on the screen. For example: cat mp3files.txt would display the file we created in the previous section.
head Display the first few lines of a text file. Example: head /etc/services
tail Display the last few lines of a text file. Example: tail /etc/services
tail -f Display the last few lines of a text file, and then output appended data as the file grows (very useful for following log files!). Example: tail -f /var/log/messages
cp copy Copies a file from one location to another. Example: cp mp3files.txt /tmp (copies the mp3files.txt file to the /tmp directory)
mv rename, ren, move Moves a file to a new location, or renames it. For example: mv mp3files.txt /tmp (copy the file to /tmp, and delete it from the original location)
rm del Delete a file. Example: rm /tmp/mp3files.txt
mkdir md Make Directory. Example: mkdir /tmp/myfiles/
rmdir rd, rmdir Remove Directory. Example: rmdir /tmp/myfiles/


FAQs

A short info with a good basic command reference

A longer linux-shell tutorial