Common SSH Commands - Linux Shell Commands

Common SSH Commands - Linux Shell Commands

Navigating in UNIX

pwd Shows the full path of the current directory
ls Lists all the files in the current directory
ls -al Lists all files and information
ls –alR Lists all files and information in all subdirectories
ls -alR | more Same as ls –alR, pausing when screen becomes full
ls -alR > filename.txt Same as ls –alR, outputs the results to a file
ls *.html Lists all files ending with .html
cd [directory name] Changes to a new directory
cd .. Changes to directory above current one
clear Clears the screen
vdir Gives a more detailed listing than the "ls" command
exit Log off your shell

Moving, Copying and Deleting Files

 

mv [old filename] [new filename] Move/rename a file
cp [filename] [new filename] Copies a file
rm [filename] Deletes a file
rm * Deletes all files in current directory
rm *.html Deletes all files ending in .html

Creating, Moving, Copying and Deleting Directories

 

mkdir [directory name] Creates a new directory
ls -d */ Lists all directories within current directory
cp -r [directory] [new directory] Copies a directory and all files/directories in it

Searching Files and Directories

 

find . -name [filename] -print Searches for a file starting with current directory
grep [text] [filename] Searches for text within a file

File and Directory Permissions

There are three levels of file permissions: read, write and execute.  In addition, there are three groups to which you can assign permissions: file owner, user group and everyone.  The command chmod followed by three numbers is used to change permissions.  The first number is the permission for the owner, the second for the group and the third for everyone.  Here are how the levels of permission translate:

 

0 = --- No permission
1 = --X Execute only
2 = -W- Write only
3 = -WX Write and execute
4 = R-- Read only
5 = R-X Read and execute
6 = RW- Read and write
7 = RWX Read, write and execute

It is preferred that the group always have permission of 0.  This prevents other users on the server from browsing files via Telnet and FTP.  Here are the most common file permissions used:

 

chmod 604 [filename] Minimum permissions for HTML file
chmod 705 [directory name] Minimum permissions for directories
chmod 755 [filename] Minimum permissions for scripts & programs
chmod 606 [filename] Permissions for data files used by scripts
chmod 703 [directory name] Write-only permissions for public FTP uploading


 

How do I unzip a file with telnet?

All of the below commands assume that you are within the same directory that the compressed file is in. To be sure type:
ls {enter}
If the file is there, you're ready to go. If not type:
cd /big/dom/xdomain/www/directory/ {enter}
replacing the path with the correct path to your file.

If a file ends in .zip (for example, file.zip) type:
unzip file.zip

If a file ends in .tar (e.g., file.tar) type:
tar -xvf file.tar

If a file ends in .gz (for example, file.gz) type:
gzip -d file.gz

If a file ends in .tar.gz (e.g. file.tar.gz) type:
gzip -d file.tar.gz
and then
tar -xvf file.tar

If a file ends in .tgz (e.g. file.tgz)

zip [options] [zipfile] [files]

The zip command compresses a file or list of files into a zip format archive file. This command is compatible with pkzip on a PC. Simply type "zip zipfile file1 file2 file3" at a telnet command prompt and replace zipfile with the name you want to use for your compressed zip archive file, and replace fileX with the name of the file(s) you want to compress into the zip archive.

For example, type "zip backup.zip home.html index.html" at a telnet command prompt to compress and archive the files called home.html and index.html into the file called backup.zip.

   
 
unzip [options] [zipfile]

The unzip command extracts a zip format archive file. This command is compatible with pkunzip files from a PC. Simply type "unzip zipfile" at a telnet command prompt and replace zipfile with the name of your zip format archive file.

For example, type "unzip -aL old.zip" at a telnet command prompt to extract files contained in the archive called old.zip. The "-aL" are options that are generally useful when unzipping files created on a PC.

    • Related Articles

    • Mysql Basic Commands

      [mysql dir]/bin/mysql -h hostname -u root -p Create a database on the sql server. create database [databasename]; List all databases on the sql server. show databases; Switch to a database. use [db name]; To see all the tables in the db. show tables; ...
    • What are common SPF errors

      SPF validation is one of the most important aspects of good delivery. The Domain Verification Tutorial will show you how to add the records to your domain's DNS settings. One of the records you will be adding is what is called an SPF record. The ...
    • How do I backup MySQL in Linux?

      1. Copying from the mysql directory By default, MySQL databases on servers that use Linux are stored in the following directory: /var/lib/mysql/ If you shut down the mysqld service first, you can copy your databases to an example /backup directory ...
    • Creating a Welcome message for SSH logins

      Did you ever want to change or create a new login message antime someone logs into SSH? We'll show you how it's done. First off login to our server as root. Then type in the following: pico /etc/motd Now type in the security login message you wish ...
    • How to install APF (Advanced Policy Firewall)

      What is APF (Advanced Policy Firewall)? APF Firewall APF is a policy based iptables firewall system designed for ease of use and configuration. It employs a subset of features to satisfy the veteran Linux user and the novice alike. Packaged in tar.gz ...