Keywords :
shell, Bash, commands, scripts
PDF Docs :
Linux Shell Scripting Tutorial
.
http://www.gnu.org/software/bash/manual/bashref.html
Shell
A shell provides a user interface for access to an operating system´s services.
Generally, operating system shells use either a command-line interface (CLI) or graphical user interface (GUI)
Computer understand the language of 0’s and 1’s called binary language, In early days of computing, instruction are provided using binary language, which is difficult for all of us, to read and write. So in operative systems there is special program called Shell. Shell accepts your instruction or commands in English and translate it into computers native binary language.
This is what Shell Does for us :
You type Your command and shell convert it.
Shell is an command language interpreter that executes commands read from the standard input device (keyboard) or from a file. Linux may use one of the following most popular shells (In MS-DOS, Shell name is COMMAND.COM which is also used for same purpose, but it’s not as powerful as our Linux Shells are!)
– Ksh – Korn Shell (David G. Korn at AT&T Bell Labs)
– Bsh – Bouner Shell (Steve Bourne 7º version of UNIX Bell Labs)
– Csh – C like shell
– Bash – GNU Bourne-Again SHell
– etc …
Bash is the shell, or command language interpreter, for the GNU operating system.
Bash is a Unix Shell written by Brain Foxfor the GNU Project as a free software replacement for the Bourne shell (sh). Released in 1989, it has been distributed widely as the shell for the GNU operating systemand as a default shell on Linuxand Mac OS X. It has been ported to Microsoft Windows and distributed with Cygwin and MinGW, to DOS by the DJGPP project, to Novell NetWare and to Android via various terminal emulation applications.
.
To use shell (You start to use your shell as soon as you log into your system) you have to simply type commands.
To find your shell type following command :
$ echo $SHELL
.
Commands
http://www.computerhope.com/unix/uln.htm
http://linuxcommand.org/index.php
$ ls print name of files in current directory
$ls -al it shows a long list of files and their properties as well as the destinations that any symbolic links point to.
$ls -latr displays the same files reversed order of the last change, so that the file changed most recently occurs at the bottom of the list
$ cd directory change directory
$ mkdir directory make a directory
read/write permissions
In order to copy a file you must have read permission on the parent directory of the file and write permission on the destination.
File Permissions:
r – can read the file.
w – can write to a file.
x – can run the file as a program.
Directory Permissions:
r – can read the contents of the directory.
w – can make changes to files inside the directory/ add or delete the files.
x – can cd
to a directory.
Directory permissions are important and can override the file permissions.
Even if you’re file doesn’t have read permissions but the parent directory of the file has a read permission than you can copy the file assuming that you’re copying the file to a location where you can write.
copy – – – – – – – – – – – – – – –
$ cp -a /etc /dest
$ cp -r /etc/skel /home/user
copy absolutely all of the files and directories in a directory, hidden files, ...
Note that /home/user
must not exist already, or else it will create /home/user/skel ??? to verify
$ cp global.c main.c parse.c /home/thegeekstuff/projectbackup/src/ copy multiple files $ cp -r src/ bin/ /home/thegeekstuff/projectbackup/ copy multiple directories $ cp --backup readme.txt /home/thegeekstuff/projectbackup/ backup the destination file before overwriting it. -d to preserve the link while copying. without option -d, it will copy the file (and not the link) -av preserve everything -n won’t overwrite the existing file -i confirme before overwriting -p option, you can preserve the properties of a file or directory -u it only copy when the source file is newer than the destination file, or when the destination file is missing $ cp --preserve=mode sample.txt test/ create soft link to a file or directory, instead of copying # cp -s libFS.so.6.0.0 libFS.so # ls -l libFS.so lrwxrwxrwx 1 root root 14 Jan 9 20:18 libFS.so -> libFS.so.6.0.0 create a hard link to a file $ ls -li sample.txt 10883362 -rw-r--r-- 2 bala geek 1038 Jan 9 18:40 sample.txt $ cp -l sample.txt test/ $ ls -li test/sample.txt 10883362 -rw-r--r-- 2 bala geek 1038 Jan 9 18:40 test/sample.txt As seen above, the test/sample.txt is a hard linked file to sample.txt file and the inode of both files are the same.
.
$ date to see date
$ who to see who´s using system
$ pwd print working directory
$ rm myfile remove file
$ chmod to change file access permissions
+ Set permission
– Remove permission
r Read permission
w Write permission
x Execute permission
chmod 666 file.txt Set the permission of file.txt to “read and write by everyone” (-rw-rw-rw-).
$ who am i To See more about currently login person
$ logout
.
Processes
$ ps To see currently running process
$ kill 1012 kill {PID} To stop any process i.e. to kill process
$ ps -ag To get information about all running process
$ kill 0 To stop all process except your shell
$ runlevel
$ who -r check what your current run level is
.
$ ifconfig
$ ifconfig eth0 192.168.1.63
$ ifconfig eth0 down
$ ifconfig eth0 hw ether 00:11:22:33:44:55 up
.
$ shutdown now
$ reboot
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.