Transcript of "Nguyễn Vũ Hưng: Basic Linux Power Tools "

1.
The Unix and GNU/Linux Command Line Nguyen Vu Hung – VINICORP [email_address] 2010/09/21 Based on “intro_unix_linux” by Michael Opdenacker from Free Electrons

2.
Best viewed with... This document is best viewed with a recent PDF reader or with OpenOffice.org itself! <ul><li>Take advantage of internal or external hyperlinks. So, don’t hesitate to click on them!

4.
Use thumbnails to navigate in the document in a quick way </li></ul>

5.
Command memento sheet It is a useful companion to this presentation. Examples for the most useful commands are given in just one sheet. Suggestions for use Stick this sheet on your wall, use it as desktop wallpaper, make it a mouse mat, print it on clothing, slice it into bookmarks... Caution Store away from mice!

54.
File paths A path is a sequence of nested directories with a file or directory at the end, separated by the / character <ul><li>Relative path: documents/fun/microsoft_jokes.html Relative to the current directory

73.
Much simpler and consistent syntax (not POSIX compliant) Makes it easier to create shell scripts. </li></ul>Command line beginners can learn much faster! Even experienced users should find this shell very convenient.

78.
ls -ltr (options can be combined) Long listing, most recent files at the end </li></ul>Lists the files in the current directory, in alphanumeric order, except files starting with the “ . ” character.

79.
File name pattern substitutions Better introduced by examples! <ul><li>ls *txt The shell first replaces *txt by all the file and directory names ending by txt (including .txt ), except those starting with . , and then executes the ls command line.

80.
ls -d .* Lists all the files and directories starting with . -d tells ls not to display the contents of directories.

81.
cat ?.log Displays all the files which names start by 1 character and end by .log </li></ul>

82.
Special directories (1) ./ <ul><li>The current directory. Useful for commands taking a directory argument. Also sometimes useful to run commands in the current directory (see later).

94.
Smart directory copy with rsync rsync (remote sync) has been designed to keep in sync directories on 2 machines with a low bandwidth connection. <ul><li>Only copies files that have changed. Files with the same size are compared by checksums.

108.
Displaying file contents Several ways of displaying the contents of files. <ul><li>cat file1 file2 file3 ... (concatenate) Concatenates and outputs the contents of the given files.

109.
more file1 file2 file3 ... After each page, asks the user to hit a key to continue. Can also jump to the first occurrence of a keyword ( / command).

110.
less file1 file2 file3 ... Does more than more with less. Doesn't read the whole file before starting. Supports backward movement in the file ( ? command). </li></ul>

111.
The head and tail commands <ul><li>head [-<n>] <file> Displays the first <n> lines (or 10 by default) of the given file. Doesn't have to open the whole file to do this!

112.
tail [-<n>] <file> Displays the last <n> lines (or 10 by default) of the given file. No need to load the whole file in RAM! Very useful for huge files.

113.
tail -f <file> (follow) Displays the last 10 lines of the given file and continues to display new lines when they are appended to the file. Very useful to follow the changes in a log file, for example.

124.
Symbolic links A symbolic link is a special file which is just a reference to the name of another one (file or directory): <ul><li>Useful to reduce disk usage and complexity when 2 files have the same content.

143.
Access right constraints <ul><li>x without r is legal but is useless You have to be able to read a file to execute it.

144.
Both r and x permissions needed for directories: x to enter, r to list its contents.

145.
You can't rename, remove, copy files in a directory if you don't have w access to this directory.

146.
If you have w access to a directory, you CAN remove a file even if you don't have write access to this file (remember that a directory is just a file describing a list of files). This even lets you modify (remove + recreate) a file even without w access to it. </li></ul>

168.
sort < participants.txt The standard input of sort is taken from the given file. </li></ul>sort takes its input from the standard input: in this case, what you type in the terminal (ended by [Ctrl][D] )

169.
Pipes <ul><li>Unix pipes are very useful to redirect the standard output of a command to the standard input of another one.

183.
Special devices (1) Device files with a special behavior or contents <ul><li>/dev/null The data sink! Discards all data written to this file. Useful to get rid of unwanted output, typically log information: mplayer big_buck_bunny_1080p_surround.avi &> /dev/null