52
Unix computing basics Campus-Booster ID : **XXXXX www.supinfo.com Copyright © SUPINFO. All rights reserved Filesystem and common commands

Linux Filesystem and Common Commands

Embed Size (px)

DESCRIPTION

Linux FileSystem and Common Command

Citation preview

Page 1: Linux Filesystem and Common Commands

Unix computing basicsCampus-Booster ID : **XXXXX

www.supinfo.comCopyright © SUPINFO. All rights reserved

Filesystem and common commands

Page 2: Linux Filesystem and Common Commands

Your trainer…

Title: **Enter title or job role.

Accomplishments: **What makes the presenter qualified to present this course.

Education: **List degrees if important.

Publications: **Writings by the presenter on the subject of the course or presentation.

Contact:**Campus-Booster ID: [email protected]’s Name

Filesystem and common commands

Page 3: Linux Filesystem and Common Commands

Course objectives

Talk about fs hierarchy. Forest vs tree.

Tell files from directories. Using the command line.

Guess where removable devices are. Mounting concept and conventions.

Navigate in the filesystem. And work with files and directories.

Combine tools. Using streams, pipes, and redirections.

By completing this course, you will:

Filesystem and common commands

Page 4: Linux Filesystem and Common Commands

Course topics

Unix filesystem. Finding your way through.

Using the shell. Terminal shell and console.

Common commands. Survival kit.

Streams and redirections. STDOUT and friends.

Course’s plan:

Filesystem and common commands

Page 5: Linux Filesystem and Common Commands

Unix filesystem

Finding your way through.

Filesystem and common commands

Page 6: Linux Filesystem and Common Commands

Forest vs TreeUnix filesystem

Windows

multi-root

One root per FS

“Disk drive”

No single entry point

Forest

Unix

Single root

Single entry point

Tree

Unix vs Windows fs models

Page 7: Linux Filesystem and Common Commands

WindowsUnix filesystem

Page 8: Linux Filesystem and Common Commands

UnixUnix filesystem

Page 9: Linux Filesystem and Common Commands

PathsUnix filesystem

Absolute

aka Full path

Begins with a ‘/’ /home/supinfo/Documents/doc.txt

Can be (very) long

Relative

From the current working directory

CWD = /home/supinfo Documents/doc.txt

Relative vs Absolute

Page 10: Linux Filesystem and Common Commands

MountingUnix filesystem

Windows

New “disk drive”

Unix

Need to attach the new fs to the existing hierarchy

Bind a filesystem to a directory

Usually under /mnt/

mount command

What about removable devices ?

Page 11: Linux Filesystem and Common Commands

Everything is a fileUnix filesystem

Devices exposed

Special files

char

block

/dev

Examples

/dev/dsp

/dev/sda

System settings

/proc/sys/

If not, it’s a process

Page 12: Linux Filesystem and Common Commands

Stop-and-thinkUnix filesystem

Do you have any questions ?

Page 13: Linux Filesystem and Common Commands

Stop-and-thinkUnix filesystem

I’m a file. I’ll sing out what’s written to me. I am:

___________

Page 14: Linux Filesystem and Common Commands

Stop-and-thinkUnix filesystem

I’m a file. I’ll sing out what’s written to me. I am:

___________/dev/dsp

Page 15: Linux Filesystem and Common Commands

Using the shell

Terminal, shell and console

Filesystem and common commands

Page 16: Linux Filesystem and Common Commands

DefinitionUsing the shell

Shell - also called "command interpreter“ executes commands that the user types.

Page 17: Linux Filesystem and Common Commands

The promptUsing the shell

[supinfo@linux-tpl1:~/documents]$

Username

Hostname

Path

Privilege level

Current working directory

$ for regular users# for root

The shell prompt is a set of characters at the start of the command line that indicates that the shell is ready to receive commands.

Page 18: Linux Filesystem and Common Commands

Terminal, shell and consoleUsing the shell

Terminal

Hardware

Connected to the server

Terminal emulator

Software

Understand the original protocol (VTx)

Shell

User interact with it through the terminal

TTY/Console

Generic term for any {STDIN,STDOUT,STDERR} tuple

Page 19: Linux Filesystem and Common Commands

Terminal exampleUsing the shell

