# Shell
A shell is a special-purpose program designed to read commands typed by a user and execute
appropriate programs in response to those commands.
Such as program is sometimes known as a command interpreter -
definition from 'Linux Programming Interface'
User
|
Shell
|
Kernel
|
Hardware
The shell is the Linux command line interpreter.
It provides an interface between the user and the kernel and executes programs called commands.
For example, if a user enters ls then the shell executes the ls command.
The shell can also execute other programs such as applications, scripts, and user programs.
# Bash
Bash (Bourne-Again Shell) is the default shell for Linux system
$ echo $SHELL
/bin/bash
# Basic operation between files and directories
// Print name of current/working directory
$ pwd
/home/fcheng
// List directory contents
$ ls
// Show detail
$ ls --help
$ man ls
// do not ignore entries starting with . (hidden files)
$ ls -a
// Use a long listing format
$ ls -l
-rw-rw-r-- 1 fcheng fcheng 0 Jan 28 22:46 test.txt
drwxr-xr-x 2 fcheng fcheng 4096 Jan 28 02:28 Videos
NOTE:
-: file
d: directory
// Sort by modification time
$ ls -t
// Show size
$ ls -s
// Human readable
$ ls -h
// Clear screen
$ clear
// Change file timestampes (Create empty file if that file does not exist)
$ touch demo.txt
// Remove a file
$ rm demo.txt
// Create a folder
$ mkdir demo
// Remove a folder
$ rm -rf demo
// Show commands history
$ history
# File Directory Structure
/
/bin User Binaries ls, touch, rm ...
/sbin System Binaries ip
/etc Configuration Files /etc/mysel/conf.d
/dev Device Files
/proc Process Information
/var Vriable Files /var/log/
/tmp Temporary Files
/usr User Programs
/home Home Directories /home/fcheng/
/boot Boot Loader Files
/lib System Libraries
/opt Optional add-on Apps
/mnt Mount Directory
/media Removable Devices
/src Service Data
# Useful commands to print files
## cat
// concatenate files and print on the standard output
$ cat /etc/profile
// Show line number (ignore blank)
$ cat -b /etc/profile
## more
// file perusal filter for crt viewing
$ more /var/log/syslog
## less
// less - opposite of more
$ less /var/log/syslog
### less commands
After executing less, you can use following commands to do more
// next page
f
// Go to page start
g
// Go to page end
G
// Search
/
## head
// output the first part of files
$ head /var/log/syslog
## tail
// output the first part of files
$ tail /var/log/syslog
NOTE: It is useful
// output appended data as the file grows;
$ tail -f /var/log/syslog
No comments:
Post a Comment