Basic Dedicated Shell Commands

From Lunarpages Web Hosting Wiki

Jump to: navigation, search

Here are a few handy and helpful basic shell commands to help you get started with becoming familiar with Shell on your dedicated hosting account. At the command prompt, enter " ls " this will list the contents of your current directory.

You should see something like this (sample contents)

[root@restoretmp steph]# ls
file.html public_html test
[root@restoretmp steph]#

The contents will normally have different colors ie: Blue for folders, white for files etc.. " ls " or ( list ) has many options for example:

" ls -a " in the same directory will show:

[root@restoretmp steph]# ls -a
. .. .bash_logout .bash_profile .bashrc file.html public_html test
[root@restoretmp steph]#

As you can see, the " -a " option allows you to see ALL the files in the directory (including hidden)

" ls -l " Will show a long format including group owner size, date modified and permissions.

" ls -R " Will list the contents of all the subdirectories recursively.

you can also mix the options: " ls -al " for example (long list of all including hidden)

You can also view directories without actually moving into them: " ls /home/steph " from root will show

[root@restoretmp root]# ls /home/steph
file.html public_html test
[root@restoretmp root]#

Moving around in shell.

" cd " (change directory) is the method of moving from one directory to another:

" cd /home/steph " for example would place me in the directory of steph.

" cd .. " will move you back one directory

" pwd " will print your current directory (useful if you need to double check where you are before typing a command)

" cd " Will take you back to root

Creating files and folders

The touch command is useful for creating a file:

" touch new-filename " would create a file named (new-filename) For directories:

" mkdir new-directory " will create a directory named (new-directory)

Removing files and directories:

" rm filename " would remove a file in the name of (filename)

" rmdir foldername " would remove a directory/folder in the name of (foldername)

chmod

Permissions often require changing on files and folders, the method is shown below:

" chmod 755 foldername " will set a folder to 755 for example:

[root@restoretmp steph]# ls -l
total 4
-rw-r--r-- 1 root root 0 May 4 05:47 file.html
drw-r--r-- 2 root root 4096 May 4 05:48 public_html
[root@restoretmp steph]#

public-html is set at chmod 644

Type: " chmod 755 public_html " then look again using " ls -l "

[root@restoretmp steph]# chmod 755 public_html
[root@restoretmp steph]# ls -l
total 4
-rw-r--r-- 1 root root 0 May 4 05:47 file.html
drwxr-xr-x 2 root root 4096 May 4 05:48 public_html
[root@restoretmp steph]#

drwxr-xr-x is 755 (the "d" means it is a directory)

Ownership

As you can see, our file.html is owned by root, to change the ownership to yourself ( chown ):

Type " chown steph:steph file.html "

[root@restoretmp steph]# chown steph:steph file.html
[root@restoretmp steph]# ls -l
total 4
-rw-r--r-- 1 steph steph 0 May 4 05:47 file.html
drwxr-xr-x 2 root root 4096 May 4 05:48 public_html
[root@restoretmp steph]#

As you can see "steph" is now the owner (lucky me)

We will add to this as required but these are the very basic commands in shell.

Want to read this in another language?

Lunarpages Deal: Save $72 on your next Business web hosting plan! Starting at $18.95 per month, this an offer you can't miss. Perfect for business and e-commerce hosting sites, comes with free e-commerce tools and a TremenDesk Help Desk. Limited time offer!