December 22nd, 2003, 03:22 PM
Basic unix file and process commands
Hello everyone welcome to my first tutorial in AO
One more of my long and basic tutorials,hope someone finds it useful
THE WHO AM I COMMAND
The who am i command is used to get the information about our self.
$ who am I
fee2-01 Dec 17 15:30
Where fee2-01 is our login id .
THE WHO COMMAND
The who command gives us the information about the users who are currently connected to the system?
This will display the list of the users who are currently logged in to the system.
PROCESS RELATED COMMANDS
659 tty03 00:00:01 sh
684 tty03 00:00:00 ps
The ps command is used to display the attributes of all process running in the system. The first column in the above output is the process identification number the second column is the terminal number of the user on which the process is running, the next column is the time taken by the process to execute, and the last column is the name of the process.
$ kill 659
If the user wishes to end the process which is running he can do so by mentioning the command kill followed by the process identification number of the process you want to kill.
Re-enter new password:
The user can change password by making use of the command passwd. The system asks us to enter the old password followed by entering the new password twice.
$ man ls
The man command is used to get the information of the particular command. In the above example the information of the ls command will be displayed.
COMMAND TO CHANGE THE PROMPT
The prompt that is normally there in unix is $. We can change this prompt to whatever we desire with the help of PS1(prompt string)command
Thus the prompt is now changed form $ to gizmofreak.
FILE RELATED COMMANDS
1) LISTING THE FILES
This command is used to list the files and directories, which are stored in the current directory or any directory
The ls command can be used with various options
$ ls –a
Displays all the hidden files in the current directory along with all the other files and directories.
The other options are
-x Displays all the files in multicolumn.
-F Displays all the files and directories, marks directories with / and executable files with *.
-l Displays the complete information of the file like the owner of the file the access rights of the file ,etc.
2) CREATING AND DISPLAYING FILES
The cat command is used in Unix to create and display the contents of text files.
$ cat > boys
The cat command when used with the redirection operator ‘>’ is used to create a file with the name boys.
The command can be used to view the contents of the file in the following manner
$ cat boys
Displays the contents of the file boys
$ cat > boys
The cat command when used with the >> sign is used to add to the contents of the file called boys. The new contents are appended at the end of the previous contents.
3) SORTING THE CONTENTS OF THE FILE
The sort command is used to sort the contents of the given file in alphabetical order
$ sort boys
The sort which is performed is temporary.
$ sort boys > new
$ cat new
The sorted names are now stored in file called new. We can also sort the file in reverse alphabetical order by making use of the option –r in the following manner
$ sort -r boys
4) COPYING THE FILE
The cp command is used to copy the file in the same directory or in other directory. The syntax is as follows
$ cp source destination
$ cp boys boy1
$ cat boy1
The contents of the file boys is copied into file boy1,wher boy1 and boys are in the same directory.
If we want to copy the file from one directory to another director then we have to specify the path for source as well for the destination.
$ cp /home/dir/boy /home/boy
$ cp /home/dir/boy /home/boy2
We can copy the file with the same name or with different name
We can also copy file using relative paths where
. Means current directory
.. Means parent directory
/ Means root directory
$ cp boys ./abc/boy1
Copies the file boys form the current directory to the directory abc which is under the current directory indicated by . .
5) MOVING AND RENAMING THE FILE
The mv command in Unix is used to either move the file from one directory or it can be used to rename the given file . The syntax for mv commands is same as that for cp command.
$ mv boys boy1
$ cat boy1
The above command renames the file boys by new name boy1.
$ mv boy1 /home/fee2-01/abc
The above moves the file boy1 for current directory to the directory abc . The file boy1 no longer exists in the current directory.
6) DELETING AND REMOVING THE FILE
The rm command is used to delete the files in Unix
$ rm boys
Deletes the file boys form the current directory
$ rm boys name girl
Deletes three files boys name and girl form the current directory.
7) PRINTING THE FILE ON THE PRINTER
$ lp boys
Prints the contents of the file boys on the printer, if the printer is available.
8) SPLITTING THE FILE
The split command is used to split the given file in to number of files newly created. The syntax is as follows
$ split -n filename newname
-n indicates the number of lines in each newly created file.
Filename the name of the file which is to be spitted.
Newname the prefix of the new files that are going to be created
$ cat > boys
$ split -2 boys by
$ cat byaa
$ cat byab
$ cat boys
Here we have created file boys in which we have stored numbers from 1 to 6 in six lines. Then we spitted this file in such a way that each newly file must contain two lines each. Total three new files will be created each with 2 lines and having prefix by where as the suffix is provided by the unix operating system. If the prefix of the newly created file is not mentioned in the command then the prefix and the suffix are both supplied by the operating system.
$ split -2 boys
$ cat xaa
$ cat xab
$ cat xac
Thus the new files which are created are having the names xaa, xab, xac supplied by the operating system, each containing two lines.
9) COUNTING THE NUMBER OF WORDS
The wc(word count) command is used to count the number of characters, words and lines in the given file.
$ cat boys
The output of the above command is in the first column it displays the number of lines present in the file, second column displays the number of words in the files and the third columns displays the number of characters including the newline characters present in the file.
The wc command can be used with the following options
-l displays only the number of lines in file
-c displays only the number of characters
-w displays only the number of words
Phew that was something