You are here: Support > Knowledgebase > SSH > Common Unix/Linux Commands Used Via Telnet/SSHPlease Login or Register  

Common Unix/Linux Commands Used Via Telnet/SSH

Common Unix/Linux Commands Used Via Telnet/SSH
When you type the Command shown, the Action described is what should happen. (Italicized portions replaced with your specific information, of course.)
 
CommandAction
Basic Navigation
/Refers to the root directory on the server
./The current directory that you are in
../Parent directory of your current directory
cdWhen typed by itself, cd ("change directory"), will take you back to your $HOME directory (on eProHosted, your home directory is /home/username).
cd /path/to/directoryTo change to a specific directory, type cd followed by the path to the directory. If it is a subdirectory of the current directory, you can just type the directory name--for example, when in your account's root directory (/home/username/public_html), you can just type cd cgi-bin to go to your cgi-bin.
cd ..Typing cd .. moves you up one directory from your current location.
pwdTo see which directory you are in, type pwd ("print (display) working directory").
exitJust as it sounds, use exit to log out. Alternatively, you can type logout or just press the "d" key while holding down the Ctrl key.
Creating, Moving, Renaming, and Deleting Directories
ls -d */Lists all directories within current directory
mkdir directorynameTo create a new directory, type mkdir ("make directory") and specify the new directory's name.
rmdir directorynameTo delete an empty directory, type rmdir ("remove directory") and the directory's name.
mv olddirectoryname newdirectoryname Move/Rename a directory
cp -r directoryname newdirectorynameCopy a directory and all files/directories in it
rm -r directorynameRemove a directory. You will be prompted to answer "Y" or "N" for whether you would like to delete each file in the directory
rm -rf directorynameRemove a directory and all files and folders in it (no prompting).
Listing Files
lsTo display a list of files and subdirectories in your current directory, type ls ("list")
ls -aTo see a more complete list which includes files that begin with a "." (dot), type ls -a.
ls -alLists filenames + information
ls -aRLists filenames + information in all subdirectories
ls -aR | moreLists filenames + information in all subdirectories, pausing when the screen becomes full
ls -aR > result.txtLists filenames + information and outputs the results to a file
ls *.htmlLists all files ending with .html
ls -al/home/usrLists files + info for /home/usr
ls -laTo list all files and directories in long format which will provide details about each file and directory, type ls -la.
ls -lSTo list all directories and files, sorted by size, in long format, type ls -lS.
ls -ltaTo list all files and directories in long format by time modified, type ls -lta.
Copying Files
cp oldfilename newfilenameWill copy the contents of one file to another file, resulting in two copies of the same file on your account.
cp directory/* destinationdirectoryWill copy the contents of one directory to another directory. Make sure you have created the destination directory before trying to copy files to it - see mkdir above. Results in two copies of the files on your account; one copy in the existing directory and another in the destination directory.
Searching Files and Directories
find -name 'n*'The find command can be used to locate files or a group of files. It can also be used to display directories. The example given will find all file and directory names within the current directory and subdirectories of it that begin with the letter n. (You can also explore using the locate command - type info locate and/or man locate for usage information.)
find / -name [filename] 2>/dev/nullSearch the whole server for a file.
find ./ -name [filename]Search for a file starting with the current directory.
grep text filenameSearch for text within a file.
grep -inw text filenameCan be used to locate text in a specific file or directory of files (use * in place of filename to search all of the files in the current directory). The -i argument indicates the search is to disregard cASe, the -n instructs to show the corresponding line number, and -w tells it to match only based on the whole word. (This doesn't even begin to touch on the power of grep and its many uses. In addition to its searching capability, the grep command can be used in combination with other commands to act as a filter. It also allows the use of "wildcards". Two other variations of grep are also available, egrep and fgrep. To begin your quest for more information, type man grep and/or info grep.)
Displaying/Comparing File Content
wc filenameCounts and displays the number of lines, number of words, and number of characters of the given file.
cat filenameDisplays the entire contents of a file.
nl filenameShows the content of the file, including line numbers (nl=number lines).
more filenameDisplays the contents of a file one screen at a time. Press the SPACEBAR to display the next screen of text.
cmp filename1 filename2Compares the contents of the two named files and reports the first different character found and the line number.
diff filename1 filename2Compares the contents of the two named files and reports all of the differences found. (Can also be used for comparing the contents of two directories.)
Moving, Copying, Renaming, and Deleting Files
mv oldfilename newfilenameCan be used to rename a file (mv fileA fileB), move a file (mv fileA /dirA/), or both (mv fileA /dirB/fileB).
cp oldfilename newfilenameCopies a file.
rm filenameDelete a file.
rm -i filenameRemoves (deletes) the specified file. (The -i is not necessary, but is recommended as it will prompt you to confirm the action first. When prompted, type y to confirm or type n if you changed your mind.)
Changing Permissions
chmod permissions filenameChanges the permissions on a filename or directory as specified. (change mode)
Archives and Compression
tar -cvf filename.tar directorynameTo archive a directory and all of its contents including subdirectories, navigate to where the directory is located and type the above command, replacing filename.tar with the name you wish to give the archive file and directoryname with the name of the directory you wish to archive. Alternatively, you can archive a select group of individual files (or directories) by specifying each file name in place of directoryname separated by spaces, like tar -cvf filename.tar fileA fileB fileC. Note: When creating a tar file (aka "tarball") be sure to specify the name you wish to give the tar file! (TAR indicates Tape ARchive, as it was originally a tape archiving program. The -c means "create", v means "verbose" (which basically says tell me what you're doing), and the f indicates that a filename will follow (filename.tar).)
tar -tvf filename.tarTyping this command will result in a list of the contents of the tar file. This is generally a good thing to do before unpacking the tar to be sure that there are no matching filenames which will result in files being unintentionally overwritten.
tar -xvf filename.tarYou can see the similarities to the command used to tar the file. This time, though, you use -x to "extract" instead of the -c used to create. You can also extract only certain select files (or directories) by specifying the individual names, separated by spaces, after the tar filename, such as
tar -xvf filename.tar fileA fileC
gzip filename.tarThis utility, gzip (gnu zip), is used for compression. Normally, when you wish to compress a set of files, you will tar them first then compress them using this command. In doing so, the filename will automatically change from filename.tar to filename.tar.gz (appending .gz to the file extension).
gunzip filename.tar.gzThis command (g"unzip") is used to uncompress a .tar.gz file, which will also result in the filename being changed back to filename.tar. Once it has been uncompressed, you can then untar it using the tar command above. (Alternatively, you can use gzip -d (for "decompress") in place of gunzip.)
tar -czvf filename.tgz directorynameThis command, which uses a z switch ("zip"), allows you to take a bit of a shortcut instead of using the tar and gzip commands separately. The example will result in a compressed archive named filename.tgz.
tar -xzvf filename.tgzThis command is used to uncompress and extract the files from a .tgz archive.
Miscellaneous Commands
man commandTo view the online manual for a command in order to find out more about its usage, just type man and the command. For example, typing man ls will show the usage documentation for the ls command including arguments (options) that can be used with it. To exit the documentation, type q (for quit). (See also info.)
info commandSimilar to the man command, info provides information on a command but in a different format and often more detailed. (You can also view the help pages of a command by typing command --help (replace "command" with the actual command. For example, ls --help will provide help on the ls command.)
whatis commandA quick way of getting information on what a specific command does. For example, typing whatis ls will tell you that its job is to list directory contents.
whereis commandUsed to locate the binary, source, and manual page files for specified commands/files. For an example, type whereis perl.
which commandShows the full path of the command. For an example, type which perl.)
who commandShows who is currently logged into the server.

This is by no means an exhaustive list of the commands and their options, however it should serve to get you started. Many other things are possible via the command line and for additional guidance in this area, along with consulting the man and help pages.



Was this answer helpful?

Add to Favourites
Print this Article

Powered by WHMCompleteSolution

WHMCS - The complete client management, billing & support system.

Home Page | Client Area | Hosting Plans | Knowledge base | Contact Us | Site Map | Legal | Privacy Policy

Copyright © 2008 -2010 Save N Host All rights reserved. Web Design by Graphics Xtreme Website Hosting by Save N Host