0% found this document useful (0 votes)
21 views4 pages

Linux Basic For Iridis

Linux basic knowledges for new users using Iridis HPC of the University of Southampton

Uploaded by

王嘉程
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views4 pages

Linux Basic For Iridis

Linux basic knowledges for new users using Iridis HPC of the University of Southampton

Uploaded by

王嘉程
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Getting Started with Linux

Navigating the Linux Filesystem Comman Command Description


Description
d
the program that converts plain
The Linux filesystem is a tree-like hierarchy of
List contents of directories in a tree- dos2unix text files in DOS/MAC format to
directories and files. tree
like format UNIX format
 When you first login to a Linux machine, you
find yourself in your home directory.
 A path is a way you need to follow in the tree
structure to reach a given file. An absolute Working with Files and Directories Getting Help
path name is one beginning with the “/” Help on most Linux commands is build into
Command Description 1.
character. A relative path is a path relative to the commands themselves:
your working directory mkdir Make directory
$ ls --help
rmdir Remove an empty directory
Comman 2. The best source of information for most
Description cp source Copy a file
d commands is the online manual pages, known
dest as “man pages” for short:
“Print Working Directory”. Shows the Copy a file, preserving its
pwd cp –p … attributes like mode, $ man ls
current location in the directory tree
ownership, timestamps
Change the current directory to dir  To search for a particular word within a man
cd dir mv source Move a file to a new location or page, type “/word”. To quite from a man page
Ex: cd /user/src/redhat just type the “q” key.
dest rename it.
cd .. Move one directory up 3. Sometimes you might not remember the name
rm Delete a file of Linux command and you need to search for
cd – Return to previous directory
rm –r Remove directories and their it. For example, if you want to know how to
cd Return to your home directory contents recursively change a file’s permissions, you can search
the man page descriptions for the word
ls List all files in the current directory “permission” like this:
Display the contents of a file on
cat
List files in “long format”, one file the screen $ man –k permission
per line. This also shows you
ls -l additional info about the file, such head Display the fist/last few lines of In the output you will find a line that looks
as ownership, permissions, tail a file like:
modification date and size chmod (1) – change file access
file Find out what kind of file it is
ls -a List files which are normally hidden permissions
Display a file or program output
Sort files by modification time and more  The number in the brackets corresponds to
one screen at a time.
list in reversed order using “long manual categories: 1=“General Commands”,
ls -ltr format”. In this way recently More sophisticated version of 2=”System Calls”, the rest you may never
modified files will be at the bottom less more (can scroll backwards and need).
of the list. has many more options) Now you know that “chmod” is the command you
were looking for!

1 HPC support team


iSolutions
Revision date: 12/12/2018
Getting Started with Linux
Basic Keyboard Shortcuts • Ctrl-x - exits the editor. If you are in the Advanced editors
middle of editing a file, Nano will ask you if
• TAB button is used to complete you want to save your work Emacs
commands and filenames
• Ctrl-o – Outputs to fine. Nanos version of save Emacs is a more advanced editor that also adds
• Ctrl-c breaks/cancels an ongoing features such as syntax highlighting. To start
• Ctrl-r - Read a file into your current working
operation emacs:
file. This enables you to add text from another
• Ctrl-z pauses (stops) an ongoing file; $ emacs filename
operation. Type “fg” (foreground) to
• Ctrl-w - Search your text If you have x-forwarding, this command displays a
resume it or “bg” (background) to new window in which you can view and edit the
continue the process in the background • Ctrl-g Get help with Nano
contents of filename. In this way you can use
• Ctrl-d exit a terminal, same as typing original window for commands, e.g. compilation.
“exit” You can still use Emacs without x-forwarding but
it will take over your whole terminal. To get out of
• Up/Down arrow keys to scroll through Emacs either close the window or press,
your most recent commands. You can
scroll back to an old command hit Enter Ctrl–x then Ctrl–c
and execute the command without having Emacs editor home page:
to re-type it. http://www.gnu.org/software/emacs/
Creating and editing files Vim

Linux comes with several editors. We show just Almost all flavours of Linux comes with Vim or at
two examples. least the original simpler version called Vi. Vim
has existed since 1991 and is version powerful
Nano but it has a version steep learning curve. A file
Nano uses very simple key combinations in order can be opened in vim with:
to work with files. A file is either opened or $ vim filename
started with the command: Nano editor home Page:
The file will open in command mode, to input test
$ nano filename http://www.nano-editor.org/
the user needs to enter insert mode by pressing
where filename is the name of the file you want to Gedit “I”. To exit insert mode and return to command
open. mode, press Esc. To save and close, switch to
If X-forwarding is enabled, then users can open
command mode and press “:x”. To close without
When you have the file open in Nano you will Gedit which is very similar to Microsoft’s Notepad.
saving, switch to command mode and press “:q!”
notice at the bottom of the terminal window a Windows users will find the shortcut commands
short list of command key-combinations. The very familiar but just as with Notepad and even Vim editor home page: https://www.vim.org/
carot symbol (^) means to hold <Ctrl> key. So, Nano, Gedit has a very limited functionality.
when you see ^X, that just means “hold the Ctrl
key down and click x”. All key combinations for
Nano start with the <Ctrl> key:

