Example: confidence

Linux Fundamentals by Commands and Examples

Linux Fundamentals by Commands and Examples version Editor: Ahmed Baraka Document Purpose This document is edited to be a quick reference of Linux essential Commands . It can be used by Linux beginners as a reminder of basic Linux Commands usage. It cannot be used to learn Linux from scratch. The document is oriented based on the required task, the command (s) to do the task, basic syntax of the command , and Examples . No explanation will be presented. Usage Terms Anyone is authorized to copy this document to any means of storage and present it in any format to any individual or organization for non-commercial purpose free. No individual or organization may use this document for commercial purpose without a written permission from the editor. There is no warranty of any type for the code or information presented in this document.

Linux Essentials article by Thomas Girke. The Linux Cookbook: Tips and Techniques for Everyday Use by Michael Stutz . Red Hat Linux Getting Started Guide, 2003

Tags:

  Linux, Example, Fundamentals, Command, Linux fundamentals by commands and examples

Information

Domain:

Source:

Link to this page:

Please notify us if you found a problem with this document:

Other abuse

Transcription of Linux Fundamentals by Commands and Examples

1 Linux Fundamentals by Commands and Examples version Editor: Ahmed Baraka Document Purpose This document is edited to be a quick reference of Linux essential Commands . It can be used by Linux beginners as a reminder of basic Linux Commands usage. It cannot be used to learn Linux from scratch. The document is oriented based on the required task, the command (s) to do the task, basic syntax of the command , and Examples . No explanation will be presented. Usage Terms Anyone is authorized to copy this document to any means of storage and present it in any format to any individual or organization for non-commercial purpose free. No individual or organization may use this document for commercial purpose without a written permission from the editor. There is no warranty of any type for the code or information presented in this document.

2 The editor is not responsible for any loses or damage resulted from using the information or executing the code in this document. If any one wishes to correct a statement or a typing error or add a new piece of information, please send the request to . If the modification is acceptable, it will be added to the document, the version of the document will be incremented and the modifier name will be listed in the version history list. Page 1 Linux Fundamentals by Commands and Examples Version History Version Date Updates 25-June-2009 Initial document. Resources Resource Name Linux Essentials article by Thomas Girke. The Linux Cookbook: Tips and Techniques for Everyday Use by Michael Stutz Red Hat Linux Getting Started Guide, 2003 Red Hat Essentials RH033 (courseware material)

3 Linux Reviews website The Linux Tutorial website Zytrax Info website Academic Computing And Communications Center ACCC website The Linux Information Project website UNIX & Linux Shell Scripting Tutorial website Page 2 Linux Fundamentals by Commands and Examples Contents Introduction _____ 7 Unix variants _____7 GNU/ Linux distributions _____7 Getting Started _____ 8 Virtual Consoles _____8 Changing password _____8 Logging-In_____8 Date and Time Commands _____8 Making Arithmetic Calculations _____8 Generating Sequential Numbers _____8 Getting Help _____9 Handy shortcuts _____9 Managing Files and Directories_____ 10 Files and Directories Commands _____10 Determining File Content_____11 Viewing Files _____11 Hard and Symbolic (Soft) Links_____12 Checking Free Space _____12 Searching Files By Names _____12 Searching Files By Names and Attributes _____12 Archiving Files _____14 Compression Utilities _____14 Text File Processing Tools _____14 Users.

4 Groups and Permissions _____ 15 Change Password _____15 Change Your Identity _____15 User Information Commands _____15 Changing File Ownership_____15 Changing Permissions _____15 Default File Permission _____15 Special Permission _____16 Page 3 Linux Fundamentals by Commands and Examples bash Shell Basics _____ 17 File Blobbing _____17 History Tricks _____17 command Line Expansion _____17 Local Shell Variables _____18 Aliases_____19 Type _____19 Environment Variables _____19 Showing Path of Executable _____19 Login and Non-Login Shells _____20 Startup and Logout Scripts _____20 Recording a Shell Session _____20 Standard I/O and Pipes _____ 21 Redirecting Output to a File _____21 Redirecting STDOUT to a Program (Piping)_____21 Redirecting to Multiple Targets _____21 Redirecting STDIN from a File _____21 Sending Multiple Lines to STDIN _____21 Text Files and String Manipulation _____ 22 Viewing File Contents _____22 Viewing File Excerpts _____22 Extracting Text by Column _____22 Gathering Text Statistics _____22 Sorting Text_____23 Eliminating Duplicates_____23 Comparing Files_____23 Spell Checking with aspell_____23 Converting Characters_____24 Combining Files _____24 Expanding Tabs Into Spaces _____24 Regular Expressions _____24 Extended Regular Expressions _____25 Extracting Text by Keyword _____25 Search and Replace _____26 Page 4 Linux Fundamentals by Commands and Examples Editing Text by Programming Language _____26 Using the Text Editor vi _____ 27 Modes _____27 Search and Replace ( command Mode)

