linux crash course chapter 03 3

39 138 0
 linux crash course chapter 03 3

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

Chapter 3: Command Line Utilities Doin’ stuff In this chapter … • Special characters • Redirection • More utilities than you shake a stick at Typing Commands • Beware of special characters • Characters that have special meaning to the shell • Shell expands, modifies and interprets special characters before issuing the command Special Characters • &;|*?‘“`[]()${}^#/\%!~+ • Plus whitespace (tabs, spaces, newlines) • Do not use these in filenames unless you have to • To use them, either put in single quotes, or proceed with a backslash – ls ‘filename with special chars!!’ – ls \[cat\] Special Characters con’t • All special characters have special meaning to the shell • We’ll explore these in great detail in upcoming chapters Utilities • Linux & Unix come with thousands of utilities • Some used explicitly, others implicitly • Some text-based, some GUI, some both Some tips before we start • Tab completion – When typing a filename or command name, you can type the first few letters then hit TAB to autocomplete the command • Pipe (|) symbol – Used to chain commands together – The output of one command becomes the input of another – We’ll revisit this in detail later ls: LiSt files • Used to list files contained in a directory • Can narrow the search using pattern matching • Examples – ls  displays ‘all’ the files in the directory – ls cats  displays the file cats in the directory – ls ca*  displays files starting with ‘ca’ cat: catenate a file • Displays the contents of one or more files • Beware – don’t try with binary files • Examples – cat myfile  displays contents of myfile – cat file1 file2  displays contents of file1 followed by contents of file2 rm: ReMoves a file • Similar to del in DOS • Use the –i option to invoke interactive mode, which prompts you if you’re sure • Examples: – rm myfile  deletes myfile – rm –i myfile  prompts you before deleting Text Converters • unix2dos and dos2unix • Unix and DOS use different end of line characters • Use these utilities when moving text files back and forth between Windows and Linux systems • Weird script error? Try dos2unix Compressing files • • • • bzip2 files gzip files compress files Each use their own algorithms and have their uses Uncompressing files • bunzip2 compressed-file • gunzip compressed-file • ucompress compressed-file tar: Tape ARchive • Packs and unpacks files from archives • *Does not compress, only assembles* • Tons of options, allowing you to add or remove files from archive, and also apply compression using third party support which: locates utilties • Will display the location of a utility • which ls  displays location of ls command you’re using • In case of there being multiple locations, which only displays the first (i.e., the one you will be using) whereis: locates utilities • Similar to which, but displays the utilities in a standard set of locations • The first one listed may not be the one you will issue when you enter the command • All depends on your PATH (chapter 4) Sidenote • which and whereis not list shell builtins • Shell builtins are functions that are internal to the shell itself – no binary executable • To see if you’re using a builtin, use type apropos: what I use? • Not sure what utility you’re looking for? • Try apropos keyword • Displays utilities and libraries related to your keyword • Found one, but not sure? whatis utility to show what it does, or check man page locate: search for files • System maintains a database of files • Your system administrator should configure a job to regularly update this database • Searches for any kind of file – not just utilities • Some systems use slocate (secure) • Latest distros use mlocate via locate who: Who’s online? • Displays what users are logged on • Also displays when they logged on, and with what device (terminal or console, etc) • Also try who am i finger: reach out and touch … • finger by itself displays users logged on like who, but also shows idle time and office location • finger username shows info about that user, like home directory, last logon, their shell, if they have unread mail, and plan and project files w: What’s up? • w is similar to who by showing who’s logged on • Also shows system uptime, and memory and CPU load averages • Good overall status of the system write: send a message • write username opens up a text-based chat with the user • Type message • Wait for response • CTRL-D to exit write mesg: Enable/disable write • Usage: mesg y|n • Turns off whether users can write you or not • Useful if you don’t want to be bugged mail: system mail • Our system is a closed system • You can send mail to other users on the system • No public mail ... characters have special meaning to the shell • We’ll explore these in great detail in upcoming chapters Utilities • Linux & Unix come with thousands of utilities • Some used explicitly, others implicitly... duh • Displays the end of a file • tail -X myfile displays the last X lines • Check out pg 8 43/ 7 83 for more options sort: displays sorted info • sort displays data in a sorted manner, without...In this chapter … • Special characters • Redirection • More utilities than you shake a stick at Typing Commands

Ngày đăng: 06/02/2018, 09:55

Mục lục

  • Chapter 3: Command Line Utilities

  • In this chapter …

  • Typing Commands

  • Special Characters

  • Special Characters con’t

  • Utilities

  • Some tips before we start

  • ls: LiSt files

  • cat: catenate a file

  • rm: ReMoves a file

  • more and less: pagers

  • hostname: Where am I?

  • cp: CoPies files

  • mv: MoVe files / change name

  • lpr: Line PRinter

  • grep: global regular expression print

  • head: display beginning

  • tail: duh

  • sort: displays sorted info

  • uniq: removes duplicates

Tài liệu cùng người dùng

Tài liệu liên quan