0% found this document useful (0 votes)
45 views37 pages

It-04 - PRT01

This document provides an introduction to basic Unix/Linux commands for working with directories, files, and file contents. It covers commands for changing directories (cd), printing the working directory (pwd), listing directory contents (ls), creating/removing directories (mkdir, rmdir), touching/removing files (touch, rm), copying/moving files (cp, mv), and viewing file contents (head, tail, cat). The document also discusses absolute vs relative file paths and hidden files indicated by a leading dot.
Copyright
© © All Rights Reserved
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)
45 views37 pages

It-04 - PRT01

This document provides an introduction to basic Unix/Linux commands for working with directories, files, and file contents. It covers commands for changing directories (cd), printing the working directory (pwd), listing directory contents (ls), creating/removing directories (mkdir, rmdir), touching/removing files (touch, rm), copying/moving files (cp, mv), and viewing file contents (head, tail, cat). The document also discusses absolute vs relative file paths and hidden files indicated by a leading dot.
Copyright
© © All Rights Reserved
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/ 37

Information Technology

Skills

Introduction to Unix/Linux
(Basic Commands)

by Dr. Saud S. Alotaibi


Email: [email protected]

Course Material Web Site: elearn.uqu.edu.sa

1
Outlines
 Introduction to Linux
 Working with directories
 Working with files
 Working with file contents

 Compress and extract archives


 Software management
 Linux file system
 Files ownership
 User management

2
Introduction to Linux
Unix and Linux Operating Systems
 UNIX/Linux is used on systems functioning as:
 Servers, clients, client/server workstations, and stand-alone workstations
 UNIX/Linux are multiuser/multitasking systems
 Some characteristics of UNIX/Linux systems:
 Portability
 Stable, reliable, and versatile
 Thousands of applications are written for them
 Many security options
 Well suited for networked environments

4
History
 Today more than 97 percent of the world’s:
 supercomputers (including the complete top 10),
 Most of all smartphones,
 Global mobile OS market share 2022 | Statista
 many millions of desktop computers,
 around 70 percent of all web servers,
 a large chunk of tablet computers,
 and several appliances (dvdplayers, washing machines, dsl modems,
routers, self-driving cars, space station laptops...)
 run Linux. Linux is by far the most commonly used operating
system in the world.

5
Linux and Unix
 Linux is a UNIX-like operating system
 Not written from the traditional UNIX code
 Kernel created to look and act like UNIX
 Enhancements include the POSIX standards
 Linus Torvalds released it free of charge in 1991

6
Linux distributions
 A Linux distribution is a collection of (usually open source)
software on top of a Linux kernel.
 A distribution (or short, distro) can bundle server software,
system management tools, documentation and many desktop
applications in a central secure software repository.
 A distro aims to provide a common look and feel, secure and
easy software management and often a specific operational
purpose.
 Many distributions are available:
 DebianGNU/Linux
 Fedora
 Red Hat Enterprise Linux
 openSUSELinux
 Ubuntu

7
Using Commands
 To interact with UNIX/Linux, you enter a command
 UNIX/Linux are case sensitive
 John differs from john
 Two categories:
 User-level commands
 System-administration commands
 Must know a command’s syntax to enter it properly
 Need to know options and arguments
 Commands are typed on the command line

 https://www.tutorialspoint.com/linux_terminal_online.php
 https://cocalc.com/features/terminal
 https://linuxcontainers.org/

8
Working with directories

4/12/2023
Directories managements
 This module is a brief overview of the most common commands
to work with directories:
 pwd,
 cd,
 ls,
 mkdir
 and rmdir.
 These commands are available on any Linux (or Unix) system.
 This module also discusses absolute and relative paths and path
completion in the bash shell.

10
Directories managements (cont.)
 pwd
 The you are here sign can be displayed with the pwd command (Print
Working Directory).

 cd
 You can change your current directory with the cd command (Change
Directory).

11
Directories managements (cont.)
 cd ..
 To go to the parent directory (the one just above your current directory
in the directory tree), type cd ..

12
Absolute and relative paths
 You should be aware of absolute and relative paths in the file
