Basic Linux Commands

Let us look at some of the basic Linux commands to manage your files through shell access granted by CPHosting support team.

File Manipulation Commands in Linux:

  1. mv – Move files from one location to another
    Example:
    mv foo.txt foo.bak.txt
    Will move file foo.txt to foo.bak.txt
  2. cp – Copy files from one location to another
    Example:
    cp foo.txt newdir
    Copies the foo.txt in the current directory to the newdir directory.
  3. rm – Remove file
    Example:
    rm foo.txt
    Removes file foo.txt
    rm -rf images
    Will remove folder images and all contains inside it including files and any sub directories.

Directory / Folder Manipulation commands in Linux:

  1. ls – List files under current directory
    Example
    ls -lha
    This command will list all files in current directory in detail with human readable file size for each file.
  2. pwd – Prints out your current working directory
  3. mkdir – Make a directory
  4. cd – Change current working directory
  5. rmdir – Remove / Delete directory
  6. chmod – command helps you set permissions for the file or directory.
    Example:
    chmod 755 FormMail.cgi
    Will change file permissions of file FormMail.cgi making it executable perl file. (rwxr-xr-x)
    For detailed tutorial, please visit chmod command page at wikipedia.

Account Management

  1. passwd – Change users account password
  2. zip – Create compressed zip file
  3. unzip – Decompress file created in zip format
  4. du – Show disk usage of current directory
    Example
    du -hs
    This command will show summary of of disk used by all files and folder under current folder in human readable format (example 7.2M, 14G)
    du -h –max-depth=1
    This command will show disk used by each folder under current folder in list format.

Create compressed files

  1. tar – Create Tape Archives (TAR) and add or extract files.
    Example:
    tar zcvf publichtml.tar.gz public_html
    Will create gzip compressed tar file with name publichtml.tar.gz containing all files and folder under folder public_html
    Example:
    tar zxvf publichtml.tar.gz
    Will unzip previously cerated gzip compressed tar file
  2. zip – Create compressed zip file
    Example:
    zip example.zip foo1 foo2 foofolder1
    This command will create example.zip which contains a copy of files foo1 foo2 and folder foofolder1
    Example:
    unzip example.zip
    This will extract contents of example.zip to current directory.

Please note, this article was originally published in 2002 on our old web site. In 2002 term Unix was more popular then Linux!