SSH Cheat Sheet
This page designed to help beginners starting out with SSH by providing a usable “SSH cheat sheet” full of common commands.- Delete an entire directory and all of its contents:
-
rm -r -f YourDirectoryWhat’s happening: rm = remove / delete -r = recursively deletes the directory and all files in it, including subdirectories -f = will not ask for confirmation before deleting - Extract a TAR.GZ File
tar -xvf yourfilename.tar.gzWhat’s happening: tar – is calling the tar program -x – extract -z – it’s gzipped (so omit the z if you merely have a .tar file) -f – supplying filename on command line.- Move a directory and/or files to another location on the server:
mv directory/* html/What’s happening: mv – move directory/* – All files/folders inside the Directory folder html/ – Location of where the files will be moved to
| 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 |
| 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 |
| 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 |
| find . -name [filename] -print | Searches for a file starting with current directory |
| grep [text] [filename] | Searches for text within a file |
| 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 |
| 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)
|
Moving files via SSH
Often you will need to move one or more files/folders or copy them to a different location. You can do so easily using an SSH connection. The commands which you would need to use are mv (short for ‘move’) and cp (short for ‘copy’).
The mv command syntax looks like this:
mv configuration.php-dist configuration.php
By issuing the above command we will move (rename) the file configuration.php-dist to configuration.php.
You can also use mv to move a whole directory and its content:
mv includes/* ./
This will move all files (and folders) in the includes/ directory to the current working directory.
In some cases however, we will need to only update the files and move only files that were changed, which we can do by passing ‘-u’ as argument to the command:
mv -u includes/* admin/includes
The copy (cp) command works the same way as mv, but instead of moving the files/folders it copies them. For example:
cp configuration.php-dist configuration.php
The command will copy the configuration.php-dist file to configuration.php and will preserve the original file (the file will NOT be removed after it is copied).
cp also accepts various arguments:
cp -R includes/ includes_backup/
-R instructs cp to copy files recursively (for example, a whole directory). To overwrite already existing files you should use the -f argument:
cp -Rf includes/ admin/includes/


Pingback: SSH Cheat Sheet | Best Cheat Sheets
Pingback: Bash scripting Refcardz please? - DZone Forums