Developed first at the AT&T laboratories, Unix is now in the hands of different non profit organizations. If you want to learn how an operating system works, learning Unix is perhaps the best way to do so. To get a proper understanding of the Unix operating system, you need to know the basic Unix commands. This article will provide you with the basic Unix commands list and the purpose of each command.
What is Unix Operating System?
Let's start from the basics. An operating system is an interface between the user and the computer. The Unix operating system was designed to augment the same purpose. But the approach was of an open source software. It is a system software and all the processes in the operating system can be controlled by the user. The core of the Unix operating system is called the kernel. It is the kernel that is responsible for handling all the internal operations of the operating system. Right from the allocation of hardware, to multi-user and multitasking facilities, the tasks are carried out entirely by the kernel. This operating system provides you with facilities right from loading selected applications for a particular session, to terminating and resuming processes at will. There are commands to handle almost every operation within the Unix operating system.
Unix Operating System Command List
As already mentioned, there are commands for handling every task in Unix. Let us start off with a basic Unix commands list. We will handle one set of commands that are used for solving one particular operation at a time.
Basic File Handling Commands
ls
This command is used for listing the files and directories in any directory. You just have to type ls at the command prompt and you get the list of all the files and folders in that particular directory. There are various switches too, that can help in listing the names of these files and directories. For example, if you type ls -a you can get the list of the hidden files along with the other files that have been listed. Hidden file names start with a (.) dot.
mkdir
This command is used for creating directories. For example, if you type mkdir abc, the directory abc will be created in the current directory.
cd
This command is used for changing from one directory to another. If you are working in the directory abc and you want to change to the directory cba, you need to type the command cd cba. In this case, the directory cba must be present within the directory abc. If the directory cba is not present within the directory abc, you cannot move over to that directory. Under such cases you have to mention the entire path location to the directory cba starting from the root directory. Suppose the directory cba is present in the directory def under the root(/) directory, then you simply need to type, cd /def/cba, to move over to that directory. If you want to move over to the parent directory of abc, which is say buzzle, then you need to type cd .. .
pwd
If you have reached a directory through various other directories and you are not aware of the path to the directory, you can simply type in pwd and get the current location path. Suppose you are in the directory hij. hij was suppose created in the directory def, which is under the directory abc created under the root, then on typing pwd, what you get is; /abc/def/hij.
Commands for Copying, Moving and Deleting
cp
Suppose you want to create a copy of the file inventory.txt in your current directory. In such cases, the command cp can be used to make the copy. cp /abc/inventory.txt inventorybackup.txt will copy the file inventory.txt in the directory abc created under the root to your current working directory and name it inventorybackup.txt. Thus, the basic syntax of this command is cp file1 file2. Here, file1 is the name of the file you want to copy and file2 will be the name of the file when it is copied to the current directory. Remember, the original file is never hampered in this case.
mv
This is a multipurpose command. It can be used not only for moving the file but also for renaming it. Suppose you want to move the file inventory.txt created in the directory abc to your current directory, then all you need to do is mv /abc/inventory.txt .. The dot (.) at the end of the command indicates current directory. When using this command, you will be left with just one file. This command does not copy the file, but moves it from one location to another. Now suppose that we have the file abc.txt, in your current directory. On typing the command mv abc.txt def.txt, the file abc.txt will be renamed to def.txt.
rm
This command is used to remove or delete a file. So, if you type the command rm abc.txt, the file will be permanently deleted from the system.
rmdir
This command has a working similar to that of rm. But it is used for removing or deleting directories. So on typing rmdir abc, you can delete the directory abc forever.
File Content Viewing Commands
cat
The command cat can be used for creating and viewing the contents of a file. Suppose you want to view the contents of the file abc.txt, then you can type in the command cat abc.txt. On typing this command you will get the contents of the file abc.txt displayed on your screen. If the file abc.txt does not exist, then it will be created on typing the command.
less
Using this command you can see the information in a file, one page at a time. This command should be used if the file contains large content. For example, typing less abc.txt, will display the contents of the file abc.txt, one page at a time.
head
This command is used to display the first ten lines of any file on your screen. If you type head abc.txt, then what you get on the screen are the first ten lines of the file abc.txt.
tail
It works similar to the head command. But here, the last ten lines of the file can be viewed. So typing, tail abc.txt, will present you with the last ten lines of the file abc.txt.
Using Wildcards
Asterisk (*)
The asterisk sign is one of the wildcards that you can use in any Unix command. To understand the application of the wildcards, let us take an example. Suppose you want to list out all the files that end with the word 'old'. Here, in this case if you type the command ls *old, then all such files that end up with the word old, like fold, gold etc. will be listed.
Question Mark (?)
The question mark can replace just one character. So if you want to list all the filenames that end with the word uzzle and have only one starting letter, then you can type the command, ls ?uzzle. So all the files containing uzzle, like puzzle, buzzle, etc. if present in that directory, will be listed.
More About Unix Commands
echo
This is one of the most common Unix commands that are used quite often. The command displays the value of any variable. For example if there is a variable $printer (all variable names in Unix start with the $ sign) and it has the value Cannon, then on typing the command echo $printer, Cannon will be displayed on the computer screen.
man
You can simply type man followed by the command name, to display the manual of all command. You will get all the information about the command including the switches that you can use along with the command to further enhance your command execution.
whatis
On simply typing whatis followed by the name of command you will get the basic working of any command. This is another easy way to learn more about Unix commands.
Advanced Unix Commands
ps
You can use the ps command to check the list of processes and their process ids that are running in your computer system. A process id is a number that is used for the identifying processes and is unique for each process.
kill
The kill command is used to terminate any process that is being executed. It is similar to 'end task' that we use in windows. Here, we have to use the command kill followed by the process id or pid, i.e. kill pid. For example, if we want to kill the process cat, which has a pid 1134, then we will simply type kill 1134 in our command prompt.
chmod
This is one of the most important commands used for file security. For understanding the use of this command, let us try to gauge a few options that this command provides. The priority and rights of a file depends on the three basic types of users. The owner user (u), the group(g) and other(o). Read, write and execute permissions are given to each user. The execute permission is represented by the number 1, the write by the number 2 and read by 4. Now suppose the user or the owner of the file, abc, has all the three permissions, then he will have a total permission number of 7 (4+2+1). Now, if the group users have just read permission then their total permission number will be 4 (4+0+0). And suppose the other users only have the permission to execute the file then they will have a total permission of 1 (0+0+1). So the permission, associated with the file will be 741. Changing this permission, will result in changing the user rights to the file. So in the same example, if we want to change the permission of the user to just read and write, and the group and other user to just execute, then we will execute the command as chmod abc 611. The other way of executing this command is that you can remove the execute rights of the user by typing in the command chmod abc u-x. For adding read and write permission to the group and other users, you can type the command, chmod abc go+rw. Remember, only the owner of the file has the right to use the chmod command on the file.
All the Unix commands explained above have a list of options or switches, that can be used along with them. What I have tried to explain is the basic Unix command list. There are a many more commands which you can use and study when you go for an in-depth study of this wonderful operating system. The Unix command list, explained above, will help you learn Unix and use it more efficiently. By simply using these commands you can not only learn Unix, but understand the fundamentals of operating systems. All the different types of operating systems are based on the same basic principles as that of Unix.
0 comments:
Post a Comment