there be 句型ls an “f” ln flne.

My 10 UNIX Command Line Mistakes
≡ MenuHomeAboutContact / Email usAnyone who has never made a mistake has never tried anything new. -- Albert Einstein.Here are a few mistakes that I made while working at UNIX prompt. Some mistakes caused me a good amount of downtime. Most of these mistakes are from my early days as a UNIX admin. userdel CommandThe
/etc/deluser.conf
was configured
to remove the home directory
(it was done by previous sys admin and it was my first day at work) and mail spool of the user to be removed. I just wanted to remove the user account and I end up deleting everything (note -r was activated via deluser.conf): userdel fooRebooted Solaris BoxOn Linux killall command kill processes by name (killall httpd). On Solaris it kill all active processes. As root I killed all process, this was our main Oracle db box: killall process-nameDestroyed named.confI wanted to append a new zone to /var/named/chroot/etc/named.conf file., but end up running: ./ > /var/named/chroot/etc/named.confDestroyed Working Backups with Tar and Rsync (personal backups)I had only one backup copy of my QT project and I just wanted to get a directory called functions. I end up deleting entire backup (note -c switch instead of -x): cd /mnt/bacupusbharddisk tar -zcvf project.tar.gz functions I had no backup. Similarly I end up running rsync command and deleted all new files by overwriting files from backup set (now I’ve switched to rsnapshot) rsync -av -delete /dest /src Again, I had no backup.Deleted Apache DocumentRootI had sym links for my web server docroot (/home/httpd/http was symlinked to /www). I forgot about symlink issue. To save disk space, I ran rm -rf on http directory. Luckily, I had full working backup set.Accidentally Changed Hostname and Triggered False AlarmAccidentally changed the current hostname (I wanted to see current hostname settings) for one of our cluster node.
Within minutes I received an alert message on both mobile and email. hostname Public Network Interface ShutdownI wanted to shutdown VPN interface eth0, but ended up shutting down eth1 while
I was logged in via SSH: ifconfig eth1 downFirewall LockdownI made changes to sshd_config and changed the ssh port number from 22 to 1022, but failed to update firewall rules. After a quick kernel upgrade, I had rebooted the box. I had to call remote data center tech to reset firewall settings. (now I use firewall reset script to avoid lockdowns).Typing UNIX Commands on Wrong BoxI wanted to shutdown my local Fedora desktop system, but I issued halt on remote server (I was logged into remote box via SSH): halt service httpd stop Wrong CNAME DNS EntryCreated a wrong DNS CNAME entry
zone file. The end result - a few visitors went to /dev/null: echo 'foo
IN CNAME ' >>
&& rndc reloadFailed To Update Postfix RBL ConfigurationIn 2006 ORDB went out of operation. But, I failed to update my Postfix RBL settings. One day ORDB was re-activated and it was returning every IP address queried as being on its blacklist. The end result was a disaster.ConclusionAll men make mistakes, but only wise men learn from their mistakes -- Winston Churchill.From all those mistakes I’ve learnt that:Backup = ( Full + Removable tapes (or media) + Offline + Offsite + Tested )The clear choice for preserving all data of UNIX file systems is dump, which is only tool that guaranties recovery under all conditions. (see Torture-testing Backup and Archive Programs paper).Never use rsync with single backup directory. Create a snapshots using rsync or rsnapshots.Use CVS to store configuration files.Wait and read command line again before hitting the dam [Enter] key.Use your well tested perl / shell scripts and open source configuration management software such as puppet, Cfengine or Chef to configure all servers. This also applies to day today jobs such as creating the users and so on.Mistakes are the inevitable, so did you made any mistakes that have caused some sort of downtime? Please add them into the comments below.There is a Linux installation where almost EVERYONE has the same home directory (no need to store user-specific stuff on this machine, they all share the same .profile). From force of habit: userdel - ## because minion had left the company. -r wiped out the shared home dir for all users, including all the DBF files for the production Oracle database. About a day’s downtime.The same guy made a second mistake: logged in remotely to a Unix server, he goes: ifdown eth0; ## then intended to ifup eth0; to pick up a config change. But he couldn’t get his prompt back after the first command, I-)
He rang up and told someone to force the power off, then on.An entire group of suburbs without phone service for a day: some vague rumour about something misconfigured.One that I did myself: very early days of Unix – confusing rm instead of mv. It was only a single file deleted (the intended destination didn’t exist, and rm croaked with the error, which alerted me to the mistake). But it was still 2 hours recreating the C-program assignment from memory – some one else’s who I was helping.Another one I did myself: swapping between the CVS storage area, and the equivalent working directory in my home directory: wanted to delete part of the working directory tree and start over: rm -fr stem_of_ ## but in the CVS area, not mine. Got someone to restore from backups. It was a pretty rudimentary CVS setup.rm -i ## at least when you have your L-plates on (L-plates is Aus slang for “learner driver”).Only execute something as root if it won’ I generally have two windows open: my normal user and the root user, and I do things like ‘ls, cat, less’ in the normal window. Then I do things like vi, or rm as root (but I do a ls just before the rm, as root).I configure my root windows with a different background colour. prior to rm or recursive commands.prior to a recursive command on a small directory tree, find . - or, find . -type d - see how many files will be affected (or for slightly larger situations, the second one gives the range of directories to be affected).When I write a script to rename files or change them in a robotic manner, I put an echo in front of the intended command, so it will give me the commands that are going to happen. If satisfied, I remove the echo, to let the command actually happen.If I’m editing files in a robotic manner (by script), I create the new files with a backup extension (eg file.cxx becomes file.cxx.new). Then I diff the various original files against their new ones, to ensure it is as intended, then I rename the files, mv - and keep my eyes peeled as I say yes to each one.The & is your enemy. If I want to create a brand new file by redirection, I … cat brand_new_ (expect a not found error), then some-cmd & brand_new_If I want to append by redirection, I make a backup of the target file regardless.When I edit a config file in /etc (or anywhere), I … cp -i file.conf file.conf.; named after today’s date. The dates aren’t that truthful, but it’s miles better than anything.Create dedicated users for running VMs and similar (especially if they are shared). That’s the approach Apache uses (usually automated).Mount a partition and have a nosey prior to hosing it (sometimes it won’t work coz it’s never had anything in it, but still: if the mount unexectedly works …)Prior to removing a large directory tree, chmod 000; and/or, mv -i; to a new name, and leave it for a few days, to see if anything stops working.rpm –test as a non-root user, prior to the real rpm.Ironic: there’s an advert below this box saying OMG’S of the week (Telstra). Yes, it’s a bit like that.Next post: 20 Linux System Monitoring Tools Every SysAdmin Should KnowPrevious post: Lighttpd Traffic Shaping: Throttle Connections Per Single IP
(Rate Limit)UNIX Shell Skills & WordPress Codex
Interested in functions, hooks, classes, or methods? Check out the new !
UNIX Shell Skills
Note: This article covers an advanced topic.
If you have recently moved to
from a hosted blogging solution like Blogger or TypePad, you may be unfamiliar with the tasks of managing a webspace as well as a blog.
WordP many
use servers running Linux and A many web hosts offer not only web-based
to their customers but also
or . Many WordPress users may not be familiar with using the
to manage their file systems. This article explains the more commonly-used UNIX commands and demonstrates how a routine administrative task, namely a minor WordPress upgrade, is carried out in the shell.
is "a command line interface for WordPress". It's a great tool that can save you a lot of time if you know more about using shells.
The shell offered by your web host is likely to be , which stands for "Bourne Again Shell" after
who wrote the .
is distributed by the . There are a number of different Unix shells. The commands briefly described below apply to almost all of them.
(ssh) is a complete set of tools for remote administration of your website. It includes
(Secure File Transfer Protocol) for the uploading of files to your host. The main benefit of using
to interface with a remote server is increased security. With other server access tools, your login password may be transferred over the Internet in plain text, which may be intercepted.
under Windows, use
or , a UNIX-like environment for Windows. The
also supports sftp via ssh-2.
on a Mac running OS X, use the Terminal-based SSH program supplied with Mac OS X or download .
On Linux or UNIX-based operating systems, you can use the text-based SSH and SFTP clients from terminals such as Konsole, Gnome Terminal or xterm. Graphical FTP clients such as
also support .
Your hosting company will provide the username and host details
(the "shell account") necessary to use these. They may be different from the ones you use with your control panel. To use, at the Terminal prompt type ssh username@host or sftp username@host
If the SSH server you're connecting to is running on a non standard port, use the
argument, followed by the port number. So, for example, if the remote server SSH was running on port 1000 you would type
ssh username@host -p 1000
To use sftp to connect to a remote server on a non-standard port use the
-oPort= argument. So, for example, to connect to a remote server using sftp on port 1000 you would type sftp -oPort=1000 user@host
Before we get started with some UNIX commands, let's review some terminology.
Directories? Folders?
A Directory is the same thing as a folder. Directories can contain subdirectories.
A dot (period or full stop) refers to t two dots represent the directory above the current directory.
The tilde character (~) refers to your home directory.
The tilde followed by a user's name (as in ~username) refers to that user's home directory.
Both the dot symbols and the tilde can be treated as directory names.
For example, ../config.php refers to the file config.php in the directory above the current one. The directory ./functions.php refers to functions.php in the current directory. And ~/public_html or ~/htdocs are (usually) the names of your main web directory, which is likely to be a subdirectory of your home directory. The domain
shown in your web browser's address bar refers to the main web directory, not to the site owner's home directory.
The forward slash (/)
The forward slash fulfils the same role it does in a website URI: it shows the item after to be in a subdirectory or the directory before it. A forward slash on its own refers to the root directory, which is at the top of the file system.
Directory Name Character Rules and Spaces
A file or directory name can contain any standard character except a forward slash — including white spaces. However, when entering shell commands, you separate commands, parameters, and files with spaces. If you have a space in a file or directory name, you need to use a backslash in front of it or put quotation marks round the name.
A directory called My Pictures would be entered as &My Pictures& or as My\ Pictures
The * and ? Symbols: The * and ? symbols are called
and can be used in any command which deals with files.
The * represents any number of characters. The ? represents just one. Note that Linux filenames are case-sensitive — the norm is lowercase.
All commands are lowercase.
Command Options: Commands usually accept options or parameters, which are given in a sequence beginning with a hyphen (-). If you would want to set options b, r and f for a command, type command -brf Other specifications, like file names, go after the options.
Here's a brief introduction to some useful UNIX shell commands.
This command displays a listing of a directory's contents. Unmodified, the command displays the contents of t you can also specify another directory's content to list. Some useful options are:
If the list is long, you can display the list in pages. To do this, type ls -l |less
(Note: The vertical bar | is also known as a UNIX pipe). The pipe bar means that the output from ls -l is submitted to the program less, which displays pages of whatever input it receives. You can press space to view the next page, or the arrow keys to go up and down.
Includes hidden files (i.e. files that begin with a dot, like )in the directory listing.
Specifies any other directory or file group to list after the options, and in this example would list all the files beginning with g, while ls public_html would list the contents of public_html.
The cd command changes the current directory. To switch from the current directory into a sub-directory, put the sub-directory's name after the command. To change into a sub-directory wp-content, you'd type
cd wp-content
To move up into the directory above the current directory, type
To change from the current directory to your home directory, type
The mkdir command creates a new directory inside the current one. To create a directory named audio inside the current directory, type
mkdir audio
To remove an empty directory, type rmdir directoryname for example:
rmdir audio
If you want to create a directory, and one or more sub-directories within it, with a single command you can use the '-p' argument with the mkdir command.
For example, to create the directory 'maindir' and 3 sub-directories named 'sub1', 'sub2' and 'sub3' within it use the following command:
mkdir -p maindir/sub1 maindir/sub2 maindir/sub3
The rm command deletes ('removes') a file, a group of files, or a directory. When using this command, use extreme caution, as once you remove the file there is no good or consistent way to recover it.
To remove a single file use:
rm filename
You can remove multiple files by naming them one after another on the line:
rm filename.php filename.html
You can also a group of files that have similar names with the use of a well place '*', and it will prompt you to type 'yes' to confirm each deletion:
rm filename*
To remove files without it prompting for confirmation, use the '-f' flag:
rm -f filename*
To remove an entire directory and its contents in one go, type:
rm -rf /path/to/directoryname.
Beware — once something is removed in this way, it is gone forever.
The exit command ends your shell session.
The mv command moves files from on it is also used to rename files. Type
mv file new-location
If the new-location parameter is a (valid) directory in the current filesystem, the file is moved if it isn't (and if it doesn't clash with an existing filename), the file will be renamed as new-location. You can also move and rename a file with one command:
mv file ~/path/to/new-file-name
The cp command copies files or directories.
To copy a directory and its entire contents, use
cp -rf source-file destination
The ln command creates links. The links relevant to our purposes are "symbolic links" or symlinks — files which "point" to other files or directories in the filesystem. When you access a symlink, you are actually accessing the original file. If you want to change the location of your WordPress directory from, say, /wordpress/ to /blog/, you could create a symlink as follows:
ln -s wordpress blog
Access will then be through either the file or directory's actual name — wordpress — or through the link name — blog. In the
panel in the Wordpress , set the "Blog address (URI)" field to show the symlink rather than the name of the directory.
The tar and unzip commands are used to compress and decompress "archive" files. Archives are files or folders that have been "compressed" — i.e. reduced in file-size — and are commonly used for distribution and backup purposes. The unzip command is used for files ending with .zip; the tar command is used for files ending with .tgz or .tar.gz.
Unzipping files: If the file is a .tar.gz archive, type tar -zxvf file.tar.gz
If it's a zip archive, you may need to create a temporary directory into which you'd unzip its contents (its files might be unzipped into the current directory otherwise).
If the file is a .tar.bz2 (bzip2) archive, use the following command to extract its contents
tar -xjvf file.tar.bz2
The chmod command changes the permissions on a given file. UNIX file permissions specify who can do what with a given file. The ls -l command will tell you what permissions a file or directory has:
-rw-r--r--
1 domain60 vweb
Feb 21 06:38 wp-config-sample.php
-rw-r--r--
1 domain60 vweb
Jun 29 20:31 wp-config.php
drwxr-xr-x
4 domain60 vweb
Jun 29 20:30 wp-content
-rw-r--r--
1 domain60 vweb
Mar 29 16:05 wp-feed.php
drwxr-xr-x
3 domain60 vweb
Jun 29 18:46 wp-images
drwxr-xr-x
2 domain60 vweb
Jun 29 18:46 wp-includes
The permissions are displayed in the string of letters in the first column. The very first letter of that column indicates whether it is a file, a link, or a directory.
A d denotes a directory, a l denotes a link, a hyphen denotes a file.
The permissions are declared with the following nine letters, which are shown in groups of three.
The first group of three concerns the owner, the second the group he belongs to (this is unlikely to concern you as a web host user), and the third concerns everyone else.
Note that people with root access (administrators) have access to all files on the system.
The letters r, w and x stand for read, if the file is a directory, executable means traversible, that is, that you can move into that directory with the cd command. Where a hyphen is shown in the permissions list, the permission is absent.
You change permissions with the chmod command. You may, in fact, not have to change th some hosts automatically set certain permissions on any file in the web directory. Your host may also tell you what permissions need to be set on your server.
The chmod command can be used to set permissions in two ways: with letters or with numbers. If you use letters, you could type chmod o+w filename
This grants write privileges to everyone with access to the system. The first letter can be u (user), g (group) or o (other), the + (grant) can also be - (withhold), and the third can also be r or x (read or execute).
If you use numbers, all permissions for a file are set in one go. An example:
chmod 755 wp-images
sets the permssions of the wp-images directory to 755, whereby the first number (the "hundreds") is for the user, the second (the "tens") is for the group and the third (the "units") is for everyone else.
More about numerical permissions settings: To add 4 in any of the fields gr to add 2 grants write and to add 1
each combination has a unique number. The directories in the example above have the permission set 755, which is common for web-available directories, in which the user has full privileges while others have r the files in the example have the permission set 644, in which the user can read and write while others can only read.
-rw-r--r--
1 domain60 vweb
Feb 21 06:38 wp-config-sample.php
drwxr-xr-x
2 domain60 vweb
4096 Jun 29 18:46 wp-includes
The wget command downloads a file if you put a web location (URI) after it. To download the latest WordPress release type wget http://wordpress.org/latest.tar.gz
The screen command allows you run multiple console-based applications with in a single Terminal session. If GNU screen is installed on your server, you can use the following command to start it:
starts, a welcome message should be displayed. Just press Return to get rid of this message and you should now see a shell prompt. This will be the first session window and is numbered 0. Each subsequent new session you open will be given a number, starting from 1 for the second session window.
To create a new session window press CTRL-a
To switch between currently open session windows press: CTRL-a
followed by the number corresponing to the session window you want to access.
To get a list of all the session windows that are currently open press: CTRL-a
To exit screen altogether, stop all running programs and type
at the shell prompts in all the session windows you have opened (including window '0'). screen will terminate when there are no more programs running in any open session windows.
Let's use the example of upgrading WordPress using the command line. First, establish the location of your WordPress on your web server's filesystem. This example assumes it is located at ~/public_html/blog.
Download the current version of WordPress to your shell account's home directory and unzip it: wget http://wordpress.org/latest.tar.gz
tar -zxvf latest.tar.gz
The WordPress archive will be unpacked into a new directory named /wordpress.
Enter the new directory with the following command: cd wordpress
Remove wp-config-sample.php: rm wp-config-sample.php (We will use our current wp-config.php instead)
Remove the entire /wp-content directory from the new directory (we will replace it with the one from our WordPress blog directory): rm -rf wp-content
Copy the blog's wp-config.php and .htaccess file to the new directory: cp ~/public_html/blog/wp-config.php .
cp ~/public_html/blog/.htaccess . Note: Don't forget the dot at the end of both commands!
Copy the wp-content directory to the new directory (it contains all our themes and plugins): cp -rf ~/public_html/blog/wp-content/ . Again, note the dot at the end of the command.
Remove the entire contents of your WordPress blog directory: rm -rf ~/public_html/blog/*
Finally, copy the entire contents of the new directory to your main blog directory: cp -rf * ~/public_html/blog
SFTP stands for Secure File Transfer Protocol.
It is an encrypted replacement for FTP, and as with FTP, you may use a shell-based client or one of the graphical clients mentioned at the top of this article. If your host supports SSH, it also supports SFTP.
Shell-type SFTP clients support commands similar to those used in bash.
These include cd, ls, mkdir, rm and rmdir. It also supports ln, with the difference that you do not need to use the -s optio in sftp, the ln command makes symlinks by default. All of these work on files on your host's system.
These two commands transfer to your host (i.e. upload) a single file (put) or any files that match the pattern you supply (mput); the wildcards * and ? described above can be used here.
These two commands transfer from your host to your local computer (i.e. download) a single file (get) or any files that match the supplied pattern (mget).
As with mput, * and ? can be used.
These commands are identical to their bash shell counterparts: change the current directory, make a new directory, and list the contents of the current directory. To do the same things within SFTP on your own machine, add an l to the front of the commands: lcd, lmkdir, lls.
This article is
as in need of editing. You can
Codex by .
Codex Resources
Code is Poetry}

我要回帖

更多关于 there be 句型 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信