With the advent of time and technology, the concept of Open Source and Working with Linux is increasing. People are moving away from propritery softwares now. And i hope many of us here must be working on Linux or Unix systems too. And while working on such systems we cannot deny the importance of working on Comman Line Interface. The power of Linux is in its Shell and and shell is the one that interprets our commands to a language computer can understand.
So i'll be explaining about some of the important Linux Commands which will be helpful for getting an idea about how they work. Linux commands can be used with [options] which is like customizing the command as per the requirement.
1. cat [options] [file-list]
This command can be use to create, Join and display files. The cat utility copies files to standard output. You can use cat to display the contents of one or more text files on the screen. Here the file-list is a list of the pathnames of one or more files that cat processes. If you do not specify an argument or if you specify a hyphen (–) in place of a filename, cat reads from standard input.
We can use cat to create short text files without using an editor like shown below.
$ cat > ... write your content here ... ... write your content here ...
And when you want to end the file just press: CONTROL-D
Note:means you can give any filename of your choice
To displays the contents of the text file on the terminal you need to type:
$ cat
The next example catenates three text files and redirects the output to the all file:
$ cat 1.txt 2.txt 3.txt > all.txt
Note of Caution: If the filename already exist, the prompt won't warn you and will simply overwrite the file So use it cutiously.
2. who [options]
We need to understand that the Linux is a multiuser operating system and so there might be many users logged in. So if a system administrator wants to know about them , he needs to use the command who.
who am i The who utility displays information about users who are logged in on the local system.
$ who puneet tty1 Jul 30 06:01 amar
tty2 Jul 30 06:02 Jyoti tty3 Jul 30 14:56
$ who am i
puneet tty1 Jul 30 06:01
3. cd [options] [directory]
Changes to another working directory. The cd builtin makes directory the working directory. Lets use the cd command to makes Puneet's home directory his working directory. To know the current working directory, we can use the command pwd( print working Direcotry) like this:
$ pwd /home/puneet/work
Then type
$ cd
And then to confirm the working directory is changed type below command again
$ pwd
/home/puneet
So if the directory puneet is having subdiretory named work. cd command can be used to make that as working directory like this:
$ cd work
$ pwd
/home/puneet/work
To go back to the parent direcotry we can use the command as:
$ cd ..
$ pwd
/home/puneet/
4. date [options] [+format]
Displays or sets the system time and date. The date utility displays the time and date known to the system. Superuser can use date to change the system clock. Use the below command to change the date without changing the year.
$ date
08191407.30 Sat Aug 19 14:07:30 IST 2012
We can use different format options display the date in a commonly used format. So type:
$ date '+Today is %h %d, %Y'
Output should be:
Today is Aug 19, 2005
5.ps [options] [process-list]
An operating system has processes and the administrator is required to know the kind of processes running and their status. So the ps command can be used to display process status. The ps utility displays status information about processes running on the local system.
$ ps
PID TTY TIME CMD
2697 pts/0 00:00:02 bash
3299 pts/0 00:00:00 ps
With the –l (long) option, ps displays more information about the processes:
$ ps -l F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD 000 S 500 2697 2696 0 75 0 - 639 wait4 pts/0 00:00:02 bash 000 R 500 3300 2697 0 76 0 - 744 - pts/0 00:00:00 ps
With option u , it can be used to display more user information.
$ ps -u
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
puneet 2697 0.0 0.5 2556 1460 pts/0 S Jul31 0:02 -bash
puneet 3303 0.0 0.2 2476 616 pts/0 R Jul31 0:00 ps -u
6. kill [option] PID-list
Terminates a process by PID. The kill utility terminates one or more processes by sending them signals. By default kill sends a software termination signal (signal number 15). For kill to work, the process must belong to the user executing kill, with one exception: Superuser can terminate any process. The ps utility can be used to determine the PID.
$ kill 259
Sometime as process gets hanged so we can kill it forcefully using the command:
$ kill -9 259
7. nice [option] [command-line]
Nice command is used to change the priority of a command. The nice utility reports the priority of the shell or alters the priority of a command. An ordinary user can decrease the priority of a command. Only Superuser can increase the priority of a command. Negative means highest priority and positive means lowest priority. The priority ranges from -19 to +20
Below is the example of nice command which finds very large files and runs at a high priority (–15):
$ nice -n -15 find / -size +50000k
8. chown [options]
Changes the owner of a file and/or the group the file is associated with. Only root can change the owner of a file. Only root or the owner of a file who belongs to the new group can change the group a file is associated with. The following command changes the owner of the data file in the work directory. The new owner is Aman.
$ chown aman work/data
The following command makes puneet the owner of, and puneet's login group the group associated with, all files in the /home/aman/work directory and in all its subdirectories.
$ chown --recursive puneet: /home/aman/work
The next command changes the ownership of the files in work direcotry of aman to puneet and the group associated with these files to pcgroup:
$ chown puneet:pcgroup /home/aman/work/*
The final example changes the only the group association of the files in work to pcgroup without altering their ownership. The owner of the files, who is executing this command, must belong to the pcgroup group.
$ chown :pcgroup work/*
9. cmp [options] file1 [file2 [skip1 [skip2]]]
This command is used to compares two files. The cmp utility displays the differences between two files on a byte-by-byte basis. If the files are the same, cmp is silent. If the files differ, cmp displays the byte and line number of the first difference.
The file1 and file2 are pathnames of the files that cmp compares. If file2 is omitted, cmp uses standard input instead. Using a hyphen (–) in place of file1 or file2 causes cmp to read standard input instead of that file. The skip1 and skip2 are decimal numbers indicating the number of bytes to skip in each file before beginning the comparison.
The examples use the files a and b shown below. These files have two differences. The first difference is that the word lazy in file a is replaced by lasy in file b. The second difference is more subtle: A TAB character appears just before the NEWLINE character in file b.
$ cat a I am Writing this article for boddunan.
$ cat b I am writing this article for boddunan.TAB
The first example uses cmp without any options to compare the two files. The cmp utility reports that the files are different and identifies the offset from the start of the files where the first difference is found:
$ cmp a b a b
differ: char 39, line 1
These were the basic commands you can use while working. Try them with different options.
Please do let me know in case you want to know about more commands. I'll be happy to help. Hope you enjoy reading it.