Lab Activity 3
Lab Activity 3
Lab Activity 3
Learning Outcomes:
Theory :
Syntax:
ls [Options]... [File]...
Examples:
total 128
drwxr-xr-x 22 root root 4096 2015-05-20 00:55 .
drwxr-xr-x 3 root root 4096 2014-08-12 04:39 ..
-rw-r--r-- 1 root root 220 2014-08-12 04:39 .bash_logout
-rw-r--r-- 1 root root 3103 2014-08-12 04:39 .bashrc
drwx------ 4 root root 4096 2015-05-20 00:56 .cache
drwxr-xr-x 5 root root 4096 2014-08-11 21:51 .config
drwx------ 3 root root 4096 2014-08-11 21:50 .dbus
drwxr-xr-x 2 root root 4096 2014-08-11 21:50 Desktop
-rw-r--r-- 1 root root 41 2015-05-20 00:55 .dmrc
Syntax:
cd [Options] [Directory]
Examples:
Syntax:
pwd [-LP]
Examples:
$ pwd
/var/log
Syntax:
who [Options] [file] [am i]
Examples:
Syntax:
man [-acdfFhkKtwW] [--path] [-m system] [-p string] [-C config_file]
[-M pathlist] [-P pager] [-B browser] [-H htmlpager] [-S section_list]
[section] name ...
Examples:
Syntax:
touch [Options]... file...
Examples:
#Create a new file
$ touch file1.txt
$ls
Desktop Downloads file1.txt Pictures Templates
Documents examples.desktop Music Public Videos
8. Editing File
cat
Syntax:
cat >> [File]...
Examples:
#Edit file1.txt
$ cat >> file1.txt
Learning command line in linux is fun !!!
Ctrl – D (to exit from text mode)
#Edit file1.txt
$ cat >> file1.txt
PUO is the best
Ctrl – D (to exit from text mode)
#Edit a file2.txt $
cat >> file2.txt
My name is ………………………………………..
I’m proud to be PUO student
Ctrl – D (to exit from text mode)
9. Concatenate and print (display) the content of files.
cat
Syntax:
cat [Options] [File]...
Examples:
#Display a file:
$ cat file1.txt
Learning command line in linux is fun !!!
PUO is the best
Syntax:
mkdir [Options] folder...
Examples:
#In your own home directory make subdirectories dir2 and dir3 simultaneously
Syntax:
cp [Options]... Source Dest
cp [Options]... Source... Directory
Examples:
#Copy file1.txt to dir1
$ cp file1.txt dir1
Syntax:
mv [Options]... SourceDest
mv [Options]... Source... Directory
Examples:
Syntax:
rm [Options]... file...
Example:
Remove directory, this command will only work if the directories are empty.
rmdir
Syntax:
rmdir [Options]... folder(s)...
Example:
Syntax:
head [Options]... [file]...
15. Output the last part of files, print the last part (10 lines by default) of each
FILE; tail reads from standard input if no files are given or when given a FILE
of - tail
Syntax:
tail [Options]... [file]...
Examples:
#Display the last 4 lines from a file /etc/group then tail to get the last 10:
$head -4 /etc/group | tail -10
Syntax:
less [Options]... [file]...
Note: The Linux commands less are similar to cat, but with less you can scroll the file
instead of showing the enter file at once. So if you have larger files you want to view that
are longer than your screen or terminal then you can use less commands instead of cat.