0% found this document useful (0 votes)
70 views

A Brief Introduction To Unix

The document provides an overview of the Unix operating system including its core components like the kernel, shell, and programs. It also summarizes important Unix commands for navigating directories, viewing files, searching, and modifying permissions.

Uploaded by

Sushil Nahar
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
70 views

A Brief Introduction To Unix

The document provides an overview of the Unix operating system including its core components like the kernel, shell, and programs. It also summarizes important Unix commands for navigating directories, viewing files, searching, and modifying permissions.

Uploaded by

Sushil Nahar
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

A Brief Introduction to Unix

-Developed in the 1960s. -Consists of 3 parts: Kernel, Shell and Programs.

Kernel: -It is the hub of the Operating System. -Allocates time and memory to programs. -Handles file storage and communication response to system calls.

Shell: -Acts as an interface between the user and the Kernel. -It is the Command Line Interpreter (CLI). It interprets the commands user types and arranges for them to be carried out. Programs: -Anything the user types are programs. -All commands are considered programs. -A Process is a program that has a PID (Process ID).

File Structure: -The UNIX file structure is hierarchical. -Top of the hierarchy is called the ROOT. -During first log in, the current working directory is the home directory. -Home directorys name is the same as the user name. -All files are organized by user and group. -A user can belong to more than one group. -All files are owned only by 1 user and 1 group.

Commands
Ls (list): -Lists the contents of the current directory. Ls command has many variants.

-a: shows hidden files and folders (hidden files start with a .) -l: shows detailed listing of all files and folders (permissions, owners, groups, last modified, size). -r: lists files in descending order. -t: lists files according to timestamp.

-To hide a file, touchcommand is used. Touch <filename> hides the file. -When using the ls l command, the 1st column contains _rw-rwx-rwx

The 1st _ is either d or blank. If it is d, then it means that the displayed content is a directory. If it is blank, then it is a file. The rwx stands for read-write-execute. It is displayed 3 times and they are in the order user-groupothers. If any of them are blank, then the corresponding user or group or others donot have the permission for that file.

Mkdir: -Creates a new directory. Mkdir <filename> -Can be used to create a directory in a different hierarchy also. In such cases, the path where the directory needs to be created has to be mentioned. -To create a directory in hierarchy, -p can be used. Mkdir p ~/a/b/d creates directory d in the given hierarchy. Existing files are not overwritten.

Cd (Change Directory): -cd <dir_name> Changes the current directory to <dir_name> -Can be used to change to a directory in a different hierarchy also. In such cases, the path of the desired directory needs to be mentioned.

Cd .. : changes the current directory to the parent directory (moves one level up in the hierarchy).

Pwd (Present Working Directory): Displays the full path of the current directory. Alternatively . Can also be used for the same purpose.

The ~ character represents the home directory. It can be used to specify paths staring from home instead of typing the name of the home directory.

Cp(copy): -cp <file1> <file2> copies the contents of <file1> in the current directory to <file2>. If we need to copy a file from a different directory to the current directory, we can use the . Operator. Cp ~/something/something/file1 . copies <file1> into the current directory. The name remains the same. To copy a directory, we need to use r.

Mv (move/rename): -mv command is used to move or rename a file. Mv <file1> <file2> moves the contents of <file1> to <file2> if <file2> already exists. In such a case, contents of <file2> is overwritten. If <file2> doesnot exist, then the operation is equivalent to rename operation.

Rm (Remove dir/ifle): -rm <file> deletes the file. To delete directories, rm r <dir> is used. The r command specifies that the directory needs to be deleted recursively until no fie is left.

Clear: clears the screen of all contents and leaves the prompt at the top of the terminal.

Cat: Displays the contents of a file. Cat <file> is the command used.

Less: Displays the contents of a file one page at a time.

Head: Displays the 1st 10 lines of a file.

Tail: Displays the last 10 lines of a file.

Grep(search for keywords in a file): -grep <keyword> <file> searches for <keyword> in file and prints out the lines containing <keyword>. -it is case sensitive. i can be used to make the search case insensitive. -to search for a phrase, enclose it in single quotes. -i: case insensitive. -v: display all lines that DO NOT math. -n: displays the line number of every displayed line. -c: prints only the count of the number of matched lines.

Wc (word count): -wc <file> Displays the number of words in the file. Wc l counts the number of lines.

Man( manual): Man <cmd> : Displays the help section for the given command.

Wildcards: These can be used in special cases to make file handling easier. -* : any number of characters. Eg: ls *.doc displays all files ending with .doc. -? : only one character. Eg : ls ?.doc displays all files that have only one character as name and is followed by the extension .doc -[]: range of characters. Eg: ls [a-b]*.doc displays all files starting with a or b and having the extension .doc.

Chmod ( modify access permissions): -chmod [options] <file/dir> modifies the permissions for that file/dir. -To modify the permissions recursicely use R command. -To give permission: +w +r +x (gives write, read and execute permissions respectively). -To revoke permission: -w r -x (revokes write, read and execute permissions respectively). -We can give/revoke permission for the whole user, group or others using u, -g and o. Eg: chmod g w +r <filename> revokes write permission and gives read permission for the whole group for <filename>. -Another way of changing access permissions is by using specially assigned numbers for read write and execute operations. Read=4, Write=2, execute=1. Eg: chmod 741 <filename> gives read, write and execute permission for user, read permission for group and execute permission for others.

Find (search for a file): -It finds both files and directories in the specified path. Eg: find <path> pattern. This searches for the pattern in the given path and displays all the files and directories whose name contains the specified pattern. To find only directories: find <path> -type d <pattern> To find only files: find <path> -type f <pattern>

You might also like