Unix for beginners
What is UNIX?
Unix is a time-sharing operating system kernel.
What is kernel then?
A kernel is a program that controls the resources of a computer and allocates them among its users.
I am stopping this discussion here, I will keep on coming back about this discussion about Operating System and Kernel.
Now start with some commands of Unix system which can be replicated on other systems like CentOS, Ubuntu etc.
File listing commands:
ls: lists the name of files.
ls -t: listed in the order they last modified.
ls -l: long listing with all details.
ls -lt: Long list, with a recently modified file at first place.
ls -ltr: same result as (ls -lt) but in reverse order.
ls -u: list by time last used
ls -r: list in reverse order
How to print a file:
cat filename: print content of the named file.
pr filename: print contents with the header, 66 lines per page
Moving, copying and removing files:
cp file1 file2: copy file1 to file2, overwrite old content in file2 if it exists.
mv file1 file2: move file1 to file2, and deletes file1
rm filenames: removed named files, irrevocably
Other useful commands:
wc filename: count lines, words, and characters for each file
wc -l filenames: count lines for each file.
grep pattern filename: print lines matching the pattern
grep -v pattern files: print lines not matching the pattern
sort filenames: sort files alphabetically by line.
tail filename: print last 10 lines of a file
tail -n filename: print last n lines of a file
tail +n filename: start printing file at line n
Comparing files:
cmp file1 file2: print location of first difference.
diff file1 file2: print all differences between files.
Now let’s discuss Directory and Shell:
Files are grouped into Directories. The system makes a difference between files of same names by comparing the Directories they reside in. In different Directories, same name files can exist.
How to know in which Directory you are working in?
Command: pwd (“print working directory”)
Pathname: How a file is mapped to root directory.
The pathname can be used as an argument to provide similar results if the only file name is given.
Changing directory: cd ‘directory name or path name’
Creating a directory: mkdir ‘name you want to give to directory’
Bibliography: The Unix Programming Environment (Brian W. Kernighan and Rob Pike)