Linux Web Hosting

Linux Operating Sistem

74 Hour 5 What Are Regular Expressions? Regular

Filed under: Learn Linux in 24 hours — webmaster @ 8:20 pm

74 Hour 5 What Are Regular Expressions? Regular expressions are patterns, using special syntax, that match strings (usually in text in files, unless your search is for filenames). There are also extended regular expressions, but the difference, important for syntax, should not deter you from the valuable lesson of being able to construct patterns that will accurately match your desired search targets. This is important if you re looking for text in files, and critical if you re performing potentially dangerous tasks, such as multiple file deletions across your system. You can build an infinite number of regular expressions using only a small subset of pattern characters. Here s a short list of some of these characters. You should be familiar with at least one (the asterisk) from the previous examples: * Matches any character ? or . Matches a single character [xxx] or [x-x] Matches a character in a range of characters x Matches a character such as ? or ^pattern Matches pattern to the beginning of a line $pattern Matches pattern to the end of a line This is not a comprehensive list of pattern characters. For more details, you can read the ed manual page (the ed command is discussed in Hour 14, Text Processing ). For now, try several simple examples using different patterns. You should know the asterisk, which is useful for finding matches to all characters. For example, if you want to find all the text files in your directory with an extension of .txt, you can use # ls *.txt 14days.txt 96hours.txt datalog.txt datebook.txt day67.txt But suppose you wanted a list of all files in your directory with numbers in the filename? You can try to string multiple searches on the ls command line, like this: # ls *0* *1* *2* *3* *4* *5* *6* *7* *8* *9* 08100097.db 14days.txt backup001.file phonelog.111597 08100097.db 32days.msg day67.txt phonelog.111597 08100097.db 32days.msg day67.txt phonelog.111597 08100097.db 96hours.txt message.76 08100097.db 96hours.txt message.76 14days.txt backup001.file phonelog.111597 Obviously, this is not the result you want, because the multiple searches have printed duplicate filenames. To find exactly what you want, use a regular expression that tells ls to list any file with a number appearing in the filename, for example: # ls *[0123456789]* 0001file.0009 32days.msg day67.txt 5

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Unix Web Hosting services

Linux Operating Sistem

Manipulation and Searching Commands 71 tempdir3 `– tempdir2

Filed under: Learn Linux in 24 hours — webmaster @ 1:22 pm

Manipulation and Searching Commands 73 Runs commands through mouse clicks Extensive, built-in hypertext help screens Emulates and supports the ls, cp, ln, mv, mkdir, rmdir, rm, cd, pwd, find, chown, chgrp, and tree commands Compares directory contents Uses customized menus so you can build your own commands Can use network links for telnet or FTP operations (see Hour 13, Internet Downloading and Browsing ) Offers mouse-click decompression of files (see gzip) Can undelete files (if your Linux filesystem is configured to support this) Figure 5.1. The Midnight Commander visual shell displays a graphical interface to Linux file commands. 5 Midnight Commander is a handy and convenient tool to use for file handling and directory navigation. You will have to invest some time in learning how to use this program, but if you ve used similar file-management interfaces, you ll feel right at home. Searching Files This section introduces you to the use of sophisticated wildcards, or regular expressions, along with short examples of file searches using the grep family of programs. If you understand and use these expressions, you ll be able to create refined search techniques you ll use again and again. You ll save time and effort during your work, and your learning investment will pay big dividends throughout your Linux experience.

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Unix Web Hosting services

Linux Operating Sistem

68 Hour 5 Renaming Files with the mv

Filed under: Learn Linux in 24 hours — webmaster @ 5:18 am

Manipulation and Searching Commands 69 Here, the mv command asks if you want to overwrite the file (but will keep quiet if no overwriting takes place, even if you use -i). You can also combine the -band -ioptions with # mv -bi file2 file3 Now that you ve seen how to delete, rename, or move your files, how do you copy files? Copying with the cp Command The cp, or copy, command is used to copy files or directories. This command has nearly 40 command-line options. They won t all be covered here, but you ll learn about some of the most commonly used options, which will save you time and trouble. You ll most likely first use cp in its simplest form, for example: # cp file1 file2 This creates file2, and unlike mv, leaves file1 in place. But you must be careful when using cp, because you can copy a file onto a second file, effectively replacing it! In this regard, cp can act just like mv. To show you how this can happen, try creating three files, each with a line of text, using the cat command: # cat > file1 this is file1 # cat > file2 this is file 2 # cat > file3 this is the third file # ls -l file* -rw-rw-r–1 bball bball 14 Nov 13 16:12 file1 -rw-rw-r–1 bball bball 15 Nov 13 16:12 file2 -rw-rw-r–1 bball bball 23 Nov 13 16:12 file3 Now, copy a file onto another file, then check the file sizes and the contents of the new file: # cp file1 file2 # ls -l file* -rw-rw-r–1 bball bball 14 Nov 13 16:12 file1 -rw-rw-r–1 bball bball 14 Nov 13 16:14 file2 -rw-rw-r–1 bball bball 23 Nov 13 16:12 file3 # cat file2 this is file1 It should be obvious that file1has replaced file2. To avoid this problem (unless you really want to overwrite the file), you can use the -b or -i options, which work just like mv. Here s an example: # cp -i file1 file2 cp: overwrite `file2′? n # cp -bi file1 file2 cp: overwrite `file2′? y # ls file* file1 file2 file2~ file3 5

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Linux Web Hosting services

