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

Handout11-Linux Commands and Utilities II

Uploaded by

Brandon Guy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views4 pages

Handout11-Linux Commands and Utilities II

Uploaded by

Brandon Guy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

CFS264 ‐ Computer and Operating Systems Fundamentals II Page 1 of 4

Handout 11 - Linux Commands and Utilities II


_____________________________________________________________________________________

Following the steps introduced in Handout1 to log onto the host metrostate.mooo.com, then try the content
discussed below. Please create a directory lab11 and do the following exercises.

Linux Commands and Utilities II

 ln: ln means link and is used to ctreate multiple names for a file;
 Links can be either hard or symbolic (soft);
 A hard link provides a point to the same file (it has the same i-node as the source file)
 A symbolic link (soft link) creates a new i-node that references to the source file)
 Only symbolic links can be created for a directory or across different partitions because they use different i-
nodes.
 When the original file is removed, one can still use the hard links to access the file while the symbolic links
are no longer workable.
 Examples:
$ cat > f2
fff
^D
$ ls –l f2
-rw-r--r-- 1 cfs264sp2580 cfs264sp25 4 2024-10-08 f2
$
 For command ls, option i can be used to display i-nodes.
$ ls –il f2
1296723 -rw-r--r-- 1 cfs264sp2580 cfs264sp25 4 2024-10-08 f2
$
 Create a hard link f3 to the original file f2:
$ ln f2 f3
$ ls –il f2 f3
1296723 -rw-r--r-- 2 cfs264sp2580 cfs264sp25 4 2024-10-08 f2
1296723 -rw-r--r-- 2 cfs264sp2580 cfs264sp25 4 2024-10-08 f3
$ cat f3
fff
$
 Create a symbolic link f4 to the original file f2:
$ ln –s f2 f4
$ ls –il f2 f3 f4
1296723 -rw-r--r-- 2 cfs264sp2580 cfs264sp25 4 2024-10-08 f2
1296723 -rw-r--r-- 2 cfs264sp2580 cfs264sp25 4 2024-10-08 f3
1296724 lrwxrwxrwx 1 cfs264sp2580 cfs264sp25 2 2024-10-08 f4 -> f2
$ cat f4
fff
$ rm f2
$ ls –il f2 f3 f4
ls: cannot access f2: No such file or directory
1296723 -rw-r--r-- 2 cfs264sp2580 cfs264sp25 4 2024-10-08 f3
1296724 lrwxrwxrwx 1 cfs264sp2580 cfs264sp25 2 2024-10-08 f4 -> f2
$ cat f3
fff
$ cat f4
cat: f4: No such file or directory
$
 What if a symbolic link was made over file “f3” instead (ln –s f3 f4)? After file “f2” was removed,
could we still be able to view the original content of the file (“fff”) by “f4”?

_____________________________________________________________________________________________
Please complete the Linux Lab in D2L
CFS264 ‐ Computer and Operating Systems Fundamentals II Page 2 of 4
Handout 11 - Linux Commands and Utilities II
_____________________________________________________________________________________

 tr: tr means translation and is used to translate, squeeze or delete characters;


 Syntax:
tr [OPTIONS]… SET1 [SET2]
 Examples:
$ echo "Metro State CFS 264" | tr [:space:] ';'
Metro;State;CFS;264;
$
$ echo "Metro State CFS 264" | tr ' ' ';'
Metro;State;CFS;264
$
$ echo "Metro State CFS 264" | tr 'Metro' 'Idaho'
Idaho Saaad CFS 264
$
 Why and how to fix the problem?
$
$ echo "Metro State CFS 264" | sed 's/Metro/Idaho/g'
Idaho State CFS 264
$
$ echo "Metro State" | tr [:lower:] [:upper:]
METRO STATE
$
$ echo "CFS 264, Lab 11" | tr –d [:digit:]
CFS , Lab
$
$ last | grep cfs264fa | grep "Jan 13" | head -2
cfs264fa pts/0 207.153.45.151 Mon Jan 13 20:41 - 20:56 (00:14)
cfs264fa pts/4 66.41.51.45 Mon Jan 13 20:04 - 22:27 (02:23)
$
$ last | grep cfs264fa | grep "Sep 17" | head -2 | tr ' ' ','
cfs264fa,pts/0,,,,,,,,207.153.45.151,,,Mon,Jan,13,20:41,-,20:56,,(00:14)
cfs264fa,pts/4,,,,,,,,66.41.51.45,,,,,,Mon,Jan,13,20:04,-,22:27,,(02:23)
$
 To replace a sequence of repeated characters with a single character, option “ s” can be used as follow:
$ last | grep cfs264fa | grep "Sep 17" | head -2 | tr -s ' ' ','
cfs264fa,pts/0,207.153.45.151,Mon,Jan,13,20:41,-,20:56,(00:14)
cfs264fa,pts/4,66.41.51.45,Mon,Jan,13,20:04,-,22:27,(02:23)
$
 In addition to the examples provided above, other useful character classes are listed below:
