-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating
Learning Linux Shell Scripting
By :
Let us learn a few commands, which are required very often, such as man, echo, cat and similar:
man command:$ man man
From the following table, you can get an idea about various types of man pages for the same command:
|
Section number |
Subject area |
|---|---|
|
1 |
User commands |
|
2 |
System calls |
|
3 |
Library calls |
|
4 |
Special files |
|
5 |
File formats |
|
6 |
Games |
|
7 |
Miscellaneous |
|
8 |
System admin |
|
9 |
Kernel routines |
man command to display corresponding manual pages as follows:$ man 1 command $ man 5 command
passwd command, which is used for changing the current password of a user, you can type the command as follows:$ man command man -k passwd // show all pages with keyword man –K passwd // will search all manual pages for pattern $ man passwd
This will show information about the passwd command:
$ man 5 passwd
The preceding command will give information about the file passwd, which is stored in /etc /passwd.
$ whatis passwd
Output:
passwd (1ssl) - compute password hashes passwd (1) - change user password passwd (5) - the password file
$ which passwd /usr/bin/passwd
The preceding line tells us that the binary file of the passwd command is located in the /usr/bin/passwd folder.
$ whereis passwd
The output will be as follows:
passwd: /usr/bin/passwd /etc/passwd /usr/bin/X11/passwd /usr/share/man/man1/passwd.1.gz /usr/share/man/man1/passwd.1ssl.gz /usr/share/man/man5/passwd.5.gz
$ whoami
This command displays the user name of the logged in user:
$ su
The su command (switch user) will make the user as the administrator; but, you should know the administrators, password. The sudo command (superuser do) will run the command with administrator's privileges. It is necessary that the user should have been added in the sudoers list.
# who am i
This command will show the effective user who is working at that moment.
# exit
$ alias ll='ls –l' $ alias copy='cp –rf'
To list all declared aliases, use the following command:
$ alias
To remove an alias, use the following command:
$ unalias copy
$ uname
Output:
Linux
This will display the basic OS information (UNIX name)
$ uname –r
Output:
3.13.0-32-generic
$ uname –a
Output:
Linux ubuntu 3.13.0-32-generic #57~precise1-Ubuntu SMP Tue Jul 15 03:50:54 UTC 2014 i686 i686 i386 GNU/Linux
$ cat /proc/version // detailed info about distribution $ cat /etc/*release # lsb_release -a // will tell distribution info for Ubuntu
The command
cat is used for reading files and displayed on the standard output.
$ ln -s file file_link
$ file fil_name // show type of file
file_name using the cat command:$ cat > file_name line 1 line 2 line 3 < Cntrl + D will save the file >
But this is very rarely used, as many powerful editors are already existing, such as vi or gedit.
Hello World on the console. The echo command is very useful for Shell script writers:$ echo "Hello World"
Hello World to the hello.c file:$ echo "Hello World" > hello.c
The command echo with > overwrites the content of the file. If content already exists in the file, it will be deleted and new content will be added in the file. In a situation, when we need to append the text to the file, then we can use the echo command as follows:
$ echo "Hello World" >> hello.c will append the text
$ cat hello.c
Change the font size
Change margin width
Change background colour