tree.
 When you type a path starting with a slash (/), then the root of
the file tree is assumed. If you don't start your path with a slash,
then the current directory is the assumed starting point.
 The screenshot below first shows the current directory /home/oneday.
From within this directory, you have to type
 cd /home instead of cd home to go to the /home directory.

13
Absolute and relative paths (cont.)
 When inside /home, you have to type cd oneday instead of cd
/oneday to enter the subdirectory oneday of the current
directory /home.

14
Directory contents
 ls
 You can list the contents of a directory with ls

 ls –a
 A frequently used option with ls is -a to show all files. Showing all files
means including the hidden files. When a file name on a Linux file system
starts with a dot, it is considered a hidden file and it doesn't show up in
regular file listings.

15
Directory contents (cont.)
 ls –l
 Many times you will be using options with ls to display the
contents of the directory in different formats or to display
different parts of the directory. Typing just ls gives you a list of
files in the directory. Typing ls -l (that is a letter L, not the number
1) gives you a long listing.

16
Directory creation
 mkdir
 To create a directory
 You have to give at least one parameter to mkdir, the name of the new
directory to be created. Think before you type a leading / .

17
mkdir -p
 The following command will fail, because the parent directory of
threedirsdeep does not exist.

 When given the option -p, then mkdir will create parent directories as
needed.

18
Removing directories
 rmdir :When a directory is empty, you can use rmdir to remove the
directory.

 rmdir –p: similar to the mkdir -p option, you can also use rmdir to
recursively remove directories.

19
Working with files
Files on Linux
 All files are sensitive
 Files on Linux (or any Unix) are case sensitive.
 This means that FILE1 is different from file1,
 and /etc/hosts is different from /etc/Hosts (the latter one does not
exist on a typical Linux computer).
 Everything is a file
 A directory is a special kind of file, but it is still a (case sensitive!) file.
 Each terminal window (for example /dev/pts/4), any hard disk or
partition (for example /dev/sdb1) and any process are all represented
somewhere in the file system as a file.
 It will become clear throughout this course that everything on Linux is a
file.

21
file
 Linux does not use extensions to determine the file type.
 Use the file utility determines the file type.

 file –s: for special files like those in /dev and /proc.

22
Files commands
 touch : create empty file

 touch –t : command can set some properties while creating


empty files

23
Files commands
 rm : remove file forever

 rm –i: to prevent yourself from accidentally removing a file

 rm –rf: remove non empty directories

24
Files commands
 cp: it copies a file

 Copy to another directory:

 cp –r: to copy complete directories, use cp -r (the -r option


forces recursive copying of all files in all subdirectories).

25
Files commands
 cp –i: to prevent cp from overwriting existing files, use the -i (for
interactive) option

 copy multiple files to directory

26
Files commands
 mv: used to move or rename file or directory

 mv –i: ask permission to overwrite an existing file

27
Working with file contents
Working with file contents
 we will look at the contents of text files with
 head,
 tail,
 cat,
 tac,
 and strings.

29
File contents
 head : display the first ten lines of a file

 The head command can also display the first n lines of a file.

30
File contents
 tail : Similar to head, the tail command will display the last ten
lines of a file.

 The tail command can also display the last n lines of a file.

31
File contents
 cat: the cat command is one of the most universal tools, yet all it
does is copy standard input to standard output. In combination
with the shell this can be very powerful and diverse.
 Display file content

32
File contents
 cat is short for concatenate. One of the basic uses of cat is to
concatenate files into a bigger (or complete) file.

33
File contents
 Create files: cat is used to create flat text files.
 Type the cat > winter.txt
 Then type one or more lines, finishing each line with the enter key.
 After the last line, type and hold the Control (Ctrl) key and press d.

 You can choose an end marker for cat with << to make end of
file

34
File contents
 cat could be used to copy file content to another file.

 tac: inverse the file content display

35
File contents
 strings : with the strings command you can display readable ascii
strings found in (binary) files. This example locates the ls binary
then displays readable strings in the binary file (output is
truncated).

 Using strings

36
Information Technology
Skills

Questions

37

You might also like