5 _____27 Manipulating Text ( command Mode)_____27 Undoing Changes ( command Mode) _____28 Visual Mode _____28 Using Multiple "windows" _____28 Configuring vi and vim _____28 Managing Processes _____ 29 Listing Processes_____29 Sending Signals to Processes _____31 Changing Process Scheduling Priority _____31 Listing Background and Suspended Jobs_____31 Resuming Suspended Jobs _____31 Compound Commands _____32 Scheduling a Process_____32 Scheduling a Process Periodically _____32 bash Shell Scripting Basics _____ 33 Creating Shell Scripts _____33 Handling Input _____33 Shell Script Debugging _____33 Handling Positional Parameters (Arguments) _____33 Using Functions _____34 Exit Status _____34 Conditional Execution _____34 Using the if Statement_____34 Using the Case Statement _____35 Using the For Loop _____35 Using the While loop _____35 Disrupting Loops _____36 File Tests _____36 String Tests _____37 Page 5 Linux Fundamentals by Commands and Examples Shell Option Test _____37 Logical Tests _____37 Comparison _____37 Page 6 Linux Fundamentals by Commands and Examples Introduction Unix variants Unix, GNU/ Linux , Solaris, IRIX, HP-UX, FreeBSD, OpenBSD, NetBSD, Darwin (Mac), and GNU/ Linux distributions Ubuntu, Edubuntu, Debian, RedHat, Fedora, Slackware, SuSE, Darwin, and Family tree of the GNU/ Linux distributions Page 7 Linux Fundamentals by Commands and Examples Getting Started Virtual Consoles In Red Hat.

6 Available through CTRL+ALT+F[1-6] If X is running, it is available as CTRL+ALT+F7 Changing password passwd Logging-In From Mac or Linux ssh -X your_username@hostname From Windows: Open Putty and select ssh. Use WinSCP software for file exchange. Date and Time Commands date u display date and time in UTC R display date and time in RFC822 (used in email messages) chrony package maintains time by connecting to servers over the Internet. cal output a calendar for the current month y print calendar of current year cal 2010 #output a calendar for the year 2010 Making Arithmetic Calculations bc supported operators: + - * / % ^ sqrt() Generating Sequential Numbers seq w make all generated numbers of same width s 'b' make b character as the separator between numbers seq 7 seq -5 5 Page 8 Linux Fundamentals by Commands and Examples seq 1 2 10 # from 1 to 10 increment by 2 seq s ' ' 1 23 # separated by spaces Getting Help man info apropos search for only exact matches whatis to list a one line description of a program Software packages may store its help files in /usr/share/doc Online help.

7 SuperMan Pages, Linux Documentation Project (LDP) man ls man k copy # search for "copy" in the whatis database apropos copy # search for "copy" (not "xcopy") in the whatis database man f copy # restrict search for the whole word ls -- help # brief help usage info cp # information is organized into sections whatis who Handy shortcuts # up(down)_key scrolls through command history # <something-incomplete> TAB completes path/file_name # Ctrl+a # cursor to beginning of command line # Ctrl+e # cursor to end of command line # Ctrl+d # delete character under cursor # Ctrl+k # cut line from cursor into kill buffer # Ctrl+y # paste content from Ctrl k Page 9 Linux Fundamentals by Commands and Examples Managing Files and Directories Files and Directories Commands pwd cd ls (see the options in the example below) File types that may be listed by ls l.

8 - regular file d directory l symbolic link b block special file c character special file p named pipe s socket cp # for copying between hosts, see next section rm mv mkdir rmdir touch create empty files or update file timestamps File Name Expansion characters can be used with these Commands . cd .. # one level up cd # home directory cd - # previous directory ls a # include hidden files ls l # long listing ls R # recurses through subdirectories with contents ls d # directory names without their contents ls lh # print sizes in human readable format ls ld # avoid listing directory contents ls i # print index number ls S # sort by file size ls t # sort by modification time (newest first) ls r # reverse order while sorting ls l --time-style=STYLE # STYLE.

9 Full-iso, long-iso, iso, locale, +FORMAT cp file1 file2 # timestamp changes for the new file Page 10 Linux Fundamentals by Commands and Examples cp p file1 file2 # all of the attributes are preserved cp file1 dir1 cp file1 file2 dir1 cp ./dir1/* dir2 cp r dir1 dir2 # -r (same as -R) copy entire directory tree # links aren't copied, permissions aren't preserved cp a dir1 dir2 # copy the entire tree including permissions and links mv file1 file2 # renames directories or files mv file1 ./dir1 # moves file/directory as specified in path rm file1 # removes file name rm -r dir1 # removes directory including its content, rm -rf dir # 'f' argument turns confirmation off rm -- -myfile # the fielename containes hyphen touch {doc,sheet}_{jan,feb,mar} touch file{ }.

10 Txt Determining File Content file file myfile Viewing Files cat less less navigation Commands : space ahead one full screen ENTER ahead one line b back one full screen k back one line g top of the file G bottom of the file /text search forward for text (Regular Expressions can be used) n repeat last search N repeat backward last search q quit Page 11 Linux Fundamentals by Commands and Examples Hard and Symbolic (Soft) Links ln ls l in case of soft link, it displays the link name and the referenced file ln s filename Checking Free Space df space usage by file systems du disk space by directories and subdirectories df h # -h prints size in readable format du h s ~ # -s reports single directory summary Searching Files By Names locate [options] name(s) slocate [options] name(s)


Related search queries