Unix and Linux — Basics

Unix and Linux — Basics

For someone who is in ‘Hello World’ stage

History:

  • Started in MIT as part of project MULTICS (Multiplexed Information and Computing Service)
  • Dennis Ritchie then wrote the complete OS in C language and named it as UNICS which finally ended up being UNIX
  • Linus Torvalds in 1991 developed a free OS based on UNIX and wanted to call it as FREAX (Free OS) but his friends insisted him to have his name and the product ended being called as LINUX

To Start With:

  • We can access and work on OS by getting into ‘Terminal’ / ‘Command Prompt’ (If you are on Windows, it is different type of OS and you need a Remote Desktop built on Unix/Linux to work on it)
  • Few directory commands
# if we write anything after '#', it indicate that is a comment
#make directory
mkdir directoryName # Ex: mkdir myNewDirectory
#change directory
cd givePathofDirectory # Ex: cd existingDirectory
#Show current directory
pwd # pwd means present working directory
#To list files and directories within a given directory
ls # ls will come with lot of flag options to use
  • Use ‘man’ command to know more about any command
man nameOfCommand #Ex: man ls will provide details about ls command
  • Use ‘cat’ command to know the contents of the file
cat fileName #Ex: cat file1.txt - to know/read contents of file1.txt
  • To copy, move and rename file/directories
mv source_file destination_file #to move/rename the file
cp source_file destination_file # to copy the file

# To move directory and all the contents within it
# -R is a flag which indicates recursively
mv -R source_directory dest_directory

# To copy directory and all the contents within it
cp -R source_directory dest_directory
  • To remove files and directories
rm -R directoryName #Remove directory and all the files within it
  • To link directories (Something like creating a shortcut)
ln -s pathToDirectory pathTolinkedDirectory 
# -s flag indicates symbolic link
  • ls command is used to list files/directories and we can use ‘find’ command to search for files/directories based on various properties of them such as name, size, owner etc. We can use wild characters in the search effectively to look for the desired results.

Shell:

  • Shell is a means by which we can communicate with Unix/Linux OS
  • There are many types of shells like bash, tshell etc
  • Shell helps in file completion (By pressing tab twice) and stores the history of commands executed which can come handy

Editors

  • Every Unix system will have ‘vi’ editor (visual) to edit the files
#Please be aware we can use the commands together as well
  • We can use nano editors to edit the files as well and it presents various commands at the bottom of the file which we can make use of.

Permissions

  • When we execute ‘ls -l’ command we can see the permissions set for any file/directory at very beginning of the line
  • This basically contains 10 characters First character either being — or d indicating it is file or directory Next 3 characters are corresponded to user Next 3 characters are corresponded to group Last 3 characters are corresponded to every user
  • Those 3 characters are in order: read, write and execute. If it displays rwx then it means file/directory can be read,written and exeucted by current user If it displats r — then it means file/directory is read-only
  • Use ‘chmod’ command to change the permissions

Working with contents of File

  • ‘wc’ is the command which helps to know the number of lines, number of characters and bytes within the file
  • ‘grep’ is one of the powerful commands to search contents of the file and has numerous flag which can be used in conjunction
  • cmp, diff and sdiff are some commands which we can use to compare and notice the differences between two files
  • Use piping concept ( |) to work on the output of the command

Other Basic Commands