Filesystem and common commands Unix computing basics Campus-Booster ID : **XXXXX www.supinfo.com Copyright SUPINFO. All rights reserved
Filesystem and common commands Your trainer Presenter s Name 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: presenter@supinfo.com
Filesystem and common commands Course objectives By completing this course, you will: n Talk about fs hierarchy. Forest vs tree. n Tell files from directories. Using the command line. n Guess where removable devices are. Mounting concept and conventions. n Navigate in the filesystem. And work with files and directories. n Combine tools. Using streams, pipes, and redirections.
Filesystem and common commands Course topics Course s plan: n Unix filesystem. Finding your way through. n Using the shell. Terminal shell and console. n Common commands. Survival kit. n Streams and redirections. STDOUT and friends.
Filesystem and common commands Unix filesystem Finding your way through.
Unix filesystem Forest vs Tree Unix vs Windows fs models n Windows n multi-root n One root per FS Disk drive n No single entry point n Forest n Unix n Single root n Single entry point n Tree
Unix filesystem Windows
Unix filesystem Unix
Unix filesystem Paths Relative vs Absolute n Absolute n aka Full path n Begins with a / /home/supinfo/ Documents/doc.txt n Can be (very) long n Relative n From the current working directory n CWD = /home/supinfo Documents/doc.txt
Unix filesystem Mounting What about removable devices? n Windows n Unix n New disk drive n Need to attach the new fs to the existing hierarchy n Bind a filesystem to a directory n Usually under /mnt/ n mount command
Unix filesystem Everything is a file If not, it s a process n Devices exposed n Special files char block n /dev n Examples /dev/dsp /dev/sda n System settings n /proc/sys/
Unix filesystem Stop-and-think Do you have any questions?
Unix filesystem Stop-and-think I m a file. I ll sing out what s written to me. I am: u
Unix filesystem Stop-and-think I m a file. I ll sing out what s written to me. I am: u /dev/dsp
Filesystem and common commands Using the shell Terminal, shell and console
Using the shell Definition Shell - also called "command interpreter executes commands that the user types.
Using the shell The prompt 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. Username Current working directory Path [supinfo@linux-tpl1:~/documents]$ Hostname Privilege level $ for regular users # for root
Using the shell Terminal, shell and console n Terminal n Hardware n Connected to the server n Terminal emulator n Software n Understand the original protocol (VTx) n Shell n User interact with it through the terminal n TTY/Console n Generic term for any {STDIN,STDOUT,STDERR} tuple
Using the shell Terminal example n Bull Questar 4000 n Many stations n screen, keyboard n One server (the cube) n Used by French administration(trésor Public) n Original terminals until late 90 s n Moved to terminal emulators running on PC s in the early 2k s
Using the shell Virtual Terminals Old concepts, modern hardware n TTY subsystem n Generic Local/Network n Virtual terminals n Like workspaces n Available through alt +F1..F6 ctrl from X n Different from terminal emulators
Using the shell Stop-and-think Do you have any questions?
Using the shell Stop-and-think The prompt is provided by: The terminal The console A TTY The Shell
Using the shell Stop-and-think The prompt is provided by: The terminal The console A TTY The Shell
Filesystem and common commands Common commands Survival kit
Common commands Listing files Good ol list segments from multics. ls [options] file-expression Option Definitions -l -h Long listing: Mode, owner, size,... Human-readable file size -a Also list hidden files Example: ls -lh *.zip
Common commands Globbing Matching files using joker characters * Corresponds to none or some characters.? Corresponds to one character. [a-z] [^a-z] Corresponds to all the letters between a and z Corresponds to all the characters except the letters between a and z. [user@linux ~]$ ls [b-c]*.txt batman.txt chocolate.txt
Common commands File properties Anatomy of a ls -l File mode bitfield represent permissions and file type mode User owner and group owner Ownership Last modification date (mtime) File -rwxr-xr-x 1 user group 64 Nov 29 17:07 file.txt Hard links Number of hard links. File size In bytes. Use -h to get humanreadable sizes. Filename
Common commands The current working directory n To get the current working directory [user@linux bin]$ pwd /usr/bin n To move into a directory : [user@linux ~]$ cd directory n directory : relative or absolute path.
Common commands The current working directory n To get back to the home directory cd or cd ~ [user@linux bin]$ pwd /usr/bin [user@linux bin]$ cd ~ [user@linux ~]$ pwd /home/user n To get back to the previous directory cd - : [user@linux ~]$ cd /usr/bin [user@linux bin]$ cd - [user@linux ~]$
Common commands Copying files The cp command: cp [options] source destination Option Definitions -r -f Recursively copy directories Delete destination if exists -p Preserve ownership Example: cp -p /etc/lilo.conf./lilo.conf
Common commands Delete files The cp command: rm [options] file... -r, -R -f Option Definitions Recursively delete directories Don t prompt for confirmation -i Prompt for confirmation Example: rm -Rf ~
Common commands Rename/move files The mv command: mv [options] source destination Option Definitions -f -i -b Don t prompt before overwrite Prompt before overwrite Create a backup of existing destination before overwriting. Example: mv texst.txt test.txt mv /etc/lilo.conf.
Common commands Creating links The ln command: ln [options] source link-name Option Definitions -s Create symlinks Example: ln -s /etc/init.d/apache2 S99apache2 ln ~/Documents/file.txt.
Common commands Links Symlinks vs hardlinks n Symlink n To the name/path n Like Windows shortcuts n Use an inode n Hardlinks n Other pointer to the same content n Cannot point outside the filesystem/partition
Common commands Creating directories The mkdir command: mkdir [options] directory Option Definitions -p Create parent directories as needed Example: mkdir tinkering mkdir -p /var/tmp/workspace
Common commands Show files content The cat command: cat [file...] file Argument Definitions A list of files to show/concatenate Example: cat file1.txt cat part1.txt part2.txt
Common commands Output text The echo command: echo [options] text Option Definitions -e Interpret escape sequences Example: echo Test string echo -e There is a newline\nhere
Common commands Stop-and-think Do you have any questions?
Common commands Stop-and-think The ~ symbol expands to the current user home directory. It s a : Relative path Absolute path
Common commands Stop-and-think The ~ symbol expands to the current user home directory. It s a : Relative path Absolute path
Filesystem and common commands Streams and redirections STDOUT and friends.
Streams and redirections I/O Streams Each process (shell incl) works with 3 streams: n STDIN (0) n Read only n Data source n Default: keyboard n STDOUT (1) n Write-only n Default: screen n STDERR (2) n Write-only n Separate errors n Default: screen
Streams and redirections Redirections Unix fundamentals: Connecting programs n Process n 3 Streams Like chip pins n Can be connected n Combine programs n Achieve complex process n Using simple tools n Redirections n Plug pins
Streams and redirections 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 n Example : [user@linux ~]$ ls -l >> file
Streams and redirections Pipes n The pipe allows to send the result of a command to another. [user@linux ~]$ command1 command2 n Example : [user@linux ~]$ ps ax grep tty 8853 tty1 Ss+ 0:00 /sbin/agetty 38400 tty1 linux 8856 tty2 Ss+ 0:00 /sbin/agetty 38400 tty2 linux 8857 tty3 Ss+ 0:00 /sbin/agetty 38400 tty3 linux 8858 tty4 Ss+ 0:00 /sbin/agetty 38400 tty4 linux 8859 tty5 Ss+ 0:00 /sbin/agetty 38400 tty5 linux 8860 tty6 Ss+ 0:00 /sbin/agetty 38400 tty6 linux
Streams and redirections Stop-and-think Do you have any questions?
Streams and redirections Stop-and-think You want to feed program2 with program1 output. Which feature will you use? Redirections Pipe
Streams and redirections Stop-and-think You want to feed program2 with program1 output. Which feature will you use? Redirections Pipe
Filesystem and common commands Course summary File attributes Unix filesystem Working with files and directories Mounting concept Streams and plumbing
Filesystem and common commands For more If you want to go into these subjects more deeply, Publications Courses Linux Technologies: Edge Computing Linux in a nutshell Web sites www.supinfo.com www.labo-linux.com www.blackbeltfactory.com Conferences FOSDEM RMLL Solutions Linux
Congratulations You have successfully completed the SUPINFO course module n 02 Filesystem and common commands
Filesystem and common commands The end n The TAB key: Use and abuse autocompletion n Lost? Let pwd be your guide.