[:alnum:] all letters and digits
[:alpha:] all letters
[:cntrl:] all control characters
[:print:] all printable characters, including space
[:punct:] all punctuation characters
[:xdigit:] all hexadecimal digits

_____________________________________________________________________________________________
Please complete the Linux Lab in D2L
CFS264 ‐ Computer and Operating Systems Fundamentals II Page 3 of 4
Handout 11 - Linux Commands and Utilities II
_____________________________________________________________________________________

 od: od stands for “octal dump” which is a Linux/Unix command used to dump files in either octal or
other formats;
 The default output format is octal, which is a number system based on 8;
 Options for output in octal, decimal, and hexadecimal are -b, -d, and –x, respectively.
 Syntax:
od [OPTIONS]… [FILE]…
 Examples:
$ cat > ddd
Metro State CFS 264
^D
$ cat ddd
Metro State CFS 264
$
 Display file “ddd” in hexadecimal:
$ od -x ddd
0000000 654d 7274 206f 7453 7461 2065 4643 2053
0000020 3632 0a34
0000024
$
 Display file “ddd” in decimal:
$ od -d ddd
0000000 25933 29300 8303 29779 29793 8293 17987 8275
0000020 13874 2612
0000024
$
 Display file “ddd” in octal:
$ od ddd
0000000 062515 071164 020157 072123 072141 020145 043103 020123
0000020 033062 005064
0000024
$
 Display file “ddd” in characters:
$ od -c ddd
0000000 M e t r o S t a t e C F S
0000020 2 6 4 \n
0000024
 To make a hexadecimal dump directly, you can use command “xxd” as follow:
$ xxd ddd
0000000: 4d65 7472 6f20 5374 6174 6520 4346 5320 Metro State CFS
0000010: 3236 340a 264.
$
 You can also use “hexdump” to obtain a similar result as the one shown above:
$ hexdump -C ddd
00000000 4d 65 74 72 6f 20 53 74 61 74 65 20 43 46 53 20 |Metro State CFS |
00000010 32 36 34 0a |264.|
00000014

_____________________________________________________________________________________________
Please complete the Linux Lab in D2L
CFS264 ‐ Computer and Operating Systems Fundamentals II Page 4 of 4
Handout 11 - Linux Commands and Utilities II
_____________________________________________________________________________________
 md5sum: generate a 128-bit hash value, called checksum or MD5 message digest, for a given file or a
piece of information.
$ echo “computer” | md5sum
eb831aeaaa3fd6eb4f5355841dd88edb -
$ echo “computer science” | md5sum
6df6bebdffbde9ca5a429da56e264182 -
$ echo “Computer science” | md5sum
cadf392665eab5c077bb240470d4e983 -
$
$ cat ddd
Metro State CFS 264
$ md5sum ddd
1c97229aca4fed8ed9cb689a578d0416 ddd
$ ls -l --time-style=+"%b %d %Y %H:%M:%S" ddd
-rw-r--r-- 1 cfs264sp2580 cfs264sp25 20 Mar 18 2022 20:23:28 ddd
$ touch ddd
$ ls -l --time-style=+"%b %d %Y %H:%M:%S" ddd
-rw-r--r-- 1 cfs264sp2580 cfs264sp25 20 Mar 18 2022 20:24:48 ddd
$ md5sum ddd
1c97229aca4fed8ed9cb689a578d0416 ddd
$ cat > ddd2
1c97229aca4fed8ed9cb689a578d0416
-rw-r--r-- 1 cfs264sp2580 cfs264sp25 20 Nov 15 2021 12:35:45 ddd
^D
$ md5sum ddd2
2dbd9e659d50958621eaad853bf5a54f ddd2
$ cat > ddd3
1c97229aca4fed8ed9cb689a578d0416
-rw-r--r-- 1 cfs264sp2580 cfs264sp25 20 Nov 15 2021 12:38:58 ddd
^D
$ md5sum ddd3
21ba4c4f192ae2f28a190ceeaaf4e50e ddd3
$
 sha256sum: generate a 256-bit hash value, called checksum or SHA256 hash value, for a given file or a
piece of information.
$ sha256sum ddd
beb6d15637f0bd55ca02ff4ef3ea690a3a0d7c991e4caf2320f2d651bae79286 ddd
$ touch ddd
$ sha256 ddd
beb6d15637f0bd55ca02ff4ef3ea690a3a0d7c991e4caf2320f2d651bae79286 ddd
$
 Some other useful Linux commands:
env [without any option]: display the initializations of the environment variables
gpg : a very useful OpenPGP encryption and signing tool (for a symmetric key: gpg –c filename)
history [without any option]: display all the commands used previously
script filename: record the interactive terminal activities
stat filename: display all the information about the file
uname –a : display the version of the operating system

_____________________________________________________________________________________________
Please complete the Linux Lab in D2L

You might also like