| Webhosting | Prices / Features | Support | Forums | Backgrounds | Announcements | Contact us |

Unix Commands

Accessing a Unix machine through telnet or a command-line shell is really not as hard as it looks. This reference sheet gives you the basic commands you'll need, focusing especially on file management.
You can also combine the commands.

    cat
Reading and printing multiple files
cat allows you to read multiple files and then print them out.
You can combine files by using the > operator and append files by using >>.
Structure: cat [argument] [specific file]
If you wanted to append three files, you'd do this:
cat porsche.html mercedes.html bmw.html > all

    cd
Changing directories, moving around
cd (or chdir) stands for "change directory."
This command is key to moving around your file structure.
Structure: cd [name of directory you want to move to]
When changing directories, start with / and then type the complete file path, like so:
cd /yoursite/cars/
If you want to enter a subdirectory of the directory that you're currently in, then omit the first /.
So if you wanted to stay in the cars directory but move to the trucks subdirectory, you'd type:
cd trucks/

    chmod
Changing permissions on a file or directory

    chown
Changing ownership of files and directories
Structure: chown [option] newowner files
chown changes who owns a particular file or set of files.
New owner files refer to a user ID number or login name that is usually located in the /etc/password directory.
The owner of a file or directory can be seen by using the command ls -l.
Only the owner of a file or a privileged user can change the permissions on a file or directory.
The following example changes the owner of mercedes.html to jack:
chown jack mercedes.html

    cp
Copying files
cp copies files or directories from one place to another.
You can copy a set of files to another file, or copy one or more files under the same name in a directory.
If the destination of the file you want to copy is an existing file, then the existing file is overwritten.
If the destination is an existing directory, then the file is copied into that directory.
Structure: cp [options] file1 file2
cp [options] files directory
If you wanted to copy the file ford.html into the directory called trucks, here's what you would do:
cp ford.html /yoursite/trucks/
A handy option to use with cp is -r . This recursively copies a particular directory and all of its contents to the specified directory, so you won't have to copy one file at a time.

    date
Displaying and setting dates
date can be used to display the date or to set a date.
Structure: date [option] [+format]
date [options] [string]
The first structure shows how date can be used to display the current date.
A certain format can be specified in which the date should be displayed.
Check the Unix manual for specific formats and options.
The second structure allows you to set the date by supplying a numeric string.
Only privileged users will be able to use this second command structure.

    diff
Differences between files
diff displays the lines that differ between two given files.
Structure: diff [options] [directory options] file1 file2
diff can be an extremely valuable tool for both checking errors and building new pages.
If you run a diff between two files, you'll be shown what differences the files have line by line.
The lines referring to file1 are marked with the < symbol. The lines referring to file2 are marked by the > symbol.
If the file is a directory, diff will list the file in the directory that has the same name as file2.
If both of the files are directories, diff will list all the lines differing between all files that have the same name.
If you have a file that is not working properly, it can be a great help to check it against a similar file that is working. It will often quickly alert you to a line of code that's missing.
An option to use if you want to generally compare two files without noting the complex differences between them is the -h option (h stands for half-hearted).
Using -i as an option will ignore differences in uppercase and lowercase characters between files, and -b will ignore repeating blanks and line breaks.

    exit
Stopping a process and coming back home
exit allows you to terminate a process that is currently occurring.
For example, if you wanted to leave a remote host that you were logged onto (see rlogin), you would type exit. This would return you to your home host.

    find
Searching for files that meet specified conditions.

    finger
Gathering information about users
Structure: finger [options] users
finger displays information about various users as well as information listed in the .plan and .project files in a user's home directory. You can obtain the information on a particular user by using login or last names.
If you use the latter, the info on all users with that last name will be printed. Environments that are hooked up to a network recognize arguments (users) in the form of user@host or @ host.

    grep
Searching for lines that match regular expressions.

    head
Printing the beginning of a file
Structure: head [-n] [files]
head prints the first couple of lines of one or multiple files.
-n is used to display the first n lines of a file(s). The default number of lines is 10.
For example, the following will display the first 15 lines of mercedes_list.html.
head -15 mercedes_list.html

    kill
Terminating processes
Structure: kill [options] IDs
kill ends one or more process IDs. In order to do this you must own the process or be designated a privileged user.
To find the process ID of a certain job use ps.
There are different levels of intensity to the kill command, and these can be represented either numerically or symbolically.
kill -1 or HUP makes a request to the server to terminate the process, while kill -9 or kill KILL forces a process to terminate absolutely.
Most polite Unix users will attempt to kill a process using -1 first before forcing a process to die.

    less
Displaying files
Structure: less [options] [files]
less is similar to more in that it displays the contents of files on your screen.
Unlike more, less allows backward and forward movement within the file. It does not read the whole file before displaying its contents, so with large files less displays faster than more.
Press h for assistance with other commands or q to quit.

    lprm