2 HPC support team


iSolutions
Revision date: 12/12/2018
Getting Started with Linux
Informational commands command is typically very long, we pipe the Finding things
output to “less” command, which displays the
Command Description output one screen at a time. Command Description
ps List currently running processes Redirecting Input and Output Search for a pattern in a file:
Report filesystem disk space Standard Output $ grep <pattern> filename
df usage grep
There are times when it is useful to save the For example, to find all referances
df –h Print sizes in “human-readable” output of a command to a file instead of to “data” in file “output”:
format displaying it to the screen. For example, if we $ grep –e data output
Disk usage in a particular want to create a file with a list of all txt files in a
directory, we can use redirection character “>”: Primarily used to selected a given
du directory
awk column from an output, e.g.
du -h Print sizes in “human-readable” $ ls –l ~/*.txt > my_txt_files
$ awk ‘{print $2}’
format To append the standard output to an existing file:
Shows the full path to a command
Display CPU processes in a full- $ ls –l ~/*.txt >> my_txt_files which
or executable
screen GUI. A great way to see
top Standard Input
the activity on your computer in Locate the program, source code
real time. Type “q” to quit. Many commands accept input from standard whereis and manual page for a command (if
input, or stdin for short. By default, standard available)
Display amount of free and
free input reads information from your keyboard, but
used memory in the system Show your complete command
just like standard output, it can be redirected: history
history
Print system information
uname -a (Kernel version, machine type $ cat < some_input_file A very powerful command, but
etc) Standard Error sometimes tricky to use. It can be
used to search for files by size,
Show who is logged on and This is where error output from your program
w modification times as well as many
what they are doing goes. This normally points at your terminal as other types of searches. A simple
well, but you can redirect it: example is:
$ cat non_existing_file 2> errors.txt $ find . –name *data*
Piping Command Together
When using cluster, batch control systems like find
This example searches in the
The pipe character “|” is used to chain two or PBS manage Standard Output and Error current directory “.” and all
more command together. The output of the first redirection, so you do not need to worry about it. subdirectories, looking for files
command is “piped” into the next program, and if with “data” in their names.
Redirect both
there is a second pipe, the output is send to the
third program, etc. For example: On ocantion it might be useful to be able to $ find . –size +500M
collate both stdout and stderr into a file. This can That would find files that are larger
$ ls –la /usr/bin | less
be done with: then 500 MB
In this example we create a list of all files in
Command > filename 2>&1
/usr/bin directory. Because the output of this
3 HPC support team
iSolutions
Revision date: 12/12/2018
Getting Started with Linux
Special Characters Char Description To see all environment variables:
Command separator as above, but only $ printenv
Char Description && runs the second command if the first one
To set an environment variable:
Directory separator, used to separate a finished without errors.
/ string of directory names. Execute a command in the background, $ export SVN_EDITOR=nano
Ex: /bin/ls & and immediately get your shell back.
Ex: find -name my* > find.results & Further reading
Escape character. If you want to reference
a special character, you must “escape” it Useful Lynda courses on Linux
\ https://www.lynda.com/search?q=linux
with a backslash first. Other Utilities
Ex: touch name\ with\ space
Command Description Emacs Tutorial
Current directory. Can also “hide” files http://ergoemacs.org/emacs/emacs.html
.
when it is the first character in a filename. clear Clear the screen
.. Parent directory Display test on the screen. Useful Interactive guide on VIM
when writing shell scripts. https://www.openvim.com/
~ Home directory echo
$echo “Step 1:start execution” Iridis 4 - Wiki
Represents 0 or more characters in a
* filename, or by itself, all files in a sort Sort a file or program output https://hpcdocs.soton.ac.uk/redmine/projects/iri
directory. dis-4-support/wiki
date Display the current date and time
Represents a single character in a Iridis 4 - Forum
? Runs the command and gives
filename. https://hpcdocs.soton.ac.uk/redmine/projects/iri
time resource usage:
“Pipe”. Redirect the output of one dis-4-support/boards
$ time ls
| command into another command.
Ex: ls | less Iridis 5 - Wiki
https://hpcdocs.soton.ac.uk/redmine/projects/iri
Redirect output of a command into a new Environment Variables dis-5-support/boards
> file. If the file already exists, over-write it.
Ex: ls > myfiles.txt All the programs that run under Linux are called Iridis 5 - Forum
processes. When you start a program a new https://hpcdocs.soton.ac.uk/redmine/projects/iri
Redirect the output of a command onto
process is created. This process runs within what dis-5-support/wiki
>> the end of an existing file.
Ex: echo “all files” >> myfiles.txt is called an environment. It looks “in the
environment” for particular variables and if they Contact Us
< Redirect a file as input to a program. are found will use the values stored. By
Ex: more < myfiles.txt convention, environment variables have UPPER Email [email protected] if you have any question
Command separator. Allows you to CASE names. An example of an environment regarding this document.
; execute multiple commands on a single variable is:
line.
$ echo $USER
Ex: cd ~; less myfiles.txt

4 HPC support team


iSolutions
Revision date: 12/12/2018

You might also like