Web Hosting Forum | Lunarpages

Author Topic: Basic shell commands  (Read 13721 times)

Offline StephanieŽ

  • Master Jedi
  • *****
  • Posts: 1094
Basic shell commands
« on: May 04, 2005, 04:40:48 AM »
Viewing files and moving around in shell

At the command prompt, enter "ls" this will list the contents of your current directory.
You should see something like this (sample contents)
Code: [Select]

[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:
Code: [Select]

[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
Code: [Select]

[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)


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

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

Code: [Select]

[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"

Code: [Select]

[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)


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

Type "chown steph:steph file.html"

Code: [Select]

[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 )  :P

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

Offline doncht

  • Intergalactic Cowboy
  • *****
  • Posts: 63
Re: Basic shell commands
« Reply #1 on: May 12, 2015, 03:38:24 PM »
Quick one on this please. Is there a command for users to check the logs when the server was accessed via SSH?


Share |