Removing printer queue requests
lprm removes printer queue requests.
Structure: lprm /usr/ucb/lprm [optons] [job#] [users]
lprm will remove a job or jobs from a printer's queue.
If lprm is used without any arguments, it will delete the active job if it is owned by the user.
If the command is used with -, then all jobs owned by the user will be removed. To remove a specific job, use the job number.

    ls
Listing files

    man
Using the online manual
The man command can be used to view information in the online Unix manual.
Structure: man [options] [[section] subjects]
man searches for information about a file, command, or directory and then displays it on your screen.
Each command is a subject in the manual. If no subject is specified, you must give either a keyword or a file.
You can also search for commands that serve a similar purpose. For example, if you wanted more information about the chmod command, you should type:
man chmod
A screen will then appear with information about chmod. Type q to quit.

    mkdir
Making directories
Structure: mkdir [options] directory name
mkdir creates a new directory. In order to do this you need permission to write to the parent directory.

    more
Displaying files
Structure: more [options] [files]
more displays the contents of files on your screen. To have the next line displayed, hit the return key, otherwise press the spacebar to bring up the next screen.
Press h for assistance with other commands, n to move to the next file, or q to quit. See also: less.

    mv
Moving and renaming files
mv moves files and directories. It can also be used to rename files or directories.
Structure: mv [options] sources target
If you wanted to rename pontiac.html to chevrolet.html, you would do this:
mv pontiac.html chevrolet.html
After typing this command, pontiac.html would no longer exist, but a file called chevrolet.html would now exist with the same contents.

    passwd
Creating or changing passwords
Structure: passwd [options] files
passwd creates or changes a user's password. Only the owner of the password or a privileged user can make these changes.

    ps
Active processes
Structure: ps [options] ps prints information about active processes. This is especially useful if you need to end an active process using the kill command.
Use ps to find out the process ID number, then use kill to end the process.

    pwd
Printing the pathname
pwd prints the pathname of the current directory.
If you wanted to know the path of the current directory you were in, you'd type pwd and the output would be something like:
/yoursite/trucks/ford/

    rlogin
Logging into remote systems
Structure: rlogin [options] host
rlogin, which stands for remote login, lets you connect your local host to a remote host.
If you wanted to connect to the remote host someothersite and you were on yoursite, you would do this:
rlogin someothersite password:******
You would then be at someothersite.

    rm
Removing files and directories
rm removes or deletes files from a directory.
Structure: rm [options] files
In order to remove a file, you must have write permission to the directory where the file is located.
When removing a file that you do not have write permission on, a prompt will come up asking you whether or not you wish to override the write protection.
The -r option is very handy and very dangerous. -r can be used to remove a directory and all its contents.
If you use the -i option, you can possibly catch some disastrous mistakes because it'll ask you to confirm whether you really want to remove a file before going ahead and doing it.

    rmdir
Removing directories
Structure: rmdir [options] directories
rmdir allows you to remove or delete directories but not their contents.
A directory must be empty in order to remove it using this command. If you wish to remove a directory and all its contents, you should use rm -r.

    su
Logging in as another user
Structure: su [option] [user] [shell_args]
su stands for superuser (a privileged user), and can be used to log in as another user.
If no user is specified and you know the appropriate password, su can be used to log in as a superuser.

    tail
Printing the end of a file
Structure: tail [options] [file]
tail will print the last ten lines of a file. tail is often used with the option -f, which tells tail not to quit at the end of file and instead follow the file as it grows.
Use ctrl-C to exit this command.
This is very useful if you need to track a file. Editors often use this command to tail error logs. This can give you insight into exactly what an error is while it's happening so you can fix it quickly.

    telnet
Communicating with other hosts
Structure: telnet [host [port]]
You can communicate with other computers by using the telnet protocol.
The host must be a name or an Internet address. telnet has two modes: the command mode, which is indicated by the telnet > prompt, and an input mode which is usually a session where you would log on to the host system.
The default mode is command mode, so if no host is given it will automatically go into this mode.
If you need help while in the command mode, type ? or help.
For More info see Telnet.

    who
Displaying information about a system
Structure: who [options] [file]
The who command prints out information about the most recent status of the system.
If no options are listed, then all of the usernames currently logged onto the system are displayed.
The option am i will print the name of the current user. The option -u will display how long the terminal has been idle.

    Combining Commands
Most Unix commands are fairly simple and only have a handful of options.
The beauty of Unix is that these commands can be combined to do more complex tasks.
You can send the output of one command to another command for further processing by separating the commands with a pipe (|).
If you want to follow a file as it grows (tail -f) and search for a regular expression (grep), you can combine commands to achieve this.
If you are searching for files in a growing error log that contains the word mypages you would type this:
tail -f errorlog | grep ".*mypages.*"
This tails the errorlog and then greps for the regular expression "mypages."
The . and * are called meta-characters. The .* in this example matches any number of any character.

  - Account Log ins
  Control Panel Sample

  - Getting Started
  Chosing a Password
  FTP
  Index Files
  Quick Html
  Virus Tracker
  Anti Spam Tips

  - Creating Databases
  Moving Databases

  - Htaccess
  Hot Linking
  Password Protection

  - Unix Commands
  Chmod
  Find
  Grep
  Ls
  Regular Expressions
  Telnet / SSH

Our Software Picks

EyesOnTraffic.com

BoxedArt.com


| Copyright | © 2000 MyPagesOnline, All Rights Reserved | Privacy Statement |