Upload
mourad-mouradi
View
229
Download
1
Embed Size (px)
DESCRIPTION
Linux FileSystem and Common Command
Citation preview
Unix computing basicsCampus-Booster ID : **XXXXX
www.supinfo.comCopyright © SUPINFO. All rights reserved
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
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
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
Unix filesystem
Finding your way through.
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
WindowsUnix filesystem
UnixUnix filesystem
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
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 ?
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
Stop-and-thinkUnix filesystem
Do you have any questions ?
Stop-and-thinkUnix filesystem
I’m a file. I’ll sing out what’s written to me. I am:
___________
Stop-and-thinkUnix filesystem
I’m a file. I’ll sing out what’s written to me. I am:
___________/dev/dsp
Using the shell
Terminal, shell and console
Filesystem and common commands
DefinitionUsing the shell
Shell - also called "command interpreter“ executes commands that the user types.
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.
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
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
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
Stop-and-thinkUsing the shell
Do you have any questions ?
Stop-and-thinkUsing the shell
The terminal
The console
A TTY
The Shell
The prompt is provided by:
Stop-and-thinkUsing the shell
The terminal
The console
A TTY
The Shell
The prompt is provided by:
Common commands
Survival kit
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
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
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
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
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 ~]$
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
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
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.
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:
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
Creating directoriesCommon commands
The mkdir command:
Option Definitions
-p Create parent directories as needed
mkdir [options] directory
mkdir tinkeringmkdir -p /var/tmp/workspace
Example:
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:
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:
Stop-and-thinkCommon commands
Do you have any questions ?
Stop-and-thinkCommon commands
Relative path
Absolute path
The ~ symbol expands to the current user home directory. It’s a :
Stop-and-thinkCommon commands
Relative path
Absolute path
The ~ symbol expands to the current user home directory. It’s a :
Streams and redirections
STDOUT and friends.
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:
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
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
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
Stop-and-thinkStreams and redirections
Do you have any questions ?
Stop-and-thinkStreams and redirections
Redirections
Pipe
You want to feed program2 with program1 output. Which feature will you use?
Stop-and-thinkStreams and redirections
Redirections
Pipe
You want to feed program2 with program1 output. Which feature will you use?
Streams and plumbing
File attributes Unix filesystem
Working with files and
directories
Course summary
Mounting concept
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
Congratulations
You have successfully completed the SUPINFO course module n°02
Filesystem and common commands
The end
The TAB key: Use and abuse autocompletion Lost? Let pwd be your guide.
Filesystem and common commands