Bull Questar 4000

Many stations

screen, keyboard

One server (the cube)

Used by French administration(Trésor Public)

Original terminals until late 90’s

Moved to terminal emulators running on PC’s in the early 2k’s

Page 20: Linux Filesystem and Common Commands

Virtual TerminalsUsing the shell

TTY subsystem

Generic

Local/Network

Virtual terminals

Like workspaces

Available through alt+F1..F6

ctrl from X

Different from terminal emulators

Old concepts, modern hardware

Page 21: Linux Filesystem and Common Commands

Stop-and-thinkUsing the shell

Do you have any questions ?

Page 22: Linux Filesystem and Common Commands

Stop-and-thinkUsing the shell

The terminal

The console

A TTY

The Shell

The prompt is provided by:

Page 23: Linux Filesystem and Common Commands

Stop-and-thinkUsing the shell

The terminal

The console

A TTY

The Shell

The prompt is provided by:

Page 24: Linux Filesystem and Common Commands

Common commands

Survival kit

Filesystem and common commands

Page 25: Linux Filesystem and Common Commands

Listing filesCommon commands

Good ol’ list segments from multics.

Option Definitions

-l

-h

Long listing: Mode, owner, size, ...

Human-readable file size

ls [options] file-expression

ls -lh *.zip

Example:

-a Also list “hidden” files

Page 26: Linux Filesystem and Common Commands

GlobbingCommon commands

Matching files using joker characters

* Corresponds to none or some characters.

? Corresponds to one character.

[a-z] Corresponds to all the letters between a and z

[^a-z] Corresponds to all the characters except the letters between a and z.

[user@linux ~]$ ls [b-c]*.txtbatman.txt chocolate.txt

Page 27: Linux Filesystem and Common Commands

File propertiesCommon commands

-rwxr-xr-x 1 user group 64 Nov 29 17:07 file.txt

mode

Hard links

Ownership File

File mode bitfield represent permissions and file type

Number of hard links.

User owner and group owner

Last modification date (mtime)

File sizeIn bytes. Use -h to get human-readable sizes.

Filename

Anatomy of a ls -l

Page 28: Linux Filesystem and Common Commands

The current working directoryCommon commands

To get the current working directory

To move into a directory :

directory : relative or absolute path.

[user@linux bin]$ pwd/usr/bin

[user@linux ~]$ cd directory

Page 29: Linux Filesystem and Common Commands

The current working directoryCommon commands

To get back to the home directory cd or cd ~

To get back to the previous directory cd - :

[user@linux bin]$ pwd/usr/bin[user@linux bin]$ cd ~[user@linux ~]$ pwd/home/user

[user@linux ~]$ cd /usr/bin[user@linux bin]$ cd -[user@linux ~]$

Page 30: Linux Filesystem and Common Commands

Copying filesCommon commands

The cp command:

Option Definitions

-r

-f

Recursively copy directories

Delete destination if exists

cp [options] source destination

cp -p /etc/lilo.conf ./lilo.conf

Example:

-p Preserve ownership

Page 31: Linux Filesystem and Common Commands

Delete filesCommon commands

The cp command:

Option Definitions

-r, -R

-f

Recursively delete directories

Don’t prompt for confirmation

rm [options] file ...

rm -Rf ~

Example:

-i Prompt for confirmation

Page 32: Linux Filesystem and Common Commands

Rename/move filesCommon commands

The mv command:

Option Definitions

-f

-i

Don’t prompt before overwrite

Prompt before overwrite

mv [options] source destination

mv texst.txt test.txtmv /etc/lilo.conf .

Example:

-b Create a backup of existing destination before overwriting.

Page 33: Linux Filesystem and Common Commands

Creating linksCommon commands

The ln command:

Option Definitions

-s Create symlinks

ln [options] source link-name

ln -s /etc/init.d/apache2 S99apache2ln ~/Documents/file.txt .

Example:

Page 34: Linux Filesystem and Common Commands

LinksCommon commands

Symlink

To the name/path

Like Windows shortcuts

Use an inode

Hardlinks

Other pointer to the same content

Cannot point outside the filesystem/partition

Symlinks vs hardlinks

Page 35: Linux Filesystem and Common Commands

Creating directoriesCommon commands

The mkdir command:

Option Definitions

-p Create parent directories as needed

mkdir [options] directory

mkdir tinkeringmkdir -p /var/tmp/workspace

Example:

Page 36: Linux Filesystem and Common Commands

Show files contentCommon commands

The cat command:

Argument Definitions

file A list of files to show/concatenate

cat [file ...]

cat file1.txtcat part1.txt part2.txt

Example:

Page 37: Linux Filesystem and Common Commands

Output textCommon commands

The echo command:

Option Definitions

-e Interpret escape sequences

echo [options] text

echo “Test string”echo -e “There is a newline\nhere”

Example:

Page 38: Linux Filesystem and Common Commands

Stop-and-thinkCommon commands

Do you have any questions ?

Page 39: Linux Filesystem and Common Commands

Stop-and-thinkCommon commands

Relative path

Absolute path

The ~ symbol expands to the current user home directory. It’s a :

Page 40: Linux Filesystem and Common Commands

Stop-and-thinkCommon commands

Relative path

Absolute path

The ~ symbol expands to the current user home directory. It’s a :

Page 41: Linux Filesystem and Common Commands

Streams and redirections

STDOUT and friends.

Filesystem and common commands

Page 42: Linux Filesystem and Common Commands

I/O StreamsStreams and redirections

STDIN (0)

Read only

Data source

Default: keyboard

STDOUT (1)

Write-only

Default: screen

STDERR (2)

Write-only

Separate errors

Default: screen

Each process (shell incl) works with 3 streams:

Page 43: Linux Filesystem and Common Commands

RedirectionsStreams and redirections

Process

3 Streams

Like chip pins

Can be connected

Combine programs

Achieve complex process

Using simple tools

Redirections

Plug pins

Unix fundamentals: Connecting programs

Page 44: Linux Filesystem and Common Commands

RedirectionsStreams and redirections

Redirection operators:

> file

< file

>> file

2>&1

Write the result of a command to a file.If the file exist it’ll be overwritten.

Read file as standard input

Append the result of the command at the end of file. The file content is not overwritten.

Rewrite the error output to the standard output

Example :

[user@linux ~]$ ls -l >> file

Page 45: Linux Filesystem and Common Commands

PipesStreams and redirections

The pipe “ | ” allows to send the result of a command to another.

Example :

[user@linux ~]$ command1 | command2

[user@linux ~]$ ps ax | grep tty8853 tty1 Ss+ 0:00 /sbin/agetty 38400 tty1 linux8856 tty2 Ss+ 0:00 /sbin/agetty 38400 tty2 linux8857 tty3 Ss+ 0:00 /sbin/agetty 38400 tty3 linux8858 tty4 Ss+ 0:00 /sbin/agetty 38400 tty4 linux8859 tty5 Ss+ 0:00 /sbin/agetty 38400 tty5 linux8860 tty6 Ss+ 0:00 /sbin/agetty 38400 tty6 linux

Page 46: Linux Filesystem and Common Commands

Stop-and-thinkStreams and redirections

Do you have any questions ?

Page 47: Linux Filesystem and Common Commands

Stop-and-thinkStreams and redirections

Redirections

Pipe

You want to feed program2 with program1 output. Which feature will you use?

Page 48: Linux Filesystem and Common Commands

Stop-and-thinkStreams and redirections

Redirections

Pipe

You want to feed program2 with program1 output. Which feature will you use?

Page 49: Linux Filesystem and Common Commands

Streams and plumbing

File attributes Unix filesystem

Working with files and

directories

Course summary

Mounting concept

Filesystem and common commands

Page 50: Linux Filesystem and Common Commands

For moreFilesystem and common commands

CoursesPublications

Web sites

www.labo-linux.com

www.blackbeltfactory.com

Linux Technologies: Edge Computing

Conferences

FOSDEM

RMLL

Solutions Linux

If you want to go into these subjects more deeply, …

www.supinfo.com

Linux in a nutshell

Page 51: Linux Filesystem and Common Commands

Congratulations

You have successfully completed the SUPINFO course module n°02

Filesystem and common commands

Page 52: Linux Filesystem and Common Commands

The end

The TAB key: Use and abuse autocompletion Lost? Let pwd be your guide.

Filesystem and common commands