Create account Login Webmail Contact Us



 
Knowledgebase
Very basic shell commands
Posted by admin on 17 September 2009 11:33 PM
What are some basic shell commands?
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:

[[email protected] steph]# ls
file.html public_html test
[[email protected] 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:

[[email protected] steph]# ls -a
. .. .bash_logout .bash_profile .bashrc file.html public_html test
[[email protected] 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:

[[email protected] root]# ls /home/steph
file.html public_html test
[[email protected] 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:

Code:

[[email protected] 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
[[email protected] steph]#

public-html is set at chmod 644

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

Code:

[[email protected] steph]# chmod 755 public_html
[[email protected] 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
[[email protected] 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 "

Code:

[[email protected] steph]# chown steph:steph file.html
[[email protected] 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
[[email protected] steph]#
(622 vote(s))
Helpful
Not helpful

Comments (0)
Post a new comment
 
 
Full Name:
Email:
Comments: