92
◾
Linux with Operating System Concepts
can use the “save” command to save the file once you have entered text into the editor. The
first time you save the file, you will be prompted for a name. We visit vi and emacs later in
Chapter 5.
The
touch
command creates an empty text file. The command’s true purpose is to
modify the access and modification time stamps of a file. However, if the file does not
currently exist, an empty text file is created. This can be useful if you wish to ensure that
a file exists which will eventually contain output from some other program such as a shell
script. Or, touch can be used to start a text file that you will later edit via vi. The options
-a and -m modify the last access time and date and last modification time and date to the
current time.
The touch command also has the option -t to specify a new access and/or modification
date and time. The -t option is followed by the date and time using the format
[[CC]YY]
MMDDhhmm[.ss]
, which means the current year, month, and date as a 6- or 8-digit number
(if CC is omitted, the year is implied to be from the current century, and if YY is omitted,
the year is implied to be this year). The .ss notation permits the seconds if included. For
instance,
-t 1112131415.16
would be 2:15.16 p.m. on December 13, 2011. Finally, you
can use
-r
filename
so that the given filename’s time/date is used in place of the current
time/date.
Another way to create a file is to call upon a Linux command and redirect the output
from terminal window to a file. For instance,
cat file1.txt file2.txt file3.txt | sort -r
>
newfile.txt
will combine the three text files, sort the entries in reverse order and store the result to
newfile.txt. If newfile.txt already exists, it is overwritten. The use of
>>
will append the
results to an already existing file, or create the file if it does not already exist.
3.3.9 Hard and Symbolic Links
A directory stores items such as files and subdirectories. In reality, the directory stores
links to these items. The links are formally known as
hard links
. Each hard link consists
of the item’s name and the inode number. The inode number is then used to index into
or reach the inode itself. Thus, the link provides a pointer to the file. You generally have a
single link per file. However, you are allowed to create duplicate links to be stored in other
directories so that accessing the item can be handled more conveniently.
There are two types of links. The hard link is a duplicate of the original link. The
Do'stlaringiz bilan baham: