Linux Environment
Linux Environment
Table of Contents
1. Introduction to Linux ................................................................................................................................................ 4
3.4 Cutting............................................................................................................................................................. 28
5. Searching................................................................................................................................................................. 38
6. Further Reading....................................................................................................................................................... 45
7. References ............................................................................................................................................................... 45
Figure 1 The Linux operating system provides an interface for users to access the hardware.
Linux is an operating system like Microsoft Windows or Apple macOS (formerly known as OSX). Imagine we have
connected the hardware components of a computer, e.g., the CPU, hard disks, the keyboard, etc. How can we
coordinate the operations of these components to perform the tasks like copying a file? This is the role of an operating
system.
It provides an interface for us to use the hardware components. Most operating systems also come with tools for many
common tasks, like text editing or web browsing.
In this course, we are using Ubuntu. However, there are many different distributions of Linux. They deviate from
each other mainly on the interfaces and tools provided.
You are welcome to use other distribution like Fedora 19 or Debian (http://www.debian.org/). For this course, these
distributions will not make a difference.
Windows and macOS (OSX) are probably more commonly known than Linux by the public. However, Linux is an
important operating system for some reasons.
1. Linux is open-source software. Hence, we can customize it for new or special hardware systems. Hence, Linux is
particularly popular for supercomputers. It also provides a higher level of security because a company can inspect
its source code.
3. Linux itself and most software provided for Linux can be used without paying a fee. Hence, it can be used to
produce low price products like netbooks and mobile phones. For example, the Android operating system is
developed based on Linux.
If you are NOT in CS network, please firstly connect to “gatekeeper.cs.hku.hk” in your SSH client and enter
ssh academy11.cs.hku.hk
The following procedures are based on using PuTTY, but you are welcome to use other SSH clients. For example, you
can use Command Prompt or PowerShell in Windows 10 or Terminal in macOS.
2. After install, Search “PuTTY” in the start menu and launch it.
3. In Host Name, type “academy11.cs.hku.hk”. Then click “Open”
6. Done! Try entering the first Linux command ls, what can you see?
The shell accepts commands and performs specific tasks. For example, to check current datetime, you need to type the
date command as follow:
$ date
Fri Jul 27 15:58:42 HKT 2018
*Note that the $ sign indicates the command line in the shell, you do not need to type it.
All data in Linux is organized into files, and all files are organized into directories (known as folders). The filesystem
in Linux is a tree structure that organized by these directories.
The ls command is to list out all the files and directories in your current directory.
$ ls
Documents/ logon.bat* public_html/ t.txt Downloads/
Pictures/ Templates/ Videos/ Desktop/ engg1340/
Music/ Public/ test.txt
The cd command is to navigate your current directory to another. E.g., To access the directory “engg1340” and then
list out all the files and directories.
$ cd engg1340
$ ls
lab1/ lab2/ lab3/
To navigate to the parent directory, type “cd ..”.
There are many commands supported by the shell. Therefore, it is impossible to remember all the Linux commands.
Here is the command that helps you to get the detail of a command – man
Suppose we want to use the man command to know more about the ls command.
$ man ls
LS(1) User Commands LS(1)
NAME
ls - list directory contents
SYNOPSIS
ls [OPTION]... [FILE]...
DESCRIPTION
List information about the FILEs (the current directory by default).
Sort entries alphabetically if none of -cftuvSUX nor --sort is speci‐
fied.
Mandatory arguments to long options are mandatory for short options
too.
-a, --all
do not ignore entries starting with .
-A, --almost-all
do not list implied . and ..
--author
Manual page ls(1) line 1/234 8% (press h for help or q to quit)
*Press arrow keys (↑, ↓) to scroll the manual page.
*Press ‘Q’ to close the manual page.
From the NAME section, we learn that the function of the ls command is to “list directory contents”.
From the DESCRIPTION section, we learn that the option “-l” is to “use a long listing format”. Long listing means
that we also list the file size, owners, last modification date, etc. We will learn more about the long list format in the
next section of this document.
Try the command ls, it will display the current directory content.
$ ls
How about display the “long listing format” of the current directory content?
$ ls -l
All files and directories can be specified using a unique path. There are two options: full path and relative path:
Full path always starts with a “/” and concatenate all directory names from the root to the specific files. As an
example, in Figure 4:
• /home/file3 is the full path for file3 under the /home directory.
• /home/kit/Desktop/file4 is the full path for file4.
Relative path is relative to the present working directory.
• If the present working directory is /home/kit, we can refer to the file4 under Desktop using the following
relative path:
Desktop/file4
If a directory A contains another directory B, then A is called the parent directory of B, and B is called a subdirectory
of A. For example, kit is a subdirectory of home and home is the parent directory of kit.
Once the shell starts, its present working directory is the home directory. We can always get the present working
directory by the command pwd.
Linux Environment Module 1 p. 11/47
2.1.1 Home Directory
For any user, there is a home directory for that user. For example, the user kit will have a home directory at /home/kit.
Here “~” denote the home directory of a user. You can go to your home directory using:
$ cd ~
If you want to create more than one directory, give them on the command line:
$ mkdir lab1 lab2
Naming a directory with space character can be done by using double quotation mark ("").
$ mkdir "lab 1"
For a non-empty directory, we can use the rm -rf or rm -r -f command to delete the entire directory
$ ls lab1
file1.txt file2.txt
$ rm -r -f lab1
$ ls lab1
ls: cannot access 'lab1': No such file or directory
• The -r flag defines recursively travel down any subdirectory and remove all files and directories.
• The -f makes sure you are not prompted for confirmation (handy if there are lots of files and directories
inside the target directory)
The mv (move) command can rename a directory. For example, rename directory lab to lab 1:
$ mv lab "lab 1"
*The 1st and 2nd arguments are directories
Below shows a list of useful commands for directory manipulation. Some commands can be invoked with different
flags or arguments. We list those variations in the table as well.
Command Meaning
pwd It prints the name of the present working directory.
ls It lists the content in the present working directory.
• ls -l – It lists the content in long format, which contains the file size, owners, last
modification date, etc.
• ls -a – It lists all content including hidden files or hidden directories. Notice that a file or
directory is hidden if its name starts with a dot.
– It has both the effect of -l and -a
• ls -la
cd dir It changes the current directory to dir.
• cd ~ – Changes to the home directory.
• cd .. – Changes to the parent directory.
• cd . – Changes to the current directory. Hence, this command is valid yet has no effect
actually.
mkdir dir It creates a new directory with name dir.
rmdir dir It removes the directory dir. This only works if dir is empty.
rm -rf dir It removes the non-empty directory dir and all the subdirectories / files.
mv dir dir2 It renames the directory from dir to dir2.
Note that “-l” and “-a” are called flags to the command, which changes the behavior of the command. On the other
hand, dir is called an argument of the command, which specifies the target of the command.
If the files have the same prefixes, you can specify all of them at once using the asterisk symbol (*).
Below shows a list of useful commands for file management. Some commands can be invoked with different flags or
arguments. We list those variations in the table as well.
Command Meaning
cp file1 file2 Copy file1 into file2.
cp -r dir1 dir2 Copy dir1 into dir2 including sub-directories
mv file dir If dir is a directory, it moves the file into dir.
mv file1 file2 If the two arguments are the same type (e.g., both file1 and file2 are files, it
mv dir1 dir2 renames file1 to file2. (The same for directories)
rm file Remove file.
rm -rf dir Remove recursively all files and directories in dir
touch file Create an empty file named file.
cat file Display the content of file.
In this section, we will discuss the use of vi editor on creating and editing files. vi is a command line text editor (like
Notepad on Windows, or gedit on Linux). However, it does not come with a GUI (Graphical User-interface).
Use vi on a file
Type vi filename to open a file. If the file does not exist, the editor will create a new one for you.
$ vi file2.txt
If the file exists, the content of the file will be displayed. Here, files2.txt does not exist, so an empty file is created and
displayed. When the vi editor is first launched, you are in Command mode.
Press ‘ESC’ to enter command mode. In command mode, you don’t see ‘INSERT’ in the bottom left corner.
Then enter the command “:wq”, you can see the cursor will move to the bottom.
After pressing ‘ENTER’, the files will be saved, and you will exit from vi.
Commands
Other than the “save and exit” (:wq) command, you can just save the file without terminating the vi by using the “:w”
command. To continue editing, press “Esc” and then press ‘I’ to enter Insert mode.
Below are some of the useful commands you can use in the command mode.
:wq Save and Quit
:w Save
:w filename Save to new file named filename
:q Quit
:q! Quit without saving file
https://www.cs.colostate.edu/helpdocs/vi.html
The following procedures are based on using WinSCP, but you are welcome to use other SCP/SFTP clients. For
example, you may download and use FileZilla in macOS, but you need to set up HKU VPN first.
3. [Tunneling, required if you are NOT in CS network and your client support it, otherwise skip this step]
Click “Advance..” > Open tap “Tunnel”, then configure as follow and click “ok”
• Check “Connect through SSH tunnel”
• Host name: gatekeeper.cs.hku.hk
• User name: [your_CS_account]
• Password: [your_CS_account_password]
• Read: Give you the permission to open and read a file. Read permission on a directory gives you the ability to
list its content.
• Write: Give you the permission to modify the content of a file. Write permission on a directory gives you the
ability to add, remove and rename files.
• Execute: Give you the permission to run a program.
Use ls -l command to list the directory. It provides different information about file permission.
$ ls -l
total 10
-rw------- 1 cklai ra 50 Jul 30 17:07 file1.txt
-rw------- 1 cklai ra 48 Jul 31 15:14 file2.txt
drwx------ 2 cklai ra 2 Jul 30 17:00 lab/
If we go through the output of the first two lines, we can break down the information ls -l gives us.
Explanations
Field Description
total 10 How much space the files have taken up in the directory, in kilobytes.
-rw------- Important!! This is the permission indicators of the file; we will discuss the meaning of it in
more detail later.
1 This is the number of hard links the file has.
cklai The owner of the file.
ra The default group that cklai belongs to (The group is called ra).
50 This is the file size in bytes.
Jul 23 17:07 Last modification time.
file1.txt The file name.
Parts Explanations
If it is a dash “-“, that means it is a normal file.
Type If it is a “d”, it means it is a directory.
There are other possible values in this field; please refer to the references for more information.
The next 3 bits represent the permission for the owner of the file.
If the permission is “rw-“, the owner can:
User • Read the file (r),
permissions • Write into the file (w)
• But not execute the file (this file is just a text file, not supposed to be executed). If the file can
be executed, then the dash will be replaced by the letter “x”.
Group The next three bits are the permission for the group you belongs to. A group can consist of other
permission members.
The last three bits (---) are the permissions for anybody else.
Other
It is now “---", which means everybody cannot read the file, write content into the file (no w),
permission
nor execute the file (no x).
You can change the permission of the files or directories you own.
Use the command chmod to change the permission. It has the following format:
chmod [who][operator][permissions] filename
Field who indicates whether we are altering the permission for user, group, other or all user.
Values Meaning
u The user (owner) permissions
g The group permissions
o The other permissions
a ALL (including user, group and other)
Example
Use touch to create a new file, the default permission for a user is “read and write only” as the permission indicators
for the user are “rw-”. Use chmod to grant the write permission to others so that everyone can modify the file.
$ touch file
$ ls -l
total 26
-rw------- 1 cklai ra 0 Aug 1 11:48 file
$ chmod o+w file
$ ls -l
total 26
-rw-----w- 1 cklai ra 0 Aug 1 11:48 file
Where “chmod o+w file” means to add (+) the write (w) permission to other (o).
For example, grant the Read (r) and Execute(x) permissions for the other (o).
$ ls -l
-rw-----w- 1 cklai ra 0 Aug 1 11:48 file
$ chmod o+rx file
$ ls -l
-rw----rwx 1 cklai ra 0 Aug 1 11:48 file*
If a file is marked with (*) at the end of its name, it means the file is executable.
4 Chicken 50 4 Chicken 50
3.3 Sorting
Use sort command to sort a file. Without any options, it sort in alphabetical order.
$ sort example1.txt
1 Coke 5.5
10 Jelly 5
2 Milk 8
3 Chocolate 15
4 Chicken 50
5 Apple 3.5
Note: The first column in the result is “1 Coke 5.5” but not “10 Jelly 5”. It is because the sorting is in alphabetical
order by default. However, other versions of Linux may have a different implementation, making “10 Jelly 5” before
“1 Coke 5.5”.
Use the flag -k for sorting on specific sort key field. (Note that the field ID starts from 1 but not 0)
Use the flag -t for specifying the field separator if the fields are not separated by space (space is the default
delimiter for sort).
For example, if the fields are separated by commas (,) and we want to sort by the 3rd column, we need to specify the
field separator “-t,”.
$ cat example1_comma.txt
5,Apple,3.5
4,Chicken,50
1,Coke,5.5
10,Jelly,5
3,Chocolate,15
2,Milk,8
$ sort -t, -k3 -n example1_comma.txt
5,Apple,3.5
10,Jelly,5
1,Coke,5.5
2,Milk,8
3,Chocolate,15
4,Chicken,50
3.4 Cutting
The command cut returns the specific column of data.
We need to specify the delimiter (even it is a space), the flag for specifying delimiter is -d. (Do not mix up with the
field separator of the command sort).
Use the flag -f to specify which column(s) to return. Note that the column ID starts from 1 but not 0.
For example, returns the 1st and the 3rd columns from the file example1.txt. 5 Apple 3.5
$ cut -d ' ' -f 1,3 example1.txt
4 Chicken 50
5 3.5
1 Coke 5.5
4 50
10 Jelly 5
1 5.5
3 Chocolate 15
10 5
2 Milk 8
3 15
2 8
example1.txt
Linux Environment Module 1 p. 28/47
3.5 Remove adjacent duplicate lines
The uniq command removes the adjacent duplicate lines so that only one of the duplicated lines remains. Note that it
only removes adjacent duplicates.
example2.txt
3.6 Check Spelling
The spell command displays all incorrect words in file.
$ spell example3.txt It's a beautiffful day!
beautiffful I am so happpy todday.
happpy
todday
example3.txt
Note: If your Linux does not have the command spell, please install it by:
aaa eee
bbb aaa
ccc ddd
fileA.txt fileB.txt
Explanations
0a1 – To add a line after line 0 of fileA, the line to be added is line 1 of fileB (denoted by > eee). (Figure 5)
Figure 5
2,3c3 – To change line 2,3 of fileA to line 3 of fileB. The lines to be deleted are bbb and ccc (denoted by < bbb and
< ccc); the line to inserted is ddd (denoted by > ddd). (Figure 6)
Figure 6
Explanations
1d0 – To delete line 1 from fileB, and the files will then be in sync starting at line 0. The line to be deleted is eee
(denoted by < eee). (See Figure 7)
Figure 7
3c2,3 –To change line 3 of fileB to line 2,3 of fileA. The line to be deleted is ddd (denoted by < ddd); the lines to
inserted are bbb and ccc (denoted by > bbb and > ccc). (See Figure 8)
Figure 8
When using commands in the shell, the shell associates each process with some open files, and references these open
files by using numbers called file descriptors.
Usually, when we execute a command, the output is printed to the screen. We can redirect the output to a file using the
file redirection operator >.
For example, the following command stores the content of the directory into a file files.txt.
$ ls -l 1> files.txt
Or short form
$ ls -l > files.txt
The result of the above command is not displayed on the screen but redirected to the file files.txt instead. This is a very
useful technique to create files storing the output of shell commands.
*If the above command is executed more than once, the system may say “cannot overwrite existing file”. To cope
with this issue, you may manually remove the existing file first or use >| to force the file to be written.
$ ls -l >| files.txt
Below shows the meaning of the redirection operators >, >>, < and <<.
Command Explanations
command 1> file or Send standard output to file.
command > file
command 1>> file or Append standard output to file.
command >> file
command 2> file Send standard error to file.
command 2>> file Append standard error to file.
command gets its input from fileA and sends
command < fileA > fileB 2>fileC
output to fileB, error to fileC.
Redirect the output of the directory listing into the files result.txt
$ ls -l 1> result.txt
Or short form
$ ls -l > result.txt
Redirect the standard error to the same location as where we redirect the standard output (2>&1).
$ cp file123 fileabc 1> result.txt 2>&1
The operator >> is the same as > except it appends the content to a file instead of replacing the content of the.
$ wc data.txt >> result.txt
If you look at result.txt, the content of wc data.txt should be appended at the end of result.txt.
Sometimes a command may return an error message. For example, if you grep a file that does not exist, then the grep
command returns error message.
Note that the error messages are stored in the standard error file (the file with file descriptor 2)
Example
Suppose that the file file123 does not exist, if we just execute the command without file redirection, the standard error
will be displayed on the screen.
$ grep 'abc' file123
grep: file123: No such file or directory
If we use file redirection for the standard error file (File descriptor: 2), the error will not be display on the screen.
Here, the error will be redirected to a file named error.txt (Figure 9).
$ grep 'abc' file123 2> error.txt
Similarly, if we have a program or command that accepts user inputs, we can redirect the file as input to the program
or command by the redirection operator <.
Assume we have a C++ program named add.cpp. This program accepts two integer inputs and then output the sum.
//add.cpp
#include <iostream>
int main() {
int a;
int b;
std::cin >> a;
std::cin >> b;
std::cout << a + b;
}
Run add, then type in 2 integer values in the console. It will print the result (e.g. 3 + 4 = 7).
$ ./add
3 4
7
File redirection: Alternatively, we can run add with input from a file.
Use the redirection operator < to redirect the content of input.txt (Figure 10) into the add program
$ ./add < input.txt
3 4
7
Figure 10 input.txt
Redirect the input input.txt (Figure 10) to the program add and redirect the program output to ouput.txt (Figure 11).
$ ./add < input.txt > output.txt
For example, to find all files created on Jan 26, we can use a temporary file to store the result of the ls command.
Then, we can grep those lines containing the pattern “Jan 26”, as follows.
$ ls -l > files.txt
$ grep "Jan 26" < files.txt
However, the method above is not good enough. It is because it creates an intermediate file files.txt. Note that files.txt
could be very large if there are many directories and files under the current directory, but the result of grep could be
just a few files or directories.
There is a more convenient way by using a pipe (i.e., the “|” symbol), which redirects the output of one program
directly into the input of another program. (No intermediate files needed)
In the above command, the “|” symbol means pipe, which redirects the output of the command ls -l directly into
the input of the grep command.
Example 1
Sort the products in data.txt by their price, and store only the product name and product price in the file result.txt
using one command (Figure 12).
The intermediate result is then piped into the input of the second command cut -d' ' -f2,3, which generates the
final result. The final result is then redirected to a file named result.txt.
Illustration:
Find the file/directories in the current directories with execute (x) permission for user, group and others.
The command to get the files and directories with the permission indicators
$ ls -l
total 190
-rwx--x--x. 1 kit gopher 0 Sep 12 10:30 add.o
The files that all user, group and others have execute permissions only if the 4th, 7th and 10th position of indicators are
“x”. (i.e. “---x--x--x”)
So, the command to return those files that are executable by users, group and others using regular expression is:
$ grep -E '^...x..x..x' [the result of ls -l]
• “^” indicates the matching start from the beginning of the line.
• “.” indicates to match any single character.
• “^...x..x..x” indicate to match the lines from the beginning, return the line if the 4th, 7th and 10th letters
are “x”.
Therefore, we can pipe the output of ls -l to the input of the grep command.
$ ls -l | grep -E '^...x..x..x'
Suppose you want to remove some of the column(s) in a file then input it into a program.
Here, you have a file mark.txt that contain one-line data of student information and marks.
$ cat mark.txt
2011111111 John M 98.5 100 62.5 88 75.5
*the format is [UID, name, gender, mark1, mark2, mark3, mark4, mark5]
One possible way to pipe the data in mark.txt to the program is to cut the data in mark.txt so that it pipes only the
assignment marks.
Example
Assume there are two files (hello.txt, hello.cpp) and one directory (home) in the current directory.
$ ls
hello/ hello.cpp hello.txt
To search for a file hello.txt in the current directory and all its sub-directories.
$ find . -name "hello.txt" -type f
./hello.txt
Note: The dot (.) define the current directory, as find will drill down starting from the current directory; the above
command is to search for the file hello.txt in the current directory and all its subdirectories.
To search for a directory in the current directory and all its any sub-directories.
$ find . -name "hello" -type d
./hello
find can do a lot more besides search by name. For example, find can search by file ownership, modification time,
size…etc. Please refer to the references if you are interested in learning more about the command find.
The most common way to use grep is to search for the lines consist of a given word, in that case, we do not need the
flag -E.
E.g., search for lines containing ‘hell’ in the file example1.txt (Figure 13).
$ grep 'hell' example1.txt
Hello how are you?
I am using the bash shell like a pro!
I am using the bash shell like a pro!
*grep is case sensitive! it only matches the “shell” in the
2nd line but NOT the “Hello” in the 1st line.
Figure 13 example1.txt
Regular expression
Symbol Meaning
. Matching any single character.
^ Match the beginning of the line only.
$ Match the end of the line only.
? A single character followed by an ?, will match zero or one occurrence.
+ A single character followed by an +, will match one or more occurrences.
* A single character followed by an *, will match zero or more occurrences.
[] Character enclosed inside the [ ]will be matched.
This can be a single or range of characters.
You can use the “-“ to include a range inclusively.
E.g., instead of saying [12345], use [1-5].
\ Use this to escape the special meaning of a metacharacter.
E.g., As “.” means matching any single character, we need to use “\.” to mean that we
are matching a dot in a pattern.
pattern {n} Match n occurrences of the pattern.
pattern {n,} Match at least n occurrences of the pattern.
pattern {n,m} Match occurrences of the pattern between n and m.
3 occurrences of the pattern ‘ab’ .
(ab){3}
For example, (ab){3} will match “ababab”, but not “abbb”.
Use a dot (.) to match any character to search for patterns any single character followed by “ell” in example1.txt
(Figure 13).
$ grep -E '.ell' example1.txt
Hello how are you?
I am using the bash shell like a pro!
• We need to use the flag -E because ‘.ell’ is a regular expression, which contains the regular expression symbol.
• With '.ell', even if the words “Cell”, “cell”, “bell” …etc will be matched. If you want to limit the single
character to be only ‘H’ or ‘h’, then you need to use the square bracket '[Hh]ell'. We will have more examples
of the use of square in the following sections.
Use ‘^’ and ‘$’ together to match the exact content of a line.
$ grep -E '^apple$' example2.txt
apple
Use ‘^’ and ‘$’ to specify the exact content of a line and use 5 “.” to express “any 5 characters” to match a line that
contains exactly 5 characters.
$ grep -E '^.....$' example2.txt
apple
The following 3 notations are used to specify the number of occurrences of the character immediately ahead of them:
? A single character followed by ?, will match zero or one occurrence of the character.
+ A single character followed by +, will match one or more occurrences of the character.
* A single character followed by *, will match zero or more occurrences of the character.
Example 1 (?)
Use ‘?’ to match lines that followed by zero or one occurrence of the character “p”.
$ grep -E '^ap?' example3.txt apple
apple coco
ape cherries
angel orange
ape
Explanations: angel
Example 2 (+)
Use ‘+’ to match lines that followed by one or more occurrences of the character “p”.
$ grep -E '^ap+' example3.txt
apple
ape
Explanations:
1. "apple" is returned as the first three characters “app” matched the expression (“a” followed by two (satisfies one
or more) occurrences of “p”).
2. "ape" is returned as the first two characters “ap” matched the expression (“a” followed by one (satisfies one or
more) occurrence of “p”).
3. "angel" is NOT returned because although is “a” matched, it is NOT followed by any character “p”. (“+” requires
one or more occurrences)
Use ‘*’ to match lines that followed by zero or more occurrences of the character “p”.
$ grep -E '^ap*' example3.txt
apple
ape
angel
Explanations:
• “apple” is returned as the first three characters “app” matched the expression (“a” followed by two (satisfies
zero or more) occurrences of “p”).
• “ape” is returned as the first two characters “ap” matched the expression (“a” followed by one (satisfies zero or
more) occurrence of “p”)
• “angel” is returned as the first character “a” matched the expression (“a” followed by zero (satisfies zero or
more) occurrences of “p”)
Here, we want to match a character “a”, followed by any number of characters and then followed by “ge”.
$ grep -E 'a.*ge' example3.txt
orange
angel
Explanations:
• “orange” and “angel” are returned as both lines have the substring “ange” , which is a character “a” followed by
any number of characters (i.e., denoted by the expression “.*”), then followed by “ge”.
Here, we want to match lines that the substring “co” occur one or more times.
$ grep -E '(co)+' example3.txt
coco
Note: If we use the regular expression “co*” then both “coco” and “cherries” will be returned because the “*” applies
to the character “o” only, which essentially means return lines with a character “c” followed by zero or more “o”.
$ grep -E 'co*' example3.txt
coco
cherries
We can use the square bracket “[ ]“ to specify matching any character in a set.
We can use “{ }“ to specify matching the number of occurrence the pattern appears.
2April2013
30-1-2013
13December2013
Note that [a-zA-Z] means any letters, you cannot write it in this way: [a-z,A-Z]. In that case, it indicates any
letters plus a comma “,” are allowed.
Linux tutorials:
3 Linux Tutorial
This website provides comprehensive introduction of Linux commands
Command-line bootcamp
This website not only provide you a brief introduction of Linux commands, but also include an online Linux
command line environment so you can try all the commands within your browser.
Regular Expression:
Using Grep & Regular Expressions to Search for Text Patterns in Linux
This website gives you more examples of using Regular Expressions in “grep” command.
7. References
• Part 1. A Practical Guide to Linux(R) Commands, Editors, and Shell Programming, Mark Sobell. Prentice Hall
PTR
• Chapter 1. File security and permission. LINUX &UNIX Shell Programming. Mr. David Tansley, Addison
Wesley.
• An A-Z Index of the Bash command line for Linux. http://ss64.com/bash/
• UNIX – Lesson 017 – chmod command in symbolic-mode and in absolute-mode.
http://tipsandtricks4it.wordpress.com/2010/01/25/lesson-017/
• Chmod Online tutorial: http://ss64.com/bash/chmod.html
• Linux.org tutorial on file permission: http://www.linux.org/article/view/file-permissions-chmod
• Understanding ‘diff’ command. http://tarique21.wordpress.com/2008/11/06/understanding-diff-command/
• Chapter 2. Using find and xargs. LINUX & UNIX Shell Programming. Mr. David Tansley, Addison Wesley.
• Online tutorial for find: http://ss64.com/bash/find.html
• A Beginner’s Guide to Grep: Basics and Regular Expressions: http://www.linuxforu.com/2012/06/beginners-
guide-gnu-grep-basics-regular-expressions/
• Online tutorial for regular expression: http://www.regular-expressions.info/
• Chapter 7. Introducing regular expressions, Chapter 8. The grep family. LINUX &UNIX Shell Programming. Mr.
David Tansley, Addison Wesley.
Graphical vi-vim Cheat Sheet and Tutorial. (n.d.). Retrieved from http://www.viemu.com/a_vi_vim_graphical_cheat_sheet_tutorial.html