soure
Introduction
- Types of Unix
- Sun Solaris
- GUN/Linux
- MacOS X
- Three parts of Unix operating system
- Kernel - allocates time and memory to programs and handles the folestores and communications in response to system calls
- Shell - an interface between user and the kernel, a command line interpreter (CLI)
- Programs
Everything in UNIX is either a file or a process
- A process is an executing program identified by a unique PID (process identifier).
- A file is a collection of data. All the files are grouped together in the directory structure. The file-system is arranged in a hierarchical structure, like an inverted tree. The top of the hierarchy is traditionally called root (written as a slash / )
Listing files and directories
- ls —list files and directories
- ls -a —list all files and directories including hidden files beginning with a dot
- mkdir —make a directory
- cd . —stay current directory
- cd .. —change to parent directory
- cd —change to home directory
- cd ~ —change to home directory
- pwd —show the working directory
Handling files
- copy file: cp originallfile destinationfile
- move file: mv originallfile destinationfile
- remove file: rm filename
- remove an empty directory: rmdir directory
- clear screen: clear
- display content of a file: cat filename
- display content of a file a page at a time: less filename. Press the [space-bar] if you want to see another page, and type [q] if you want to quit reading
- show the first ten lines of a file: head filename
- show the last ten lines of a file: tail filename
- search file:
- search keyword: grep keyword filename
- search a phrase or pattern: grep ‘phrase’ filename
- serach keyword ignore case distinction: grep -i keyword filename
- display lines do NOT match: grep -v keyword filename
- precede each matching line with the line number: grep -n keyword filename
- print only the total count of matched lines: grep -c keyword filename
- use more than one option: grep -ivc keyword filename
- word count:
- count numbers of words: wc -w filename
- count numbers of lines: wc -l filename
- compress file: gzip filename (will create a file names filename.gz)
- unzip a file: gunzip filename
- read gzipped files:
- for small file: zcat filename.gz
- for large file: zcat filename.gz | less
- compare files: diff file1 file2
- find file:
- by name: find . -name “*.txt" -print (search all files with extention .txt in the current directory)
- by size: find . -size +1M -ls (find files over 1Mb in size, and display the result as a long listing)
Redirecting
- outputof a command: cat > filename
- append to a file: cat >> filename
- cconcatenate two files to a new file: cat file1 file2 > newfile
- input a file and sort then output as another file: sort < inputfile > outputfile
- check the current login user: who
- pipe the output of command1 to the input of command2: command1 | command2
example: Using pipes, display all lines of list1 and list2 containing the letter ‘p’, and sort the result.
cat list1 list2 | grep p | sort
Wildcard
- match any number of characters: *
- match one character: ?
Getting help
- read the manual page: man commandName
- one-line discription: whatis commandName
- match commands with keyword in their man pages: apropos keyword
Access rights
- check access right: ls -l
example: -rwxrw-r– 1 ee51ab beng95 2450 Sept29 11:52 file1
- If d is present, it will be at the left hand end of the string, and indicates a directory: otherwise - will be the starting symbol of the string.
- The 9 remaining symbols indicate the permissions, or access rights, and are taken as three groups of 3.
- The left group of 3 gives the file permissions for the user that owns the file (or directory)
- The middle group gives the permissions for the group
- The rightmost group gives the permissions for all others.
- Owner of the file/directorry: ee51ab
- Group of the file/directory: eebeng95
- file size: 2450
- created time: Sept29 11:52
- file name: file1
Changing access right
- only the owner can use chmod to change the permission
- symbol:
- user: u
- group: g
- other: o
- all: a
- read: r
- write and delete: w
- execute and access directory: x
- add permission: +
- take away permission: - examples:
- remove read write and execute permissions on the file biglist for the group and others: chmod go-rwx biglist
- give read and write permissions on the file biglist to all: chmod a+rw biglist
Jobs
- show a job list: jobs
- restart a suspended job: fg %jobnumber (fg restart the last suspended job)
- show process numbers: ps
- kill a job running in the forground: ^C (control c)
- suspend the job running in the foreground: ^z (control z)
- kill a suspenbded job with job number: kill %jobnumber
- kill a suspenbded job with job number: kill PID_number
NOTE: It is no possible to kill off other users’ processes/jobs!!