Introduction

In the most of our tutorials we rely on our readers and their at least the basic A�knowledge about UNIX commands. If you are not too familiar with UNIX commands this one is for you.

Directories

Files and directories in UNIX use slash / as a separator. For example /home/jhon/file.sh means:A�directory “jhon” under directory “home” with the specific file “file.sh”.

Examples:

/              "root" directory
/home          directory home (sub-directory of "root")
/home/JHON     JHON is a subdirectory of /home

pwd – shows “present working directory”

Example:

[email protected] [/home/master]# pwd
/home/master

cdA�– change current directory

Example:

cd home           Change current directory to home which is a sub-directory of the current directory
cd ..             Change current directory to the parent directory of the current directory

lsA�– list information about the files in (current) directory

Example:

ls
directory   index.php   sendmail.php
ls -l
drwxr-xr-x    4 jhon    www-user        1024 Aug 8 20:11 directory
-rw-r--r--    1 jhon    www-user      767392 Aug 6 22:13 index.php
^ ^  ^  ^     ^   ^       ^              ^      ^    ^      ^
| |  |  |     |   |       |              |      |    |      |  
| |  |  |     | owner   group          size   date  time    name 
| |  |  |     number of links to file or directory contents
| |  |  permissions for world
| |  permissions for members of group
| permissions for owner of file: r = read, w = write, x = execute -=no permission
type of file: - = normal file, d=directory, l = symbolic link, ...

ls -a  #list including hidden files. Hidden files start with "." for example .htaccess

mkdirA�-A�make a new directory

Example:

mkdir example

Working with filesA�(copy, move, rename, remove)

copyA�-A�copy file

Example:

cp file1.php file2.php #create copy of file1.php
cp /home/doe/file1.php /home/jhon/file2.php #create copy of file in different directory

mvA�– move file

Example:

mv /home/doe/file1.php /home/jhon/file1.php #move a file file1.php to different directory

mv – (again)A�rename file

Example:

mv file1.php file1.php #rename file1.php to file2.php

rmA�– remove file

Example:

rm file1.php   #remove file1.php
rm -r dir      #remove directory with content
rm -rf dir     #remove directory without prompt

Changing file permissions and attributes

chownA�– makes user:groupA�the owner of file

Example:

chown user:group file1.php   #change user and group of a file1.php

chmodA�-A�changes the permissions of file

Example:

chmod 0777 file1.php   #change permissions for file1.php

Here is a little chown calculator for you (thanks JavaScriptA�Kit):

Permission Owner Group Other
Read
Write
Execute

Conclusion

Those areA�nineA�basic commands for better orientation inA�all UNIX systems or distributions (Mac OSX, Ubuntu, Fedora, CentOS, RedHat, …)

Join the community

Leave a Reply

Our sponsors

We’re social

New in Lab

New Collection

New Tutorial

Knowledge base