Common SSH Commands
Common SSH Commands
Move into another directory
Use this command to move into a directory:
cd
You can specify the full path from the root of the server:
cd /home/00000/domains/
You can type the path from where you are now (leave out the beginning /):
cd downloads/
You can go up a directory level:
cd ..
You can go to your home directory:
cd ~
Where am I?
Working with your server without graphics can take a little getting used to. If you ever need to see exactly which folder you're in, use the following command:
pwd
It stands for print working directory. You'll see output like this:
/home/00000/data/
What's here?
Next, we want to see a list of files and folders in our current directory:
ls -alh
ls is the list command, and -alh modifies the standard list in three ways. a means that all files, even hidden files, should be shown. l means that the long format is used - it shows things like file size and the date every file was last modified. h makes the sizes display in convenient units. Here's some sample output:
drwxr-xr-x 3 example.com example.com 15 Oct 21 10:01 .
drwxr-xr-x 6 example.com example.com 6 Oct 21 09:13 ..
-rw-r--r-- 1 example.com example.com 137 Oct 21 10:01 .htaccess
drwxr-xr-x 2 example.com example.com 4 Jun 8 17:24 errors
-rwxr-xr-x 1 example.com example.com 379 Jan 28 2010 hello.pl
-rw-r--r-- 1 example.com example.com 45 Oct 30 2009 home.html
-rw-r--r-- 1 example.com example.com 83 Oct 21 09:47 index.php
-rw-r--r-- 1 example.com example.com 68 Jul 20 15:53 phpinfo.php
Change permissions
This section shows basic commands for changing the access settings on a file. It is highly recommended that you read File Permissions before making any changes, so you'll know what kinds of changes are good and what might be a security risk.
To change permissions:
chmod 755 index.php
Quick permissions guide:
7 = Read + Write + Execute
6 = Read + Write
5 = Read + Execute
4 = Read
3 = Write + Execute
2 = Write
1 = Execute
0 = All access denied
First number is for the owner, second for the group, and third for everyone.
Copy file
Use this command to copy a file to a different location (first example), or to the same folder but with a new name (second example):
cp logo.png image/logo.png
cp index.php index.php_old
You can also copy an entire folder (along with all subfolders) using -R:
cp -R image/ image2
Move or rename file
The format for the move command is very similar to that for the copy command. Here's an example:
mv logo.png image/logo.png
mv is the basic command. This moves logo.png into the image/ subdirectory.
You can also use it to rename a file:
mv index.php index.php_old
This renames index.php to index.php_old.
Finally, you can move a folder just as easily as a single file. This example shows how to move the folder image/ up one level (..means "up one level"):
mv image/ ..
Delete file
You can also delete a file using SSH. Be sure you don't need it any more before you delete it.
rm index.php_old
Create or edit a file:
vi file.html
Read or search within a file
If you need to look through a file, the quickest way to get all the contents on your screen is cat:
cat index.html
Delete file
You can also delete a file using SSH. Be sure you don't need it any more before you delete it.
rm index.php_old
Move into another directory
Use this command to move into a directory:
cd
You can specify the full path from the root of the server:
cd /home/00000/domains/
You can type the path from where you are now (leave out the beginning /):
cd downloads/
You can go up a directory level:
cd ..
You can go to your home directory:
cd ~
Where am I?
Working with your server without graphics can take a little getting used to. If you ever need to see exactly which folder you're in, use the following command:
pwd
It stands for print working directory. You'll see output like this:
/home/00000/data/
What's here?
Next, we want to see a list of files and folders in our current directory:
ls -alh
ls is the list command, and -alh modifies the standard list in three ways. a means that all files, even hidden files, should be shown. l means that the long format is used - it shows things like file size and the date every file was last modified. h makes the sizes display in convenient units. Here's some sample output:
drwxr-xr-x 3 example.com example.com 15 Oct 21 10:01 .
drwxr-xr-x 6 example.com example.com 6 Oct 21 09:13 ..
-rw-r--r-- 1 example.com example.com 137 Oct 21 10:01 .htaccess
drwxr-xr-x 2 example.com example.com 4 Jun 8 17:24 errors
-rwxr-xr-x 1 example.com example.com 379 Jan 28 2010 hello.pl
-rw-r--r-- 1 example.com example.com 45 Oct 30 2009 home.html
-rw-r--r-- 1 example.com example.com 83 Oct 21 09:47 index.php
-rw-r--r-- 1 example.com example.com 68 Jul 20 15:53 phpinfo.php
Change permissions
This section shows basic commands for changing the access settings on a file. It is highly recommended that you read File Permissions before making any changes, so you'll know what kinds of changes are good and what might be a security risk.
To change permissions:
chmod 755 index.php
Quick permissions guide:
7 = Read + Write + Execute
6 = Read + Write
5 = Read + Execute
4 = Read
3 = Write + Execute
2 = Write
1 = Execute
0 = All access denied
First number is for the owner, second for the group, and third for everyone.
Copy file
Use this command to copy a file to a different location (first example), or to the same folder but with a new name (second example):
cp logo.png image/logo.png
cp index.php index.php_old
You can also copy an entire folder (along with all subfolders) using -R:
cp -R image/ image2
Move or rename file
The format for the move command is very similar to that for the copy command. Here's an example:
mv logo.png image/logo.png
mv is the basic command. This moves logo.png into the image/ subdirectory.
You can also use it to rename a file:
mv index.php index.php_old
This renames index.php to index.php_old.
Finally, you can move a folder just as easily as a single file. This example shows how to move the folder image/ up one level (..means "up one level"):
mv image/ ..
Delete file
You can also delete a file using SSH. Be sure you don't need it any more before you delete it.
rm index.php_old
Create or edit a file:
vi file.html
Read or search within a file
If you need to look through a file, the quickest way to get all the contents on your screen is cat:
cat index.html
Delete file
You can also delete a file using SSH. Be sure you don't need it any more before you delete it.
rm index.php_old
留言
張貼留言