Helpful UNIX tasks

 
 
 
 
 
 
 
 
 

    I do not pretend to be a UNIX(generally) guru, nor a guru on any particular flavor of UNIX, however, I do happen to know a fair amount about these things, and therefore have several very simple tasks outlined, and am working on this and therefore eventually, this list could get rather long.
 
 
 

Adding a user, general UNIX Modifying a user, general UNIX Setting Up a Linux Machine To Automatically Start Xwindows, the Login Process
Some General UNIX commands

Adding a user, general UNIX
 

Simple user


Modifying a user, general UNIX

One should note that none of these changes will take affect until the user logs out.
using the command usermod
Setting Up a Linux Machine To Automatically Start Xwindows, the Login Process
This is more commonly known as XDM, but is basically setting up an Xserver so that it provides the login screen and people do not have to start up Xwindows on their own on a Linux System.

These instructions assume that you already have Xwindows installed and working on your system.  If you do not have it working (i.e. xinit either does nothing, is not found, or you can do nothing once you enter the command other than simply kill Xwindows...) then DO NOT use these instructions as you will have a great deal of problems if you do.
 

General UNIX Commands
 
cat rm mv cd
find pwd ls ps
kill
cat
this command will "list" a file (output its contents to the screen). It does it in such a way that every character in the file is output to the screen using its various representation thanks to ASCII code.
rm
this command removes a file or directory from the file system, dependent upon the arguments to the rm command. The arguments to this function are -r (to recursively destroy a file or directory, though this argument really only matters in destroying a directory. In fact, this is the only way to destroy a directory with the rm command, otherwise, one needs to use the rmdir command.), or -f (force, this will destroy things even if the -i option is used to confirm the destruction, and it will suppress error messages, such as permission errors, note, it will not override permission errors, it simply will not tell you about them in this case). -i can be used to force you to confirm removal of files.
mv
this command moves a file or directory from one location in the file system to another location in the file system. A -i can be used to ask you to confirm any move which will overwrite files.
cd
this command changes your current focus, or where you are, to another location. The command is an acronym for Change Directory, as the purpose of the command is to move around in the file structure of UNIX, known as the directory structure. The place that you can change directory from is always from the current directory you are in, which can be shown using the command pwd.
pwd
this command will show you the current directory you are in.
ls
this command will show you the contents of the current directory you are in, if used using only the command ls. However, this command takes a myriad of arguments, some of the more useful of which can tell you sizes, and types of files ('ls -l'), and other very interesting things. The arguments gone over below may be combined, such that the arguments are preceeded by a single dash, and then a list of arguments (for the '-F', '-l', and '-a' arguments, the appropriate argument would be '-Fla'. Though the order does not matter).
The output of the normal ls command is simply a list of files, if the -a option is used, then all files are shown that are in the directory, otherwise all hidden files (files preceeded with a '.') are not shown. Each file is listed in a column of the output, or if the -1 argument is used, then each file will be listed on its own line.
Using the -F command produces a slightly different output, in that using this argument, a single character is appended to the filename, in the case that the file is executable (a '*' is appended), a directory (a '/' is appended), or a link (not a real file, but merely a pointer to another file, a '@' is appended).
find
this command will search every file in the directory structure, from the place that it is given to start with onward. The command takes a list of directories, for which it will search every file in each directory and then will traverse the directories underneath it until it has nowhere to go. The find command will not traverse softlinks. Though by searching every file, I feel I must explain what this means. It will perform the actions specified, by the remaining arguments to the command, on every file that it searches. To explain what this means, I will go over a common usage of the command. Using the -name argument, it will check each file searched against the name specified as a shell expression, this basically means a regular expression, except there are some differences (though you must look these up, as each shell has different issues with this. If the name matches the -name argument, then it performs the next command on the file. Another common usage is the -exec argument after this. The -exec executes a command (in a new shell) with a set of arguments (it will send everything between the -exec and the \; to the shell). A note here is that, in the -exec the {} symbols indicate, place the filename that we are searching here.

A cool find command (in tcsh/csh):
find . -exec test -f {} \; -exec grep -l phrase {} \;
Find all files in this directory, or any subdirectory (recursively) which contain the word "phrase". Most importantly this command will not spam you with the usual 'grep: x is a directory' error message for each subdirectory. A small note is that the 'test -f' is peculiar to tcsh/csh, and if you use a different type of shell you may have to use something else, such as for ksh it is 'test -a'.
ps
This command will display processes being run on this computer. This is very useful for finding out whether a process is actually done running or not, and similarly for finding processes to use the kill command on. Though ps does not actually look for process names, it can be done.

alias findnumber 'ps aux | grep \!* | cut -c 10-15'
is a handy alias that will list all process numbers of processes that match the specified name when you use findnumber. For instance:
fundnumber netscape
would list all the process numbers of any process that had netscape in its name. Explaining the findnumber alias, we look at the ps command and it uses the argument ax, which on linux, and similar systems will show all processes that belong to the user who runs the command, and whether they are in zombie state or not (as the system does not normally list processes that are zombified) The grep command uses the argument \!*, which is csh/tcsh syntax for whatever is typed after the command (all arguments of the alias in this case). Further the cut command takes the -c argument, which will cut a specified range of characters out of whatever it is given (on each line). A much more useful alias is built later in the kill command. But this can also be quite a useful building block.
kill
This command will send a signal to a specific process (running program). The point behind this command is that sometimes a process will become errant, in that it does not do what you want it to. This can obviously be a problem. So this command is most often used without argument to terminate a process, though this is also sometimes not enough, when the process becomes so embroiled in its own processing that it no longer responds. In these cases, it is necessary to use the -9 argument with kill, so that the process is killed no matter what the process wants to do. The thing about this command is that it is necessary to use the process's number in order to do something about it, and therefore ps is necessary. An example of these two commands is below.

alias killproc 'kill -9 `ps aux | grep \!* | cut -c 10-15`'
As is often useful, the above will kill all programs with the name matching the argument of the killproc alias. Taking the command a piece at a time, we use the -9 argument of kill, telling it to take the process down no matter what. The ps command next will list all processes you own, but it is fed into grep, making it match only processes that have the argument to the killproc alias in their name, then the cut command is used to cut out only the process numbers of list. As with the ps command, these assume that you are on a linux or similar system, as each system will require slightly different arguments. One other interesting note is that the kill command does not take standard input, only arguments, so that is why we included the backticks (`) in the alias, and could not simply use a pipe (|) as we do in other places.