Linux Operating Sistem

68 Hour 5 Renaming Files with the mv

Filed under: Learn Linux in 24 hours — webmaster @ 5:18 am

70 Hour 5 Note that file2, which was overwritten, was backed up. The cp command may also be used to copy a number of files at one time. The following example shows how to copy all of the files in directory tempdir1 to directory tempdir2: # cp tempdir1/* tempdir2 # tree tempdir2 tempdir2 |– temp1file1 |– temp1file2 `– temp1file3 0 directories, 3 files Like the rm command, cp also has a -r, or recursive, option. You can use this option to copy one directory into another. For example, to copy the tempdir1 directory and its files into tempdir2, use this syntax: # cp -r tempdir1 tempdir2 # tree tempdir2 tempdir2 |– temp1file1 |– temp1file2 |– temp1file3 `– tempdir1 |– temp1file1 |– temp1file2 `– temp1file3 1 directory, 6 files Finally, the cp command has the -poption, which is similar to mkdir s -p option. Normally, when you copy a file inside several directories into another directory, only the file is copied. The following example will only copy temp1file1 into tempdir3: # tree tempdir2 tempdir2 |– temp1file1 |– temp1file2 |– temp1file3 `– tempdir1 |– temp1file1 |– temp1file2 `– temp1file3 1 directory, 6 files # cp tempdir2/tempdir1/temp1file1 tempdir3 However, what if you d like a file, along with its directory structure, copied? To do this, you can use the -P option: # cp -P tempdir2/tempdir1/temp1file1 tempdir3 # tree tempdir3 5

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Linux Web Hosting services

Linux Operating Sistem

68 Hour 5 Renaming Files with the mv

Filed under: Learn Linux in 24 hours — webmaster @ 5:18 am

68 Hour 5 Renaming Files with the mv Command The mv command, called a rename command but known to many as a move command, will indeed rename files or directories, but it will also move them around your file system. Actually, in the technical sense, the files or directories are not really moved. If you insist on knowing all the gory details, read the Linux System Administrator s Guide, available through http://sunsite.unc.edu/LDP/LDP/sag/index.html In its simplest form, mv can rename files, for example: # touch file1 # mv file1 file2 This command renames file1 to file2. However, besides renaming files, mv can rename directories, whether empty or not, for example: # mkdir -p temp/temp2/temp3 # mv temp newtemp Although mvhas nine different options, this section concentrates on the two most commonly used. These options, -b and -i, allow you to use mv in a fairly safe way, because mv will not only rename, but overwrite silently and quickly! The first option, -b, creates a backup of any file or directory you rename to an existing name, for example: # touch file1 file2 file3 # ls file* file1 file2 file3 # mv file1 file2 # ls file* file1 file2 As you can see, without using -b, mv not only renamed file1 to file2, but deleted file2 in the process. Is this dangerous? You bet! Now, try the -b option: # touch file1 # ls file* file1 file2 file3 # mv -b file1 file2 # ls file* file2 file2~ file3 This example shows that although file1 has been renamed, replacing file2, a backup of file2 with a default extension of the tilde (~) has been created. The mvcommand can work silently, or as with rm, you can use the -i(interactive) option, for example: # mv -i file2 file3 # mv -i file2 file3 mv: replace `file3′? y 5

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Linux Web Hosting services

Linux Operating Sistem

Manipulation and Searching Commands 65 Always running Linux

Filed under: Learn Linux in 24 hours — webmaster @ 11:09 pm

Manipulation and Searching Commands 65 Always running Linux while logged in as the root operator and using the rm command has caused many untold tales of woe and grief. Why? Because with one simple command you can wipe out not only your Linux system, but also any mounted filesystems, including DOS partitions, flash RAM cards, or removable hard drives, as follows: # rm -fr /* This command removes all files and directories recursively (with the -r option), starting at the root or /directory. If you must run Linux as root, make sure to back up your system, and read Hour 23, Archiving. The rm command will delete one or several files from the command line. You can use any of the following: # rm file # rm file1 file2 file2 # rm file* One of the safer ways to use rmis through the -ior interactive option, where you ll be asked if you want to delete the file, for example: # rm -i new* rm: remove `newfile ? y rm: remove `newfile2′? y You can also force file deletion by using the -f option, as in # rm -f new* However, if rm finds a directory, even if it is empty, it will not delete the directory, and complains, even if you use -f, as in the following: # rm -f temp* rm: temp: is a directory rm: temp2: is a directory When you combine -f and -r, the recursive option, you can delete directories and all files or directories found within (if you own them; see Hour 21, Handling Files ), as in the following example: # rm -fr temp* The -fr option also makes rm act like the rmdir command (discussed later in this chapter). Use this option with caution! Some X Window managers, such as CDE, or utilities, such as TkDesk, offer trash can approaches to deleting files, but the files are not really deleted, just moved to a temporary directory. This is a safe, but not fail-safe, approach to deleting or recovering files. You may also be able to use the mccommand, or Midnight Commander, discussed later in this chapter. 5

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Unix Web Hosting services

Linux Operating Sistem

62Hour44

Filed under: Learn Linux in 24 hours — webmaster @ 5:16 pm

62Hour44

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Inexpensive Web Hosting services

Linux Operating Sistem

62Hour44

Filed under: Learn Linux in 24 hours — webmaster @ 5:16 pm

II PART Hour 5 Manipulation and Searching Commands In this hour, you ll learn about creating, copying, deleting, and moving files and directories. You ll also learn about searching through files and how to compress and uncompress files. This information will build on information you ve learned in the last hour, and the commands you learn here will be used later on in this book. Manipulating Files or Directories Using Linux isn t different from any other computer operating system. You create, delete, and move files on your hard drive in order to organize your information and manage how your system works or looks. This section shows you how to do these tasks quickly and easily. Although the graphical interface for Linux, the X Window System, may offer drag and drop or multiple selections in order to copy or delete files, many of the commands you ll learn here form the base of these operations. It is worth knowing how these programs work, even if you don t use Linux in the console mode.

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Inexpensive Web Hosting services

Linux Operating Sistem

Reading and Navigation Commands 59 The more command

Filed under: Learn Linux in 24 hours — webmaster @ 10:15 am

Reading and Navigation Commands 61 cmcia/fixed_cs.o Nov 12 21:02:03 localhost kernel: hdc: SunDisk SDCFB-4, 3MB w/1kB Cache, LBA, CH S=123/2/32 Nov 12 21:02:03 localhost kernel: ide1 at 0×100-0×107,0×10e on irq 3 Nov 12 21:02:03 localhost kernel: hdc: hdc1 Nov 12 21:02:03 localhost cardmgr[152]: executing: ./fixed start hdc Nov 12 21:02:03 localhost cardmgr[152]: initializing socket 1 Nov 12 21:02:03 localhost cardmgr[152]: socket 1: Serial or Modem Card Nov 12 21:02:03 localhost kernel: tty01 at 0×02f8 (irq = 5) is a 16550A Nov 12 21:02:03 localhost cardmgr[152]: executing: insmod /lib/modules/2.0.30/p cmcia/serial_cs.o Nov 12 21:30:17 localhost PAM_pwdb[556]: (su) session opened for user root by bball(uid=0) Being able to read large files in this way is convenient, considering that the system messages can grow to more than a million characters. 4

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Linux Web Hosting services

Linux Operating Sistem

Reading and Navigation Commands 59 The more command

Filed under: Learn Linux in 24 hours — webmaster @ 10:15 am

60 Hour 4 The headcommand has a number of options besides the traditional -n, which prints the first n lines of a file. You ll find that the head command in your Linux distribution, which is part of the GNU text utilities, will also print any number of 512-character, 1-kilobyte (1024 bytes), or megabyte-sized blocks from the beginning of a file. Like the cat command, head can also handle binary files. If you use headin the traditional way, you strip off lines from the beginning of one or several files. For example, if you d like to do a quick check of the formatting of all the manual pages for programs with names beginning with xm under the /usr/man/man1 directory, you can use the following command: # head -5 /usr/man/man1/xm*.1 ==> /usr/man/man1/xmpeg.1 <== .TH XMPEG 1 6 FEBRUARY 1993 X Version 11 .SH NAME xmpeg - X11 MPEG-Player [Version 1.0] .SH SYNOPSIS .B xmpeg ==> /usr/man/man1/xmplay.1 <== .TH XMPLAY 1 6 FEBRUARY 1993 X Version 11 .SH NAME xmplay - X11 directory browser for xmpeg [Version 1.0] .SH SYNOPSIS .B xmplay Note that the default output from the head command is to include the filename. If you d prefer just to have the information, use the -q option, for example: # head -5 -q /usr/man/man1/xm*.1 .TH XMPEG 1 6 FEBRUARY 1993 X Version 11 .SH NAME xmpeg - X11 MPEG-Player [Version 1.0] .SH SYNOPSIS .B xmpeg .TH XMPLAY 1 6 FEBRUARY 1993 X Version 11 .SH NAME xmplay - X11 directory browser for xmpeg [Version 1.0] .SH SYNOPSIS .B xmplay The tail command is especially useful when you re faced with the task of reading through large files where the most useful information is at the end of the file. One example task is if you want to look at the system messages for errors. One message file, located in /var/log, contains details of system operations, but the log is updated at the end of the message file (in other words, text is appended, so the most recent messages are at the end of the file). To look at the last 12 lines in the message file using tail, make sure you re logged in as root, and type # tail -12 /var/log/messages Nov 12 21:02:02 localhost cardmgr[152]: initializing socket 0 Nov 12 21:02:02 localhost cardmgr[152]: socket 0: ATA/IDE Fixed Disk Card Nov 12 21:02:02 localhost cardmgr[152]: executing: insmod /lib/modules/2.0.30/p 4

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Linux Web Hosting services

« Previous PageNext Page »

Powered by Linux Web Hosting